Adding a user core bulk update function.
This commit is contained in:
parent
9466592663
commit
a1c7e60dfa
|
@ -40,9 +40,9 @@ export async function usersAdded(count: number, group: UserGroup) {
|
||||||
await publishEvent(Event.USER_GROUP_USERS_ADDED, properties)
|
await publishEvent(Event.USER_GROUP_USERS_ADDED, properties)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function usersDeleted(emails: string[], group: UserGroup) {
|
export async function usersDeleted(count: number, group: UserGroup) {
|
||||||
const properties: GroupUsersDeletedEvent = {
|
const properties: GroupUsersDeletedEvent = {
|
||||||
count: emails.length,
|
count,
|
||||||
groupId: group._id as string,
|
groupId: group._id as string,
|
||||||
}
|
}
|
||||||
await publishEvent(Event.USER_GROUP_USERS_REMOVED, properties)
|
await publishEvent(Event.USER_GROUP_USERS_REMOVED, properties)
|
||||||
|
|
|
@ -6,7 +6,7 @@ import {
|
||||||
} from "./db/utils"
|
} from "./db/utils"
|
||||||
import { queryGlobalView } from "./db/views"
|
import { queryGlobalView } from "./db/views"
|
||||||
import { UNICODE_MAX } from "./db/constants"
|
import { UNICODE_MAX } from "./db/constants"
|
||||||
import { User } from "@budibase/types"
|
import { BulkDocsResponse, User } from "@budibase/types"
|
||||||
import { getGlobalDB } from "./context"
|
import { getGlobalDB } from "./context"
|
||||||
import PouchDB from "pouchdb"
|
import PouchDB from "pouchdb"
|
||||||
|
|
||||||
|
@ -20,6 +20,11 @@ export const bulkGetGlobalUsersById = async (userIds: string[]) => {
|
||||||
).rows.map(row => row.doc) as User[]
|
).rows.map(row => row.doc) as User[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const bulkUpdateGlobalUsers = async (users: User[]) => {
|
||||||
|
const db = getGlobalDB() as PouchDB.Database
|
||||||
|
return (await db.bulkDocs(users)) as BulkDocsResponse
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given an email address this will use a view to search through
|
* Given an email address this will use a view to search through
|
||||||
* all the users to find one with this email address.
|
* all the users to find one with this email address.
|
||||||
|
|
|
@ -21,7 +21,6 @@ import {
|
||||||
AllDocsResponse,
|
AllDocsResponse,
|
||||||
BulkCreateUsersResponse,
|
BulkCreateUsersResponse,
|
||||||
BulkDeleteUsersResponse,
|
BulkDeleteUsersResponse,
|
||||||
BulkDocsResponse,
|
|
||||||
CloudAccount,
|
CloudAccount,
|
||||||
CreateUserResponse,
|
CreateUserResponse,
|
||||||
InviteUsersRequest,
|
InviteUsersRequest,
|
||||||
|
@ -391,7 +390,7 @@ export const bulkCreate = async (
|
||||||
})
|
})
|
||||||
|
|
||||||
const usersToBulkSave = await Promise.all(usersToSave)
|
const usersToBulkSave = await Promise.all(usersToSave)
|
||||||
await db.bulkDocs(usersToBulkSave)
|
await usersCore.bulkUpdateGlobalUsers(usersToBulkSave)
|
||||||
|
|
||||||
// Post-processing of bulk added users, e.g. events and cache operations
|
// Post-processing of bulk added users, e.g. events and cache operations
|
||||||
for (const user of usersToBulkSave) {
|
for (const user of usersToBulkSave) {
|
||||||
|
@ -469,13 +468,11 @@ export const bulkDelete = async (
|
||||||
)
|
)
|
||||||
|
|
||||||
// Delete from DB
|
// Delete from DB
|
||||||
const dbResponse: BulkDocsResponse = await db.bulkDocs(
|
const toDelete = usersToDelete.map(user => ({
|
||||||
usersToDelete.map(user => ({
|
...user,
|
||||||
...user,
|
_deleted: true,
|
||||||
_deleted: true,
|
}))
|
||||||
}))
|
const dbResponse = await usersCore.bulkUpdateGlobalUsers(toDelete)
|
||||||
)
|
|
||||||
|
|
||||||
for (let user of usersToDelete) {
|
for (let user of usersToDelete) {
|
||||||
await bulkDeleteProcessing(user)
|
await bulkDeleteProcessing(user)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue