Small change to make sure no duplicates ever occur.
This commit is contained in:
parent
70c9d06832
commit
0771ec55fb
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -2,4 +2,5 @@ import { Document } from "../document"
|
|||
|
||||
export interface UserMetadata extends Document {
|
||||
roleId: string
|
||||
email?: string
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue