Small change to make sure no duplicates ever occur.

This commit is contained in:
Michael Drury 2023-04-05 21:22:50 +01:00
parent 70c9d06832
commit 0771ec55fb
2 changed files with 7 additions and 1 deletions

View File

@ -75,14 +75,19 @@ export async function syncGlobalUsers() {
toWrite.push(combined)
}
}
let foundEmails: string[] = []
for (let data of metadata) {
if (!data._id) {
continue
}
const alreadyExisting = data.email && foundEmails.indexOf(data.email) !== -1
const globalId = getGlobalIDFromUserMetadataID(data._id)
if (!users.find(user => user._id === globalId)) {
if (!users.find(user => user._id === globalId) || alreadyExisting) {
toWrite.push({ ...data, _deleted: true })
}
if (data.email) {
foundEmails.push(data.email)
}
}
await db.bulkDocs(toWrite)
}

View File

@ -2,4 +2,5 @@ import { Document } from "../document"
export interface UserMetadata extends Document {
roleId: string
email?: string
}