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)
|
toWrite.push(combined)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
let foundEmails: string[] = []
|
||||||
for (let data of metadata) {
|
for (let data of metadata) {
|
||||||
if (!data._id) {
|
if (!data._id) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
const alreadyExisting = data.email && foundEmails.indexOf(data.email) !== -1
|
||||||
const globalId = getGlobalIDFromUserMetadataID(data._id)
|
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 })
|
toWrite.push({ ...data, _deleted: true })
|
||||||
}
|
}
|
||||||
|
if (data.email) {
|
||||||
|
foundEmails.push(data.email)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
await db.bulkDocs(toWrite)
|
await db.bulkDocs(toWrite)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,4 +2,5 @@ import { Document } from "../document"
|
||||||
|
|
||||||
export interface UserMetadata extends Document {
|
export interface UserMetadata extends Document {
|
||||||
roleId: string
|
roleId: string
|
||||||
|
email?: string
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue