diff --git a/packages/commons/src/events/ActionDocument.ts b/packages/commons/src/events/ActionDocument.ts index 2062fc6dd1..576f5ae17f 100644 --- a/packages/commons/src/events/ActionDocument.ts +++ b/packages/commons/src/events/ActionDocument.ts @@ -14,6 +14,7 @@ import { z } from 'zod' const ActionBase = z.object({ createdAt: z.string().datetime(), createdBy: z.string(), + createdAtLocation: z.string(), data: z.record(z.string(), z.any()) }) @@ -60,15 +61,13 @@ const DraftAction = ActionBase.merge( const CreatedAction = ActionBase.merge( z.object({ - type: z.literal(ActionType.CREATE), - createdAtLocation: z.string() + type: z.literal(ActionType.CREATE) }) ) const NotifiedAction = ActionBase.merge( z.object({ - type: z.literal(ActionType.NOTIFY), - createdAtLocation: z.string() + type: z.literal(ActionType.NOTIFY) }) ) diff --git a/packages/events/src/router/router.ts b/packages/events/src/router/router.ts index aa98ccdc6a..d54a593745 100644 --- a/packages/events/src/router/router.ts +++ b/packages/events/src/router/router.ts @@ -112,19 +112,22 @@ export const appRouter = router({ notify: publicProcedure.input(NotifyActionInput).mutation((options) => { return addAction(options.input, { eventId: options.input.eventId, - createdBy: options.ctx.user.id + createdBy: options.ctx.user.id, + createdAtLocation: options.ctx.user.primaryOfficeId }) }), draft: publicProcedure.input(DraftActionInput).mutation((options) => { return addAction(options.input, { eventId: options.input.eventId, - createdBy: options.ctx.user.id + createdBy: options.ctx.user.id, + createdAtLocation: options.ctx.user.primaryOfficeId }) }), declare: publicProcedure.input(DeclareActionInput).mutation((options) => { return addAction(options.input, { eventId: options.input.eventId, - createdBy: options.ctx.user.id + createdBy: options.ctx.user.id, + createdAtLocation: options.ctx.user.primaryOfficeId }) }), register: publicProcedure @@ -140,7 +143,8 @@ export const appRouter = router({ }, { eventId: options.input.eventId, - createdBy: options.ctx.user.id + createdBy: options.ctx.user.id, + createdAtLocation: options.ctx.user.primaryOfficeId } ) }) diff --git a/packages/events/src/service/events.ts b/packages/events/src/service/events.ts index 537fc664a5..d3dc867240 100644 --- a/packages/events/src/service/events.ts +++ b/packages/events/src/service/events.ts @@ -101,7 +101,11 @@ export async function createEvent({ export async function addAction( input: ActionInput, - { eventId, createdBy }: { eventId: string; createdBy: string } + { + eventId, + createdBy, + createdAtLocation + }: { eventId: string; createdBy: string; createdAtLocation: string } ) { const db = await getClient() const now = new Date().toISOString() @@ -115,7 +119,8 @@ export async function addAction( actions: { ...input, createdBy, - createdAt: now + createdAt: now, + createdAtLocation } } }