fixed duplicating users in user creation backend
This commit is contained in:
parent
6b83fcb8d9
commit
529d2c06da
|
@ -23,10 +23,23 @@ export const save = async (ctx: any) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const bulkSave = 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 usersToSave: any[] = []
|
||||||
let groupsToSave: any[] = []
|
let groupsToSave: any[] = []
|
||||||
|
const newUsers: any[] = []
|
||||||
const db = tenancy.getGlobalDB()
|
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) => {
|
newUsers.forEach((user: any) => {
|
||||||
usersToSave.push(
|
usersToSave.push(
|
||||||
|
|
Loading…
Reference in New Issue