Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: store createdAtLocation for each action based on users primary office #8263

Merged
merged 1 commit into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions packages/commons/src/events/ActionDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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())
})

Expand Down Expand Up @@ -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)
})
)

Expand Down
12 changes: 8 additions & 4 deletions packages/events/src/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
)
})
Expand Down
9 changes: 7 additions & 2 deletions packages/events/src/service/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -115,7 +119,8 @@ export async function addAction(
actions: {
...input,
createdBy,
createdAt: now
createdAt: now,
createdAtLocation
}
}
}
Expand Down
Loading