fixed duplicating users in user creation backend

This commit is contained in:
NEOLPAR 2022-07-13 17:37:03 +01:00
parent 6b83fcb8d9
commit 529d2c06da
1 changed files with 14 additions and 1 deletions

View File

@ -23,10 +23,23 @@ export const save = async (ctx: any) => {
}
export const bulkSave = async (ctx: any) => {
let { users: newUsers, groups } = ctx.request.body
let { users: newUsersRequested, groups } = ctx.request.body
let usersToSave: any[] = []
let groupsToSave: any[] = []
const newUsers: any[] = []
const db = tenancy.getGlobalDB()
const currentUserEmails =
(await users.allUsers())?.map((x: any) => x.email) || []
for (const newUser of newUsersRequested) {
if (
newUsers.find((x: any) => x.email === newUser.email) ||
currentUserEmails.includes(newUser.email)
)
continue
newUsers.push(newUser)
}
newUsers.forEach((user: any) => {
usersToSave.push(