pr comments

This commit is contained in:
Peter Clement 2024-10-22 12:03:16 +01:00
parent 33ea5f09a7
commit bce430b57c
4 changed files with 34 additions and 33 deletions

View File

@ -65,14 +65,14 @@ export async function patch(
}
ctx.status = 200
ctx.eventEmitter &&
ctx.eventEmitter.emitRow(
`row:update`,
ctx.eventEmitter.emitRow({
eventName: `row:update`,
appId,
row,
table,
oldRow,
sdk.users.getUserContextBindings(ctx.user)
)
user: sdk.users.getUserContextBindings(ctx.user),
})
ctx.message = `${table.name} updated successfully.`
ctx.body = row
gridSocket?.emitRowUpdate(ctx, row)
@ -104,14 +104,13 @@ export const save = async (ctx: UserCtx<Row, Row>) => {
)
ctx.status = 200
ctx.eventEmitter &&
ctx.eventEmitter.emitRow(
`row:save`,
ctx.eventEmitter.emitRow({
eventName: `row:save`,
appId,
row,
table,
null,
sdk.users.getUserContextBindings(ctx.user)
)
user: sdk.users.getUserContextBindings(ctx.user),
})
ctx.message = `${table.name} saved successfully`
// prefer squashed for response
ctx.body = row || squashed
@ -184,17 +183,14 @@ async function deleteRows(ctx: UserCtx<DeleteRowRequest>) {
for (let row of rows) {
ctx.eventEmitter &&
ctx.eventEmitter.emitRow(
`row:delete`,
ctx.eventEmitter.emitRow({
eventName: `row:delete`,
appId,
row,
null,
null,
sdk.users.getUserContextBindings(ctx.user)
)
user: sdk.users.getUserContextBindings(ctx.user),
})
gridSocket?.emitRowDeletion(ctx, row)
}
return rows
}
@ -208,14 +204,12 @@ async function deleteRow(ctx: UserCtx<DeleteRowRequest>) {
}
ctx.eventEmitter &&
ctx.eventEmitter.emitRow(
`row:delete`,
ctx.eventEmitter.emitRow({
eventName: `row:delete`,
appId,
resp.row,
null,
null,
sdk.users.getUserContextBindings(ctx.user)
)
row: resp.row,
user: sdk.users.getUserContextBindings(ctx.user),
})
gridSocket?.emitRowDeletion(ctx, resp.row)
return resp

View File

@ -145,7 +145,7 @@ export async function externalTrigger(
fields: Record<string, any>
timeout?: number
appId?: string
user?: UserBindings | undefined
user?: UserBindings
},
{ getResponses }: { getResponses?: boolean } = {}
): Promise<any> {

View File

@ -13,14 +13,21 @@ import { Table, Row, User } from "@budibase/types"
* This is specifically quite important for template strings used in automations.
*/
class BudibaseEmitter extends EventEmitter {
emitRow(
eventName: string,
appId: string,
row: Row,
table?: Table,
oldRow?: Row,
user?: User
) {
emitRow({
eventName,
appId,
row,
table,
oldRow,
user,
}: {
eventName: string
appId: string
row: Row
table?: Table
oldRow?: Row
user: User
}) {
rowEmission({ emitter: this, eventName, appId, row, table, oldRow, user })
}

View File

@ -73,7 +73,7 @@ export interface UserBindings extends Document {
lastName?: string
email?: string
status?: string
roleId?: string | undefined | null
roleId?: string | null
globalId?: string
userId?: string
}