@open-mercato/core 0.4.2-canary-7c76659938 → 0.4.2-canary-70c8402224
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/generated/entities/notification/index.js +57 -0
- package/dist/generated/entities/notification/index.js.map +7 -0
- package/dist/generated/entities.ids.generated.js +5 -1
- package/dist/generated/entities.ids.generated.js.map +2 -2
- package/dist/generated/entity-fields-registry.js +2 -0
- package/dist/generated/entity-fields-registry.js.map +2 -2
- package/dist/modules/api_docs/frontend/docs/api/page.js +3 -2
- package/dist/modules/api_docs/frontend/docs/api/page.js.map +2 -2
- package/dist/modules/auth/api/admin/nav.js +4 -3
- package/dist/modules/auth/api/admin/nav.js.map +2 -2
- package/dist/modules/auth/api/profile/route.js +155 -0
- package/dist/modules/auth/api/profile/route.js.map +7 -0
- package/dist/modules/auth/api/reset/confirm.js +25 -2
- package/dist/modules/auth/api/reset/confirm.js.map +2 -2
- package/dist/modules/auth/api/reset.js +23 -0
- package/dist/modules/auth/api/reset.js.map +2 -2
- package/dist/modules/auth/api/sidebar/preferences/route.js +14 -9
- package/dist/modules/auth/api/sidebar/preferences/route.js.map +2 -2
- package/dist/modules/auth/backend/auth/profile/page.js +99 -0
- package/dist/modules/auth/backend/auth/profile/page.js.map +7 -0
- package/dist/modules/auth/backend/auth/profile/page.meta.js +12 -0
- package/dist/modules/auth/backend/auth/profile/page.meta.js.map +7 -0
- package/dist/modules/auth/commands/users.js +55 -0
- package/dist/modules/auth/commands/users.js.map +2 -2
- package/dist/modules/auth/lib/setup-app.js +1 -0
- package/dist/modules/auth/lib/setup-app.js.map +2 -2
- package/dist/modules/auth/notifications.js +112 -0
- package/dist/modules/auth/notifications.js.map +7 -0
- package/dist/modules/auth/services/authService.js +3 -3
- package/dist/modules/auth/services/authService.js.map +2 -2
- package/dist/modules/business_rules/notifications.js +28 -0
- package/dist/modules/business_rules/notifications.js.map +7 -0
- package/dist/modules/business_rules/subscribers/rule-execution-failed-notification.js +37 -0
- package/dist/modules/business_rules/subscribers/rule-execution-failed-notification.js.map +7 -0
- package/dist/modules/catalog/notifications.js +28 -0
- package/dist/modules/catalog/notifications.js.map +7 -0
- package/dist/modules/catalog/subscribers/low-stock-notification.js +38 -0
- package/dist/modules/catalog/subscribers/low-stock-notification.js.map +7 -0
- package/dist/modules/configs/cli.js +6 -0
- package/dist/modules/configs/cli.js.map +2 -2
- package/dist/modules/customers/commands/deals.js +31 -0
- package/dist/modules/customers/commands/deals.js.map +2 -2
- package/dist/modules/customers/notifications.js +48 -0
- package/dist/modules/customers/notifications.js.map +7 -0
- package/dist/modules/notifications/acl.js +11 -0
- package/dist/modules/notifications/acl.js.map +7 -0
- package/dist/modules/notifications/api/[id]/action/route.js +69 -0
- package/dist/modules/notifications/api/[id]/action/route.js.map +7 -0
- package/dist/modules/notifications/api/[id]/dismiss/route.js +15 -0
- package/dist/modules/notifications/api/[id]/dismiss/route.js.map +7 -0
- package/dist/modules/notifications/api/[id]/read/route.js +15 -0
- package/dist/modules/notifications/api/[id]/read/route.js.map +7 -0
- package/dist/modules/notifications/api/[id]/restore/route.js +53 -0
- package/dist/modules/notifications/api/[id]/restore/route.js.map +7 -0
- package/dist/modules/notifications/api/batch/route.js +17 -0
- package/dist/modules/notifications/api/batch/route.js.map +7 -0
- package/dist/modules/notifications/api/feature/route.js +17 -0
- package/dist/modules/notifications/api/feature/route.js.map +7 -0
- package/dist/modules/notifications/api/mark-all-read/route.js +35 -0
- package/dist/modules/notifications/api/mark-all-read/route.js.map +7 -0
- package/dist/modules/notifications/api/openapi.js +57 -0
- package/dist/modules/notifications/api/openapi.js.map +7 -0
- package/dist/modules/notifications/api/role/route.js +17 -0
- package/dist/modules/notifications/api/role/route.js.map +7 -0
- package/dist/modules/notifications/api/route.js +85 -0
- package/dist/modules/notifications/api/route.js.map +7 -0
- package/dist/modules/notifications/api/settings/route.js +96 -0
- package/dist/modules/notifications/api/settings/route.js.map +7 -0
- package/dist/modules/notifications/api/unread-count/route.js +38 -0
- package/dist/modules/notifications/api/unread-count/route.js.map +7 -0
- package/dist/modules/notifications/backend/config/notifications/page.js +10 -0
- package/dist/modules/notifications/backend/config/notifications/page.js.map +7 -0
- package/dist/modules/notifications/backend/config/notifications/page.meta.js +24 -0
- package/dist/modules/notifications/backend/config/notifications/page.meta.js.map +7 -0
- package/dist/modules/notifications/cli.js +16 -0
- package/dist/modules/notifications/cli.js.map +7 -0
- package/dist/modules/notifications/data/entities.js +112 -0
- package/dist/modules/notifications/data/entities.js.map +7 -0
- package/dist/modules/notifications/data/validators.js +94 -0
- package/dist/modules/notifications/data/validators.js.map +7 -0
- package/dist/modules/notifications/di.js +13 -0
- package/dist/modules/notifications/di.js.map +7 -0
- package/dist/modules/notifications/emails/NotificationEmail.js +58 -0
- package/dist/modules/notifications/emails/NotificationEmail.js.map +7 -0
- package/dist/modules/notifications/frontend/NotificationInboxPageClient.js +44 -0
- package/dist/modules/notifications/frontend/NotificationInboxPageClient.js.map +7 -0
- package/dist/modules/notifications/frontend/NotificationSettingsPageClient.js +219 -0
- package/dist/modules/notifications/frontend/NotificationSettingsPageClient.js.map +7 -0
- package/dist/modules/notifications/index.js +14 -0
- package/dist/modules/notifications/index.js.map +7 -0
- package/dist/modules/notifications/lib/deliveryConfig.js +105 -0
- package/dist/modules/notifications/lib/deliveryConfig.js.map +7 -0
- package/dist/modules/notifications/lib/events.js +12 -0
- package/dist/modules/notifications/lib/events.js.map +7 -0
- package/dist/modules/notifications/lib/notificationBuilder.js +66 -0
- package/dist/modules/notifications/lib/notificationBuilder.js.map +7 -0
- package/dist/modules/notifications/lib/notificationFactory.js +54 -0
- package/dist/modules/notifications/lib/notificationFactory.js.map +7 -0
- package/dist/modules/notifications/lib/notificationMapper.js +34 -0
- package/dist/modules/notifications/lib/notificationMapper.js.map +7 -0
- package/dist/modules/notifications/lib/notificationRecipients.js +35 -0
- package/dist/modules/notifications/lib/notificationRecipients.js.map +7 -0
- package/dist/modules/notifications/lib/notificationService.js +279 -0
- package/dist/modules/notifications/lib/notificationService.js.map +7 -0
- package/dist/modules/notifications/lib/routeHelpers.js +101 -0
- package/dist/modules/notifications/lib/routeHelpers.js.map +7 -0
- package/dist/modules/notifications/lib/safeHref.js +24 -0
- package/dist/modules/notifications/lib/safeHref.js.map +7 -0
- package/dist/modules/notifications/migrations/Migration20260123000001.js +70 -0
- package/dist/modules/notifications/migrations/Migration20260123000001.js.map +7 -0
- package/dist/modules/notifications/migrations/Migration20260126150000.js +37 -0
- package/dist/modules/notifications/migrations/Migration20260126150000.js.map +7 -0
- package/dist/modules/notifications/subscribers/deliver-notification.js +139 -0
- package/dist/modules/notifications/subscribers/deliver-notification.js.map +7 -0
- package/dist/modules/notifications/workers/create-notification.worker.js +70 -0
- package/dist/modules/notifications/workers/create-notification.worker.js.map +7 -0
- package/dist/modules/sales/commands/documents.js +53 -0
- package/dist/modules/sales/commands/documents.js.map +2 -2
- package/dist/modules/sales/commands/payments.js +26 -0
- package/dist/modules/sales/commands/payments.js.map +2 -2
- package/dist/modules/sales/notifications.client.js +51 -0
- package/dist/modules/sales/notifications.client.js.map +7 -0
- package/dist/modules/sales/notifications.js +88 -0
- package/dist/modules/sales/notifications.js.map +7 -0
- package/dist/modules/sales/subscribers/quote-expiring-notification.js +38 -0
- package/dist/modules/sales/subscribers/quote-expiring-notification.js.map +7 -0
- package/dist/modules/sales/widgets/notifications/SalesOrderCreatedRenderer.js +137 -0
- package/dist/modules/sales/widgets/notifications/SalesOrderCreatedRenderer.js.map +7 -0
- package/dist/modules/sales/widgets/notifications/SalesQuoteCreatedRenderer.js +137 -0
- package/dist/modules/sales/widgets/notifications/SalesQuoteCreatedRenderer.js.map +7 -0
- package/dist/modules/sales/widgets/notifications/index.js +7 -0
- package/dist/modules/sales/widgets/notifications/index.js.map +7 -0
- package/dist/modules/sales/widgets/notifications/useSalesDocumentTotals.js +60 -0
- package/dist/modules/sales/widgets/notifications/useSalesDocumentTotals.js.map +7 -0
- package/dist/modules/staff/commands/leave-requests.js +79 -0
- package/dist/modules/staff/commands/leave-requests.js.map +2 -2
- package/dist/modules/staff/notifications.js +75 -0
- package/dist/modules/staff/notifications.js.map +7 -0
- package/dist/modules/workflows/notifications.js +28 -0
- package/dist/modules/workflows/notifications.js.map +7 -0
- package/dist/modules/workflows/subscribers/task-assigned-notification.js +38 -0
- package/dist/modules/workflows/subscribers/task-assigned-notification.js.map +7 -0
- package/generated/entities/notification/index.ts +27 -0
- package/generated/entities.ids.generated.ts +5 -1
- package/generated/entity-fields-registry.ts +2 -0
- package/package.json +2 -2
- package/src/modules/api_docs/frontend/docs/api/page.tsx +3 -2
- package/src/modules/auth/api/admin/nav.ts +10 -6
- package/src/modules/auth/api/profile/route.ts +160 -0
- package/src/modules/auth/api/reset/confirm.ts +25 -2
- package/src/modules/auth/api/reset.ts +23 -0
- package/src/modules/auth/api/sidebar/preferences/route.ts +21 -12
- package/src/modules/auth/backend/auth/profile/page.meta.ts +8 -0
- package/src/modules/auth/backend/auth/profile/page.tsx +127 -0
- package/src/modules/auth/commands/users.ts +68 -0
- package/src/modules/auth/i18n/de.json +29 -1
- package/src/modules/auth/i18n/en.json +29 -1
- package/src/modules/auth/i18n/es.json +29 -1
- package/src/modules/auth/i18n/pl.json +29 -1
- package/src/modules/auth/lib/setup-app.ts +1 -0
- package/src/modules/auth/notifications.ts +109 -0
- package/src/modules/auth/services/authService.ts +4 -4
- package/src/modules/business_rules/i18n/en.json +3 -1
- package/src/modules/business_rules/notifications.ts +25 -0
- package/src/modules/business_rules/subscribers/rule-execution-failed-notification.ts +50 -0
- package/src/modules/catalog/i18n/en.json +3 -1
- package/src/modules/catalog/notifications.ts +25 -0
- package/src/modules/catalog/subscribers/low-stock-notification.ts +52 -0
- package/src/modules/configs/cli.ts +6 -0
- package/src/modules/customers/commands/deals.ts +39 -0
- package/src/modules/customers/i18n/en.json +5 -1
- package/src/modules/customers/notifications.ts +44 -0
- package/src/modules/notifications/acl.ts +7 -0
- package/src/modules/notifications/api/[id]/action/route.ts +70 -0
- package/src/modules/notifications/api/[id]/dismiss/route.ts +12 -0
- package/src/modules/notifications/api/[id]/read/route.ts +12 -0
- package/src/modules/notifications/api/[id]/restore/route.ts +53 -0
- package/src/modules/notifications/api/batch/route.ts +14 -0
- package/src/modules/notifications/api/feature/route.ts +14 -0
- package/src/modules/notifications/api/mark-all-read/route.ts +34 -0
- package/src/modules/notifications/api/openapi.ts +52 -0
- package/src/modules/notifications/api/role/route.ts +14 -0
- package/src/modules/notifications/api/route.ts +92 -0
- package/src/modules/notifications/api/settings/route.ts +98 -0
- package/src/modules/notifications/api/unread-count/route.ts +38 -0
- package/src/modules/notifications/backend/config/notifications/page.meta.ts +22 -0
- package/src/modules/notifications/backend/config/notifications/page.tsx +12 -0
- package/src/modules/notifications/cli.ts +18 -0
- package/src/modules/notifications/data/entities.ts +99 -0
- package/src/modules/notifications/data/validators.ts +110 -0
- package/src/modules/notifications/di.ts +11 -0
- package/src/modules/notifications/emails/NotificationEmail.tsx +98 -0
- package/src/modules/notifications/frontend/NotificationInboxPageClient.tsx +42 -0
- package/src/modules/notifications/frontend/NotificationSettingsPageClient.tsx +231 -0
- package/src/modules/notifications/i18n/de.json +50 -0
- package/src/modules/notifications/i18n/en.json +50 -0
- package/src/modules/notifications/i18n/es.json +50 -0
- package/src/modules/notifications/i18n/pl.json +50 -0
- package/src/modules/notifications/index.ts +12 -0
- package/src/modules/notifications/lib/deliveryConfig.ts +145 -0
- package/src/modules/notifications/lib/events.ts +48 -0
- package/src/modules/notifications/lib/notificationBuilder.ts +121 -0
- package/src/modules/notifications/lib/notificationFactory.ts +76 -0
- package/src/modules/notifications/lib/notificationMapper.ts +33 -0
- package/src/modules/notifications/lib/notificationRecipients.ts +83 -0
- package/src/modules/notifications/lib/notificationService.ts +414 -0
- package/src/modules/notifications/lib/routeHelpers.ts +151 -0
- package/src/modules/notifications/lib/safeHref.ts +29 -0
- package/src/modules/notifications/migrations/.snapshot-open-mercato.json +300 -0
- package/src/modules/notifications/migrations/Migration20260123000001.ts +73 -0
- package/src/modules/notifications/migrations/Migration20260126150000.ts +39 -0
- package/src/modules/notifications/subscribers/deliver-notification.ts +175 -0
- package/src/modules/notifications/workers/create-notification.worker.ts +122 -0
- package/src/modules/sales/commands/documents.ts +65 -0
- package/src/modules/sales/commands/payments.ts +33 -0
- package/src/modules/sales/i18n/de.json +20 -0
- package/src/modules/sales/i18n/en.json +25 -1
- package/src/modules/sales/i18n/es.json +20 -0
- package/src/modules/sales/i18n/pl.json +20 -0
- package/src/modules/sales/notifications.client.ts +65 -0
- package/src/modules/sales/notifications.ts +82 -0
- package/src/modules/sales/subscribers/quote-expiring-notification.ts +53 -0
- package/src/modules/sales/widgets/notifications/SalesOrderCreatedRenderer.tsx +156 -0
- package/src/modules/sales/widgets/notifications/SalesQuoteCreatedRenderer.tsx +156 -0
- package/src/modules/sales/widgets/notifications/index.ts +2 -0
- package/src/modules/sales/widgets/notifications/useSalesDocumentTotals.ts +81 -0
- package/src/modules/staff/commands/leave-requests.ts +94 -0
- package/src/modules/staff/i18n/de.json +4 -0
- package/src/modules/staff/i18n/en.json +9 -1
- package/src/modules/staff/i18n/es.json +4 -0
- package/src/modules/staff/i18n/pl.json +4 -0
- package/src/modules/staff/notifications.ts +71 -0
- package/src/modules/workflows/i18n/en.json +3 -1
- package/src/modules/workflows/notifications.ts +25 -0
- package/src/modules/workflows/subscribers/task-assigned-notification.ts +53 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/modules/staff/commands/leave-requests.ts"],
|
|
4
|
-
"sourcesContent": ["import { randomUUID } from 'crypto'\nimport type { CommandHandler, CommandRuntimeContext } from '@open-mercato/shared/lib/commands'\nimport { registerCommand } from '@open-mercato/shared/lib/commands'\nimport type { EntityManager } from '@mikro-orm/postgresql'\nimport { CrudHttpError } from '@open-mercato/shared/lib/crud/errors'\nimport { resolveTranslations } from '@open-mercato/shared/lib/i18n/server'\nimport { emitCrudSideEffects, emitCrudUndoSideEffects, buildChanges } from '@open-mercato/shared/lib/commands/helpers'\nimport type { CrudIndexerConfig } from '@open-mercato/shared/lib/crud/types'\nimport type { DataEngine } from '@open-mercato/shared/lib/data/engine'\nimport { invalidateCrudCache } from '@open-mercato/shared/lib/crud/cache'\nimport { findOneWithDecryption } from '@open-mercato/shared/lib/encryption/find'\nimport { PlannerAvailabilityRule } from '@open-mercato/core/modules/planner/data/entities'\nimport { StaffLeaveRequest, type StaffLeaveRequestStatus } from '../data/entities'\nimport {\n staffLeaveRequestCreateSchema,\n staffLeaveRequestDecisionSchema,\n staffLeaveRequestUpdateSchema,\n type StaffLeaveRequestCreateInput,\n type StaffLeaveRequestDecisionInput,\n type StaffLeaveRequestUpdateInput,\n} from '../data/validators'\nimport { ensureOrganizationScope, ensureTenantScope, extractUndoPayload, requireTeamMember } from './shared'\nimport { E } from '#generated/entities.ids.generated'\n\nconst leaveRequestCrudIndexer: CrudIndexerConfig<StaffLeaveRequest> = {\n entityType: E.staff.staff_leave_request,\n}\n\nconst availabilityRuleCrudIndexer: CrudIndexerConfig<PlannerAvailabilityRule> = {\n entityType: E.planner.planner_availability_rule,\n cacheAliases: ['planner.availability'],\n}\n\ntype LeaveRequestSnapshot = {\n id: string\n tenantId: string\n organizationId: string\n memberId: string\n startDate: string\n endDate: string\n timezone: string\n status: StaffLeaveRequestStatus\n unavailabilityReasonEntryId: string | null\n unavailabilityReasonValue: string | null\n note: string | null\n decisionComment: string | null\n submittedByUserId: string | null\n decidedByUserId: string | null\n decidedAt: string | null\n deletedAt: string | null\n createdAt: string | null\n updatedAt: string | null\n}\n\ntype LeaveRequestUndoPayload = {\n before?: LeaveRequestSnapshot | null\n after?: LeaveRequestSnapshot | null\n availabilityRuleIds?: string[]\n}\n\nfunction parseUuidCandidate(value: string | null | undefined): string | null {\n if (!value) return null\n const uuidRegex = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/\n return uuidRegex.test(value) ? value : null\n}\n\nfunction resolveAuthUserId(ctx: { auth?: { sub?: string | null; isApiKey?: boolean } | null }): string | null {\n if (!ctx.auth || ctx.auth.isApiKey) return null\n return parseUuidCandidate(ctx.auth.sub ?? null)\n}\n\nfunction formatDateKey(value: Date): string {\n const year = value.getUTCFullYear()\n const month = String(value.getUTCMonth() + 1).padStart(2, '0')\n const day = String(value.getUTCDate()).padStart(2, '0')\n return `${year}-${month}-${day}`\n}\n\nfunction listDateKeysInRange(start: Date, end: Date): string[] {\n const dates: string[] = []\n const current = new Date(Date.UTC(start.getUTCFullYear(), start.getUTCMonth(), start.getUTCDate()))\n const last = new Date(Date.UTC(end.getUTCFullYear(), end.getUTCMonth(), end.getUTCDate()))\n while (current <= last) {\n dates.push(formatDateKey(current))\n current.setUTCDate(current.getUTCDate() + 1)\n }\n return dates\n}\n\nfunction formatDuration(minutes: number): string {\n const clamped = Math.max(1, minutes)\n const hours = Math.floor(clamped / 60)\n const mins = clamped % 60\n if (hours > 0 && mins > 0) return `PT${hours}H${mins}M`\n if (hours > 0) return `PT${hours}H`\n return `PT${mins}M`\n}\n\nfunction buildAvailabilityRrule(start: Date, end: Date): string {\n const dtStart = start.toISOString().replace(/[-:]/g, '').split('.')[0] + 'Z'\n const durationMinutes = Math.max(1, Math.round((end.getTime() - start.getTime()) / 60000))\n const duration = formatDuration(durationMinutes)\n return `DTSTART:${dtStart}\\nDURATION:${duration}\\nRRULE:FREQ=DAILY;COUNT=1`\n}\n\nfunction buildFullDayRrule(date: string): string | null {\n const [year, month, day] = date.split('-').map((part) => Number(part))\n if (!Number.isFinite(year) || !Number.isFinite(month) || !Number.isFinite(day)) return null\n const start = new Date(Date.UTC(year, month - 1, day, 0, 0, 0))\n const end = new Date(start.getTime() + 24 * 60 * 60 * 1000)\n return buildAvailabilityRrule(start, end)\n}\n\nasync function loadLeaveRequestSnapshot(em: EntityManager, id: string): Promise<LeaveRequestSnapshot | null> {\n const request = await findOneWithDecryption(em, StaffLeaveRequest, { id }, undefined, { tenantId: null, organizationId: null })\n if (!request) return null\n const memberId = typeof request.member === 'string' ? request.member : request.member.id\n return {\n id: request.id,\n tenantId: request.tenantId,\n organizationId: request.organizationId,\n memberId,\n startDate: request.startDate.toISOString(),\n endDate: request.endDate.toISOString(),\n timezone: request.timezone,\n status: request.status,\n unavailabilityReasonEntryId: request.unavailabilityReasonEntryId ?? null,\n unavailabilityReasonValue: request.unavailabilityReasonValue ?? null,\n note: request.note ?? null,\n decisionComment: request.decisionComment ?? null,\n submittedByUserId: request.submittedByUserId ?? null,\n decidedByUserId: request.decidedByUserId ?? null,\n decidedAt: request.decidedAt ? request.decidedAt.toISOString() : null,\n deletedAt: request.deletedAt ? request.deletedAt.toISOString() : null,\n createdAt: request.createdAt ? request.createdAt.toISOString() : null,\n updatedAt: request.updatedAt ? request.updatedAt.toISOString() : null,\n }\n}\n\nasync function requireLeaveRequest(em: EntityManager, id: string): Promise<StaffLeaveRequest> {\n const request = await findOneWithDecryption(em, StaffLeaveRequest, { id, deletedAt: null }, undefined, { tenantId: null, organizationId: null })\n if (!request) throw new CrudHttpError(404, { error: 'Leave request not found.' })\n return request\n}\n\nfunction ensurePendingStatus(request: StaffLeaveRequest): void {\n if (request.status !== 'pending') {\n throw new CrudHttpError(400, { error: 'Leave request is already finalized.' })\n }\n}\n\nasync function createUnavailabilityRules(params: {\n em: EntityManager\n tenantId: string\n organizationId: string\n memberId: string\n timezone: string\n dates: string[]\n note: string | null\n reasonEntryId: string | null\n reasonValue: string | null\n}): Promise<string[]> {\n const now = new Date()\n const createdIds: string[] = []\n params.dates.forEach((date) => {\n const rrule = buildFullDayRrule(date)\n if (!rrule) return\n const ruleId = randomUUID()\n const rule = params.em.create(PlannerAvailabilityRule, {\n id: ruleId,\n tenantId: params.tenantId,\n organizationId: params.organizationId,\n subjectType: 'member',\n subjectId: params.memberId,\n timezone: params.timezone,\n rrule,\n exdates: [],\n kind: 'unavailability',\n note: params.note,\n unavailabilityReasonEntryId: params.reasonEntryId,\n unavailabilityReasonValue: params.reasonValue,\n createdAt: now,\n updatedAt: now,\n deletedAt: null,\n })\n params.em.persist(rule)\n createdIds.push(ruleId)\n })\n return createdIds\n}\n\nasync function invalidateAvailabilityCache(params: {\n container: CommandRuntimeContext['container']\n tenantId: string | null\n organizationId: string | null\n ruleIds: string[]\n}) {\n if (!params.ruleIds.length) return\n const resource = 'planner.availability'\n const fallbackTenant = params.tenantId ?? null\n for (const ruleId of params.ruleIds) {\n await invalidateCrudCache(\n params.container,\n resource,\n { id: ruleId, organizationId: params.organizationId, tenantId: params.tenantId },\n fallbackTenant,\n 'updated',\n )\n }\n}\n\nconst createLeaveRequestCommand: CommandHandler<StaffLeaveRequestCreateInput, { requestId: string }> = {\n id: 'staff.leave-requests.create',\n async execute(rawInput, ctx) {\n const parsed = staffLeaveRequestCreateSchema.parse(rawInput)\n ensureTenantScope(ctx, parsed.tenantId)\n ensureOrganizationScope(ctx, parsed.organizationId)\n\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const member = await requireTeamMember(em, parsed.memberId, 'Team member not found')\n ensureTenantScope(ctx, member.tenantId)\n ensureOrganizationScope(ctx, member.organizationId)\n\n const submittedByUserId = parsed.submittedByUserId ?? resolveAuthUserId(ctx)\n const now = new Date()\n const request = em.create(StaffLeaveRequest, {\n tenantId: parsed.tenantId,\n organizationId: parsed.organizationId,\n member,\n startDate: parsed.startDate,\n endDate: parsed.endDate,\n timezone: parsed.timezone,\n status: 'pending',\n unavailabilityReasonEntryId: parsed.unavailabilityReasonEntryId ?? null,\n unavailabilityReasonValue: parsed.unavailabilityReasonValue ?? null,\n note: parsed.note ?? null,\n decisionComment: null,\n submittedByUserId,\n decidedByUserId: null,\n decidedAt: null,\n createdAt: now,\n updatedAt: now,\n deletedAt: null,\n })\n em.persist(request)\n await em.flush()\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudSideEffects({\n dataEngine: de,\n action: 'created',\n entity: request,\n identifiers: {\n id: request.id,\n organizationId: request.organizationId,\n tenantId: request.tenantId,\n },\n indexer: leaveRequestCrudIndexer,\n })\n\n return { requestId: request.id }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = (ctx.container.resolve('em') as EntityManager)\n return await loadLeaveRequestSnapshot(em, result.requestId)\n },\n buildLog: async ({ result, ctx }) => {\n const { translate } = await resolveTranslations()\n const em = (ctx.container.resolve('em') as EntityManager)\n const snapshot = await loadLeaveRequestSnapshot(em, result.requestId)\n return {\n actionLabel: translate('staff.audit.leaveRequests.create', 'Create leave request'),\n resourceKind: 'staff.leave_request',\n resourceId: result.requestId,\n tenantId: snapshot?.tenantId ?? null,\n organizationId: snapshot?.organizationId ?? null,\n snapshotAfter: snapshot ?? null,\n payload: {\n undo: {\n after: snapshot ?? null,\n } satisfies LeaveRequestUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<LeaveRequestUndoPayload>(logEntry)\n const after = payload?.after\n if (!after) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const request = await em.findOne(StaffLeaveRequest, { id: after.id })\n if (request) {\n request.deletedAt = new Date()\n request.updatedAt = new Date()\n await em.flush()\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudUndoSideEffects({\n dataEngine: de,\n action: 'deleted',\n entity: request,\n identifiers: {\n id: request.id,\n organizationId: request.organizationId,\n tenantId: request.tenantId,\n },\n indexer: leaveRequestCrudIndexer,\n })\n }\n },\n}\n\nconst updateLeaveRequestCommand: CommandHandler<StaffLeaveRequestUpdateInput, { requestId: string }> = {\n id: 'staff.leave-requests.update',\n async prepare(rawInput, ctx) {\n const parsed = staffLeaveRequestUpdateSchema.parse(rawInput)\n const em = (ctx.container.resolve('em') as EntityManager)\n const snapshot = await loadLeaveRequestSnapshot(em, parsed.id)\n return snapshot ? { before: snapshot } : {}\n },\n async execute(rawInput, ctx) {\n const parsed = staffLeaveRequestUpdateSchema.parse(rawInput)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const request = await requireLeaveRequest(em, parsed.id)\n ensureTenantScope(ctx, request.tenantId)\n ensureOrganizationScope(ctx, request.organizationId)\n ensurePendingStatus(request)\n\n if (parsed.memberId !== undefined) {\n const member = await requireTeamMember(em, parsed.memberId, 'Team member not found')\n ensureTenantScope(ctx, member.tenantId)\n ensureOrganizationScope(ctx, member.organizationId)\n request.member = member\n }\n if (parsed.startDate !== undefined) request.startDate = parsed.startDate\n if (parsed.endDate !== undefined) request.endDate = parsed.endDate\n if (parsed.timezone !== undefined) request.timezone = parsed.timezone\n if (parsed.unavailabilityReasonEntryId !== undefined) request.unavailabilityReasonEntryId = parsed.unavailabilityReasonEntryId ?? null\n if (parsed.unavailabilityReasonValue !== undefined) request.unavailabilityReasonValue = parsed.unavailabilityReasonValue ?? null\n if (parsed.note !== undefined) request.note = parsed.note ?? null\n request.updatedAt = new Date()\n await em.flush()\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudSideEffects({\n dataEngine: de,\n action: 'updated',\n entity: request,\n identifiers: {\n id: request.id,\n organizationId: request.organizationId,\n tenantId: request.tenantId,\n },\n indexer: leaveRequestCrudIndexer,\n })\n\n return { requestId: request.id }\n },\n buildLog: async ({ snapshots, ctx }) => {\n const { translate } = await resolveTranslations()\n const before = snapshots.before as LeaveRequestSnapshot | undefined\n if (!before) return null\n const em = (ctx.container.resolve('em') as EntityManager)\n const after = await loadLeaveRequestSnapshot(em, before.id)\n const changes = after\n ? buildChanges(before as unknown as Record<string, unknown>, after as unknown as Record<string, unknown>, [\n 'memberId',\n 'startDate',\n 'endDate',\n 'timezone',\n 'unavailabilityReasonEntryId',\n 'unavailabilityReasonValue',\n 'note',\n ])\n : {}\n return {\n actionLabel: translate('staff.audit.leaveRequests.update', 'Update leave request'),\n resourceKind: 'staff.leave_request',\n resourceId: before.id,\n tenantId: before.tenantId,\n organizationId: before.organizationId,\n snapshotBefore: before,\n snapshotAfter: after ?? null,\n changes,\n payload: {\n undo: {\n before,\n after: after ?? null,\n } satisfies LeaveRequestUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<LeaveRequestUndoPayload>(logEntry)\n const before = payload?.before\n const after = payload?.after\n if (!before || !after) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const request = await em.findOne(StaffLeaveRequest, { id: after.id })\n if (!request) return\n request.startDate = new Date(before.startDate)\n request.endDate = new Date(before.endDate)\n request.timezone = before.timezone\n request.status = before.status\n request.unavailabilityReasonEntryId = before.unavailabilityReasonEntryId\n request.unavailabilityReasonValue = before.unavailabilityReasonValue\n request.note = before.note\n request.decisionComment = before.decisionComment\n request.decidedByUserId = before.decidedByUserId\n request.decidedAt = before.decidedAt ? new Date(before.decidedAt) : null\n request.updatedAt = new Date()\n await em.flush()\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudUndoSideEffects({\n dataEngine: de,\n action: 'updated',\n entity: request,\n identifiers: {\n id: request.id,\n organizationId: request.organizationId,\n tenantId: request.tenantId,\n },\n indexer: leaveRequestCrudIndexer,\n })\n },\n}\n\nconst deleteLeaveRequestCommand: CommandHandler<{ id: string }, { requestId: string }> = {\n id: 'staff.leave-requests.delete',\n async execute(rawInput, ctx) {\n const parsed = staffLeaveRequestDecisionSchema.pick({ id: true }).parse(rawInput)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const request = await requireLeaveRequest(em, parsed.id)\n ensureTenantScope(ctx, request.tenantId)\n ensureOrganizationScope(ctx, request.organizationId)\n ensurePendingStatus(request)\n\n request.deletedAt = new Date()\n request.updatedAt = new Date()\n await em.flush()\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudSideEffects({\n dataEngine: de,\n action: 'deleted',\n entity: request,\n identifiers: {\n id: request.id,\n organizationId: request.organizationId,\n tenantId: request.tenantId,\n },\n indexer: leaveRequestCrudIndexer,\n })\n\n return { requestId: request.id }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = (ctx.container.resolve('em') as EntityManager)\n return await loadLeaveRequestSnapshot(em, result.requestId)\n },\n buildLog: async ({ result, ctx }) => {\n const { translate } = await resolveTranslations()\n const em = (ctx.container.resolve('em') as EntityManager)\n const snapshot = await loadLeaveRequestSnapshot(em, result.requestId)\n return {\n actionLabel: translate('staff.audit.leaveRequests.delete', 'Delete leave request'),\n resourceKind: 'staff.leave_request',\n resourceId: result.requestId,\n tenantId: snapshot?.tenantId ?? null,\n organizationId: snapshot?.organizationId ?? null,\n snapshotAfter: snapshot ?? null,\n payload: {\n undo: {\n after: snapshot ?? null,\n } satisfies LeaveRequestUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<LeaveRequestUndoPayload>(logEntry)\n const after = payload?.after\n if (!after) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const request = await em.findOne(StaffLeaveRequest, { id: after.id })\n if (!request) return\n request.deletedAt = null\n request.updatedAt = new Date()\n await em.flush()\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudUndoSideEffects({\n dataEngine: de,\n action: 'created',\n entity: request,\n identifiers: {\n id: request.id,\n organizationId: request.organizationId,\n tenantId: request.tenantId,\n },\n indexer: leaveRequestCrudIndexer,\n })\n },\n}\n\nconst acceptLeaveRequestCommand: CommandHandler<StaffLeaveRequestDecisionInput, { requestId: string; ruleIds: string[] }> = {\n id: 'staff.leave-requests.accept',\n async execute(rawInput, ctx) {\n const parsed = staffLeaveRequestDecisionSchema.parse(rawInput)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const request = await requireLeaveRequest(em, parsed.id)\n ensureTenantScope(ctx, request.tenantId)\n ensureOrganizationScope(ctx, request.organizationId)\n ensurePendingStatus(request)\n\n const memberId = typeof request.member === 'string' ? request.member : request.member.id\n const decidedByUserId = parsed.decidedByUserId ?? resolveAuthUserId(ctx)\n const now = new Date()\n const dates = listDateKeysInRange(request.startDate, request.endDate)\n let createdRuleIds: string[] = []\n\n await em.transactional(async (trx) => {\n request.status = 'approved'\n request.decisionComment = parsed.decisionComment ?? null\n request.decidedByUserId = decidedByUserId\n request.decidedAt = now\n request.updatedAt = now\n trx.persist(request)\n\n createdRuleIds = await createUnavailabilityRules({\n em: trx,\n tenantId: request.tenantId,\n organizationId: request.organizationId,\n memberId,\n timezone: request.timezone,\n dates,\n note: request.note ?? null,\n reasonEntryId: request.unavailabilityReasonEntryId ?? null,\n reasonValue: request.unavailabilityReasonValue ?? null,\n })\n await trx.flush()\n })\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudSideEffects({\n dataEngine: de,\n action: 'updated',\n entity: request,\n identifiers: {\n id: request.id,\n organizationId: request.organizationId,\n tenantId: request.tenantId,\n },\n indexer: leaveRequestCrudIndexer,\n })\n if (createdRuleIds.length) {\n const rules = await em.find(PlannerAvailabilityRule, { id: { $in: createdRuleIds } })\n for (const rule of rules) {\n await emitCrudSideEffects({\n dataEngine: de,\n action: 'created',\n entity: rule,\n identifiers: {\n id: rule.id,\n organizationId: rule.organizationId,\n tenantId: rule.tenantId,\n },\n indexer: availabilityRuleCrudIndexer,\n })\n }\n }\n await invalidateAvailabilityCache({\n container: ctx.container,\n tenantId: request.tenantId,\n organizationId: request.organizationId,\n ruleIds: createdRuleIds,\n })\n\n return { requestId: request.id, ruleIds: createdRuleIds }\n },\n buildLog: async ({ result, ctx, snapshots }) => {\n const { translate } = await resolveTranslations()\n const before = snapshots.before as LeaveRequestSnapshot | undefined\n const em = (ctx.container.resolve('em') as EntityManager)\n const after = await loadLeaveRequestSnapshot(em, result.requestId)\n return {\n actionLabel: translate('staff.audit.leaveRequests.accept', 'Approve leave request'),\n resourceKind: 'staff.leave_request',\n resourceId: result.requestId,\n tenantId: after?.tenantId ?? before?.tenantId ?? null,\n organizationId: after?.organizationId ?? before?.organizationId ?? null,\n snapshotBefore: before ?? null,\n snapshotAfter: after ?? null,\n payload: {\n undo: {\n before: before ?? null,\n after: after ?? null,\n availabilityRuleIds: result.ruleIds,\n } satisfies LeaveRequestUndoPayload,\n },\n }\n },\n async prepare(rawInput, ctx) {\n const parsed = staffLeaveRequestDecisionSchema.parse(rawInput)\n const em = (ctx.container.resolve('em') as EntityManager)\n const snapshot = await loadLeaveRequestSnapshot(em, parsed.id)\n return snapshot ? { before: snapshot } : {}\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<LeaveRequestUndoPayload>(logEntry)\n const before = payload?.before\n const availabilityRuleIds = payload?.availabilityRuleIds ?? []\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const request = await em.findOne(StaffLeaveRequest, { id: before.id })\n if (!request) return\n request.status = before.status\n request.decisionComment = before.decisionComment\n request.decidedByUserId = before.decidedByUserId\n request.decidedAt = before.decidedAt ? new Date(before.decidedAt) : null\n request.updatedAt = new Date()\n await em.flush()\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudUndoSideEffects({\n dataEngine: de,\n action: 'updated',\n entity: request,\n identifiers: {\n id: request.id,\n organizationId: request.organizationId,\n tenantId: request.tenantId,\n },\n indexer: leaveRequestCrudIndexer,\n })\n\n if (availabilityRuleIds.length) {\n const rules = await em.find(PlannerAvailabilityRule, { id: { $in: availabilityRuleIds } })\n const now = new Date()\n rules.forEach((rule) => {\n rule.deletedAt = now\n rule.updatedAt = now\n })\n await em.flush()\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n for (const rule of rules) {\n await emitCrudUndoSideEffects({\n dataEngine: de,\n action: 'deleted',\n entity: rule,\n identifiers: {\n id: rule.id,\n organizationId: rule.organizationId,\n tenantId: rule.tenantId,\n },\n indexer: availabilityRuleCrudIndexer,\n })\n }\n }\n await invalidateAvailabilityCache({\n container: ctx.container,\n tenantId: before.tenantId,\n organizationId: before.organizationId,\n ruleIds: availabilityRuleIds,\n })\n },\n}\n\nconst rejectLeaveRequestCommand: CommandHandler<StaffLeaveRequestDecisionInput, { requestId: string }> = {\n id: 'staff.leave-requests.reject',\n async execute(rawInput, ctx) {\n const parsed = staffLeaveRequestDecisionSchema.parse(rawInput)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const request = await requireLeaveRequest(em, parsed.id)\n ensureTenantScope(ctx, request.tenantId)\n ensureOrganizationScope(ctx, request.organizationId)\n ensurePendingStatus(request)\n\n request.status = 'rejected'\n request.decisionComment = parsed.decisionComment ?? null\n request.decidedByUserId = parsed.decidedByUserId ?? resolveAuthUserId(ctx)\n request.decidedAt = new Date()\n request.updatedAt = new Date()\n await em.flush()\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudSideEffects({\n dataEngine: de,\n action: 'updated',\n entity: request,\n identifiers: {\n id: request.id,\n organizationId: request.organizationId,\n tenantId: request.tenantId,\n },\n indexer: leaveRequestCrudIndexer,\n })\n\n return { requestId: request.id }\n },\n async prepare(rawInput, ctx) {\n const parsed = staffLeaveRequestDecisionSchema.parse(rawInput)\n const em = (ctx.container.resolve('em') as EntityManager)\n const snapshot = await loadLeaveRequestSnapshot(em, parsed.id)\n return snapshot ? { before: snapshot } : {}\n },\n buildLog: async ({ result, ctx, snapshots }) => {\n const { translate } = await resolveTranslations()\n const before = snapshots.before as LeaveRequestSnapshot | undefined\n const em = (ctx.container.resolve('em') as EntityManager)\n const after = await loadLeaveRequestSnapshot(em, result.requestId)\n return {\n actionLabel: translate('staff.audit.leaveRequests.reject', 'Reject leave request'),\n resourceKind: 'staff.leave_request',\n resourceId: result.requestId,\n tenantId: after?.tenantId ?? before?.tenantId ?? null,\n organizationId: after?.organizationId ?? before?.organizationId ?? null,\n snapshotBefore: before ?? null,\n snapshotAfter: after ?? null,\n payload: {\n undo: {\n before: before ?? null,\n after: after ?? null,\n } satisfies LeaveRequestUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<LeaveRequestUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const request = await em.findOne(StaffLeaveRequest, { id: before.id })\n if (!request) return\n request.status = before.status\n request.decisionComment = before.decisionComment\n request.decidedByUserId = before.decidedByUserId\n request.decidedAt = before.decidedAt ? new Date(before.decidedAt) : null\n request.updatedAt = new Date()\n await em.flush()\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudUndoSideEffects({\n dataEngine: de,\n action: 'updated',\n entity: request,\n identifiers: {\n id: request.id,\n organizationId: request.organizationId,\n tenantId: request.tenantId,\n },\n indexer: leaveRequestCrudIndexer,\n })\n },\n}\n\nregisterCommand(createLeaveRequestCommand)\nregisterCommand(updateLeaveRequestCommand)\nregisterCommand(deleteLeaveRequestCommand)\nregisterCommand(acceptLeaveRequestCommand)\nregisterCommand(rejectLeaveRequestCommand)\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,kBAAkB;AAE3B,SAAS,uBAAuB;AAEhC,SAAS,qBAAqB;AAC9B,SAAS,2BAA2B;AACpC,SAAS,qBAAqB,yBAAyB,oBAAoB;AAG3E,SAAS,2BAA2B;AACpC,SAAS,6BAA6B;AACtC,SAAS,+BAA+B;AACxC,SAAS,yBAAuD;AAChE;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AACP,SAAS,yBAAyB,mBAAmB,oBAAoB,yBAAyB;AAClG,SAAS,SAAS;AAElB,MAAM,0BAAgE;AAAA,EACpE,YAAY,EAAE,MAAM;AACtB;AAEA,MAAM,8BAA0E;AAAA,EAC9E,YAAY,EAAE,QAAQ;AAAA,EACtB,cAAc,CAAC,sBAAsB;AACvC;AA6BA,SAAS,mBAAmB,OAAiD;AAC3E,MAAI,CAAC,MAAO,QAAO;AACnB,QAAM,YAAY;AAClB,SAAO,UAAU,KAAK,KAAK,IAAI,QAAQ;AACzC;AAEA,SAAS,kBAAkB,KAAmF;AAC5G,MAAI,CAAC,IAAI,QAAQ,IAAI,KAAK,SAAU,Q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ommandHandler, CommandRuntimeContext } from '@open-mercato/shared/lib/commands'\nimport { registerCommand } from '@open-mercato/shared/lib/commands'\nimport type { EntityManager } from '@mikro-orm/postgresql'\nimport { CrudHttpError } from '@open-mercato/shared/lib/crud/errors'\nimport { resolveTranslations } from '@open-mercato/shared/lib/i18n/server'\nimport { emitCrudSideEffects, emitCrudUndoSideEffects, buildChanges } from '@open-mercato/shared/lib/commands/helpers'\nimport type { CrudIndexerConfig } from '@open-mercato/shared/lib/crud/types'\nimport type { DataEngine } from '@open-mercato/shared/lib/data/engine'\nimport { invalidateCrudCache } from '@open-mercato/shared/lib/crud/cache'\nimport { findOneWithDecryption } from '@open-mercato/shared/lib/encryption/find'\nimport { PlannerAvailabilityRule } from '@open-mercato/core/modules/planner/data/entities'\nimport { StaffLeaveRequest, type StaffLeaveRequestStatus } from '../data/entities'\nimport {\n staffLeaveRequestCreateSchema,\n staffLeaveRequestDecisionSchema,\n staffLeaveRequestUpdateSchema,\n type StaffLeaveRequestCreateInput,\n type StaffLeaveRequestDecisionInput,\n type StaffLeaveRequestUpdateInput,\n} from '../data/validators'\nimport { ensureOrganizationScope, ensureTenantScope, extractUndoPayload, requireTeamMember } from './shared'\nimport { E } from '#generated/entities.ids.generated'\nimport { resolveNotificationService } from '../../notifications/lib/notificationService'\nimport { buildFeatureNotificationFromType, buildNotificationFromType } from '../../notifications/lib/notificationBuilder'\nimport { notificationTypes } from '../notifications'\n\nconst leaveRequestCrudIndexer: CrudIndexerConfig<StaffLeaveRequest> = {\n entityType: E.staff.staff_leave_request,\n}\n\nconst availabilityRuleCrudIndexer: CrudIndexerConfig<PlannerAvailabilityRule> = {\n entityType: E.planner.planner_availability_rule,\n cacheAliases: ['planner.availability'],\n}\n\ntype LeaveRequestSnapshot = {\n id: string\n tenantId: string\n organizationId: string\n memberId: string\n startDate: string\n endDate: string\n timezone: string\n status: StaffLeaveRequestStatus\n unavailabilityReasonEntryId: string | null\n unavailabilityReasonValue: string | null\n note: string | null\n decisionComment: string | null\n submittedByUserId: string | null\n decidedByUserId: string | null\n decidedAt: string | null\n deletedAt: string | null\n createdAt: string | null\n updatedAt: string | null\n}\n\ntype LeaveRequestUndoPayload = {\n before?: LeaveRequestSnapshot | null\n after?: LeaveRequestSnapshot | null\n availabilityRuleIds?: string[]\n}\n\nfunction parseUuidCandidate(value: string | null | undefined): string | null {\n if (!value) return null\n const uuidRegex = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/\n return uuidRegex.test(value) ? value : null\n}\n\nfunction resolveAuthUserId(ctx: { auth?: { sub?: string | null; isApiKey?: boolean } | null }): string | null {\n if (!ctx.auth || ctx.auth.isApiKey) return null\n return parseUuidCandidate(ctx.auth.sub ?? null)\n}\n\nfunction formatDateKey(value: Date): string {\n const year = value.getUTCFullYear()\n const month = String(value.getUTCMonth() + 1).padStart(2, '0')\n const day = String(value.getUTCDate()).padStart(2, '0')\n return `${year}-${month}-${day}`\n}\n\nfunction listDateKeysInRange(start: Date, end: Date): string[] {\n const dates: string[] = []\n const current = new Date(Date.UTC(start.getUTCFullYear(), start.getUTCMonth(), start.getUTCDate()))\n const last = new Date(Date.UTC(end.getUTCFullYear(), end.getUTCMonth(), end.getUTCDate()))\n while (current <= last) {\n dates.push(formatDateKey(current))\n current.setUTCDate(current.getUTCDate() + 1)\n }\n return dates\n}\n\nfunction formatDuration(minutes: number): string {\n const clamped = Math.max(1, minutes)\n const hours = Math.floor(clamped / 60)\n const mins = clamped % 60\n if (hours > 0 && mins > 0) return `PT${hours}H${mins}M`\n if (hours > 0) return `PT${hours}H`\n return `PT${mins}M`\n}\n\nfunction buildAvailabilityRrule(start: Date, end: Date): string {\n const dtStart = start.toISOString().replace(/[-:]/g, '').split('.')[0] + 'Z'\n const durationMinutes = Math.max(1, Math.round((end.getTime() - start.getTime()) / 60000))\n const duration = formatDuration(durationMinutes)\n return `DTSTART:${dtStart}\\nDURATION:${duration}\\nRRULE:FREQ=DAILY;COUNT=1`\n}\n\nfunction buildFullDayRrule(date: string): string | null {\n const [year, month, day] = date.split('-').map((part) => Number(part))\n if (!Number.isFinite(year) || !Number.isFinite(month) || !Number.isFinite(day)) return null\n const start = new Date(Date.UTC(year, month - 1, day, 0, 0, 0))\n const end = new Date(start.getTime() + 24 * 60 * 60 * 1000)\n return buildAvailabilityRrule(start, end)\n}\n\nasync function loadLeaveRequestSnapshot(em: EntityManager, id: string): Promise<LeaveRequestSnapshot | null> {\n const request = await findOneWithDecryption(em, StaffLeaveRequest, { id }, undefined, { tenantId: null, organizationId: null })\n if (!request) return null\n const memberId = typeof request.member === 'string' ? request.member : request.member.id\n return {\n id: request.id,\n tenantId: request.tenantId,\n organizationId: request.organizationId,\n memberId,\n startDate: request.startDate.toISOString(),\n endDate: request.endDate.toISOString(),\n timezone: request.timezone,\n status: request.status,\n unavailabilityReasonEntryId: request.unavailabilityReasonEntryId ?? null,\n unavailabilityReasonValue: request.unavailabilityReasonValue ?? null,\n note: request.note ?? null,\n decisionComment: request.decisionComment ?? null,\n submittedByUserId: request.submittedByUserId ?? null,\n decidedByUserId: request.decidedByUserId ?? null,\n decidedAt: request.decidedAt ? request.decidedAt.toISOString() : null,\n deletedAt: request.deletedAt ? request.deletedAt.toISOString() : null,\n createdAt: request.createdAt ? request.createdAt.toISOString() : null,\n updatedAt: request.updatedAt ? request.updatedAt.toISOString() : null,\n }\n}\n\nasync function requireLeaveRequest(em: EntityManager, id: string): Promise<StaffLeaveRequest> {\n const request = await findOneWithDecryption(em, StaffLeaveRequest, { id, deletedAt: null }, undefined, { tenantId: null, organizationId: null })\n if (!request) throw new CrudHttpError(404, { error: 'Leave request not found.' })\n return request\n}\n\nfunction ensurePendingStatus(request: StaffLeaveRequest): void {\n if (request.status !== 'pending') {\n throw new CrudHttpError(400, { error: 'Leave request is already finalized.' })\n }\n}\n\nasync function createUnavailabilityRules(params: {\n em: EntityManager\n tenantId: string\n organizationId: string\n memberId: string\n timezone: string\n dates: string[]\n note: string | null\n reasonEntryId: string | null\n reasonValue: string | null\n}): Promise<string[]> {\n const now = new Date()\n const createdIds: string[] = []\n params.dates.forEach((date) => {\n const rrule = buildFullDayRrule(date)\n if (!rrule) return\n const ruleId = randomUUID()\n const rule = params.em.create(PlannerAvailabilityRule, {\n id: ruleId,\n tenantId: params.tenantId,\n organizationId: params.organizationId,\n subjectType: 'member',\n subjectId: params.memberId,\n timezone: params.timezone,\n rrule,\n exdates: [],\n kind: 'unavailability',\n note: params.note,\n unavailabilityReasonEntryId: params.reasonEntryId,\n unavailabilityReasonValue: params.reasonValue,\n createdAt: now,\n updatedAt: now,\n deletedAt: null,\n })\n params.em.persist(rule)\n createdIds.push(ruleId)\n })\n return createdIds\n}\n\nasync function invalidateAvailabilityCache(params: {\n container: CommandRuntimeContext['container']\n tenantId: string | null\n organizationId: string | null\n ruleIds: string[]\n}) {\n if (!params.ruleIds.length) return\n const resource = 'planner.availability'\n const fallbackTenant = params.tenantId ?? null\n for (const ruleId of params.ruleIds) {\n await invalidateCrudCache(\n params.container,\n resource,\n { id: ruleId, organizationId: params.organizationId, tenantId: params.tenantId },\n fallbackTenant,\n 'updated',\n )\n }\n}\n\nconst createLeaveRequestCommand: CommandHandler<StaffLeaveRequestCreateInput, { requestId: string }> = {\n id: 'staff.leave-requests.create',\n async execute(rawInput, ctx) {\n const parsed = staffLeaveRequestCreateSchema.parse(rawInput)\n ensureTenantScope(ctx, parsed.tenantId)\n ensureOrganizationScope(ctx, parsed.organizationId)\n\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const member = await requireTeamMember(em, parsed.memberId, 'Team member not found')\n ensureTenantScope(ctx, member.tenantId)\n ensureOrganizationScope(ctx, member.organizationId)\n\n const submittedByUserId = parsed.submittedByUserId ?? resolveAuthUserId(ctx)\n const now = new Date()\n const request = em.create(StaffLeaveRequest, {\n tenantId: parsed.tenantId,\n organizationId: parsed.organizationId,\n member,\n startDate: parsed.startDate,\n endDate: parsed.endDate,\n timezone: parsed.timezone,\n status: 'pending',\n unavailabilityReasonEntryId: parsed.unavailabilityReasonEntryId ?? null,\n unavailabilityReasonValue: parsed.unavailabilityReasonValue ?? null,\n note: parsed.note ?? null,\n decisionComment: null,\n submittedByUserId,\n decidedByUserId: null,\n decidedAt: null,\n createdAt: now,\n updatedAt: now,\n deletedAt: null,\n })\n em.persist(request)\n await em.flush()\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudSideEffects({\n dataEngine: de,\n action: 'created',\n entity: request,\n identifiers: {\n id: request.id,\n organizationId: request.organizationId,\n tenantId: request.tenantId,\n },\n indexer: leaveRequestCrudIndexer,\n })\n\n // Create notification for users who can approve/reject leave requests\n try {\n const notificationService = resolveNotificationService(ctx.container)\n const typeDef = notificationTypes.find((type) => type.type === 'staff.leave_request.pending')\n if (typeDef) {\n const memberName = member.displayName || 'Team member'\n const startDateStr = request.startDate.toLocaleDateString()\n const endDateStr = request.endDate.toLocaleDateString()\n\n const notificationInput = buildFeatureNotificationFromType(typeDef, {\n requiredFeature: 'staff.leave_requests.manage',\n bodyVariables: {\n memberName,\n startDate: startDateStr,\n endDate: endDateStr,\n },\n sourceEntityType: 'staff:leave_request',\n sourceEntityId: request.id,\n linkHref: `/backend/staff/leave-requests/${request.id}`,\n })\n\n await notificationService.createForFeature(notificationInput, {\n tenantId: request.tenantId,\n organizationId: request.organizationId,\n })\n }\n } catch {\n // Notification creation is non-critical, don't fail the command\n }\n\n return { requestId: request.id }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = (ctx.container.resolve('em') as EntityManager)\n return await loadLeaveRequestSnapshot(em, result.requestId)\n },\n buildLog: async ({ result, ctx }) => {\n const { translate } = await resolveTranslations()\n const em = (ctx.container.resolve('em') as EntityManager)\n const snapshot = await loadLeaveRequestSnapshot(em, result.requestId)\n return {\n actionLabel: translate('staff.audit.leaveRequests.create', 'Create leave request'),\n resourceKind: 'staff.leave_request',\n resourceId: result.requestId,\n tenantId: snapshot?.tenantId ?? null,\n organizationId: snapshot?.organizationId ?? null,\n snapshotAfter: snapshot ?? null,\n payload: {\n undo: {\n after: snapshot ?? null,\n } satisfies LeaveRequestUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<LeaveRequestUndoPayload>(logEntry)\n const after = payload?.after\n if (!after) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const request = await em.findOne(StaffLeaveRequest, { id: after.id })\n if (request) {\n request.deletedAt = new Date()\n request.updatedAt = new Date()\n await em.flush()\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudUndoSideEffects({\n dataEngine: de,\n action: 'deleted',\n entity: request,\n identifiers: {\n id: request.id,\n organizationId: request.organizationId,\n tenantId: request.tenantId,\n },\n indexer: leaveRequestCrudIndexer,\n })\n }\n },\n}\n\nconst updateLeaveRequestCommand: CommandHandler<StaffLeaveRequestUpdateInput, { requestId: string }> = {\n id: 'staff.leave-requests.update',\n async prepare(rawInput, ctx) {\n const parsed = staffLeaveRequestUpdateSchema.parse(rawInput)\n const em = (ctx.container.resolve('em') as EntityManager)\n const snapshot = await loadLeaveRequestSnapshot(em, parsed.id)\n return snapshot ? { before: snapshot } : {}\n },\n async execute(rawInput, ctx) {\n const parsed = staffLeaveRequestUpdateSchema.parse(rawInput)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const request = await requireLeaveRequest(em, parsed.id)\n ensureTenantScope(ctx, request.tenantId)\n ensureOrganizationScope(ctx, request.organizationId)\n ensurePendingStatus(request)\n\n if (parsed.memberId !== undefined) {\n const member = await requireTeamMember(em, parsed.memberId, 'Team member not found')\n ensureTenantScope(ctx, member.tenantId)\n ensureOrganizationScope(ctx, member.organizationId)\n request.member = member\n }\n if (parsed.startDate !== undefined) request.startDate = parsed.startDate\n if (parsed.endDate !== undefined) request.endDate = parsed.endDate\n if (parsed.timezone !== undefined) request.timezone = parsed.timezone\n if (parsed.unavailabilityReasonEntryId !== undefined) request.unavailabilityReasonEntryId = parsed.unavailabilityReasonEntryId ?? null\n if (parsed.unavailabilityReasonValue !== undefined) request.unavailabilityReasonValue = parsed.unavailabilityReasonValue ?? null\n if (parsed.note !== undefined) request.note = parsed.note ?? null\n request.updatedAt = new Date()\n await em.flush()\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudSideEffects({\n dataEngine: de,\n action: 'updated',\n entity: request,\n identifiers: {\n id: request.id,\n organizationId: request.organizationId,\n tenantId: request.tenantId,\n },\n indexer: leaveRequestCrudIndexer,\n })\n\n return { requestId: request.id }\n },\n buildLog: async ({ snapshots, ctx }) => {\n const { translate } = await resolveTranslations()\n const before = snapshots.before as LeaveRequestSnapshot | undefined\n if (!before) return null\n const em = (ctx.container.resolve('em') as EntityManager)\n const after = await loadLeaveRequestSnapshot(em, before.id)\n const changes = after\n ? buildChanges(before as unknown as Record<string, unknown>, after as unknown as Record<string, unknown>, [\n 'memberId',\n 'startDate',\n 'endDate',\n 'timezone',\n 'unavailabilityReasonEntryId',\n 'unavailabilityReasonValue',\n 'note',\n ])\n : {}\n return {\n actionLabel: translate('staff.audit.leaveRequests.update', 'Update leave request'),\n resourceKind: 'staff.leave_request',\n resourceId: before.id,\n tenantId: before.tenantId,\n organizationId: before.organizationId,\n snapshotBefore: before,\n snapshotAfter: after ?? null,\n changes,\n payload: {\n undo: {\n before,\n after: after ?? null,\n } satisfies LeaveRequestUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<LeaveRequestUndoPayload>(logEntry)\n const before = payload?.before\n const after = payload?.after\n if (!before || !after) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const request = await em.findOne(StaffLeaveRequest, { id: after.id })\n if (!request) return\n request.startDate = new Date(before.startDate)\n request.endDate = new Date(before.endDate)\n request.timezone = before.timezone\n request.status = before.status\n request.unavailabilityReasonEntryId = before.unavailabilityReasonEntryId\n request.unavailabilityReasonValue = before.unavailabilityReasonValue\n request.note = before.note\n request.decisionComment = before.decisionComment\n request.decidedByUserId = before.decidedByUserId\n request.decidedAt = before.decidedAt ? new Date(before.decidedAt) : null\n request.updatedAt = new Date()\n await em.flush()\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudUndoSideEffects({\n dataEngine: de,\n action: 'updated',\n entity: request,\n identifiers: {\n id: request.id,\n organizationId: request.organizationId,\n tenantId: request.tenantId,\n },\n indexer: leaveRequestCrudIndexer,\n })\n },\n}\n\nconst deleteLeaveRequestCommand: CommandHandler<{ id: string }, { requestId: string }> = {\n id: 'staff.leave-requests.delete',\n async execute(rawInput, ctx) {\n const parsed = staffLeaveRequestDecisionSchema.pick({ id: true }).parse(rawInput)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const request = await requireLeaveRequest(em, parsed.id)\n ensureTenantScope(ctx, request.tenantId)\n ensureOrganizationScope(ctx, request.organizationId)\n ensurePendingStatus(request)\n\n request.deletedAt = new Date()\n request.updatedAt = new Date()\n await em.flush()\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudSideEffects({\n dataEngine: de,\n action: 'deleted',\n entity: request,\n identifiers: {\n id: request.id,\n organizationId: request.organizationId,\n tenantId: request.tenantId,\n },\n indexer: leaveRequestCrudIndexer,\n })\n\n return { requestId: request.id }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = (ctx.container.resolve('em') as EntityManager)\n return await loadLeaveRequestSnapshot(em, result.requestId)\n },\n buildLog: async ({ result, ctx }) => {\n const { translate } = await resolveTranslations()\n const em = (ctx.container.resolve('em') as EntityManager)\n const snapshot = await loadLeaveRequestSnapshot(em, result.requestId)\n return {\n actionLabel: translate('staff.audit.leaveRequests.delete', 'Delete leave request'),\n resourceKind: 'staff.leave_request',\n resourceId: result.requestId,\n tenantId: snapshot?.tenantId ?? null,\n organizationId: snapshot?.organizationId ?? null,\n snapshotAfter: snapshot ?? null,\n payload: {\n undo: {\n after: snapshot ?? null,\n } satisfies LeaveRequestUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<LeaveRequestUndoPayload>(logEntry)\n const after = payload?.after\n if (!after) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const request = await em.findOne(StaffLeaveRequest, { id: after.id })\n if (!request) return\n request.deletedAt = null\n request.updatedAt = new Date()\n await em.flush()\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudUndoSideEffects({\n dataEngine: de,\n action: 'created',\n entity: request,\n identifiers: {\n id: request.id,\n organizationId: request.organizationId,\n tenantId: request.tenantId,\n },\n indexer: leaveRequestCrudIndexer,\n })\n },\n}\n\nconst acceptLeaveRequestCommand: CommandHandler<StaffLeaveRequestDecisionInput, { requestId: string; ruleIds: string[] }> = {\n id: 'staff.leave-requests.accept',\n async execute(rawInput, ctx) {\n const parsed = staffLeaveRequestDecisionSchema.parse(rawInput)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const request = await requireLeaveRequest(em, parsed.id)\n ensureTenantScope(ctx, request.tenantId)\n ensureOrganizationScope(ctx, request.organizationId)\n ensurePendingStatus(request)\n\n const memberId = typeof request.member === 'string' ? request.member : request.member.id\n const decidedByUserId = parsed.decidedByUserId ?? resolveAuthUserId(ctx)\n const now = new Date()\n const dates = listDateKeysInRange(request.startDate, request.endDate)\n let createdRuleIds: string[] = []\n\n await em.transactional(async (trx) => {\n request.status = 'approved'\n request.decisionComment = parsed.decisionComment ?? null\n request.decidedByUserId = decidedByUserId\n request.decidedAt = now\n request.updatedAt = now\n trx.persist(request)\n\n createdRuleIds = await createUnavailabilityRules({\n em: trx,\n tenantId: request.tenantId,\n organizationId: request.organizationId,\n memberId,\n timezone: request.timezone,\n dates,\n note: request.note ?? null,\n reasonEntryId: request.unavailabilityReasonEntryId ?? null,\n reasonValue: request.unavailabilityReasonValue ?? null,\n })\n await trx.flush()\n })\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudSideEffects({\n dataEngine: de,\n action: 'updated',\n entity: request,\n identifiers: {\n id: request.id,\n organizationId: request.organizationId,\n tenantId: request.tenantId,\n },\n indexer: leaveRequestCrudIndexer,\n })\n if (createdRuleIds.length) {\n const rules = await em.find(PlannerAvailabilityRule, { id: { $in: createdRuleIds } })\n for (const rule of rules) {\n await emitCrudSideEffects({\n dataEngine: de,\n action: 'created',\n entity: rule,\n identifiers: {\n id: rule.id,\n organizationId: rule.organizationId,\n tenantId: rule.tenantId,\n },\n indexer: availabilityRuleCrudIndexer,\n })\n }\n }\n await invalidateAvailabilityCache({\n container: ctx.container,\n tenantId: request.tenantId,\n organizationId: request.organizationId,\n ruleIds: createdRuleIds,\n })\n\n // Send notification to the requester\n if (request.submittedByUserId) {\n try {\n const notificationService = resolveNotificationService(ctx.container)\n const typeDef = notificationTypes.find((type) => type.type === 'staff.leave_request.approved')\n if (typeDef) {\n const startDateStr = request.startDate.toLocaleDateString()\n const endDateStr = request.endDate.toLocaleDateString()\n\n const notificationInput = buildNotificationFromType(typeDef, {\n recipientUserId: request.submittedByUserId,\n bodyVariables: {\n startDate: startDateStr,\n endDate: endDateStr,\n },\n sourceEntityType: 'staff:leave_request',\n sourceEntityId: request.id,\n linkHref: `/backend/staff/leave-requests/${request.id}`,\n })\n\n await notificationService.create(notificationInput, {\n tenantId: request.tenantId,\n organizationId: request.organizationId,\n })\n }\n } catch {\n // Notification creation is non-critical, don't fail the command\n }\n }\n\n return { requestId: request.id, ruleIds: createdRuleIds }\n },\n buildLog: async ({ result, ctx, snapshots }) => {\n const { translate } = await resolveTranslations()\n const before = snapshots.before as LeaveRequestSnapshot | undefined\n const em = (ctx.container.resolve('em') as EntityManager)\n const after = await loadLeaveRequestSnapshot(em, result.requestId)\n return {\n actionLabel: translate('staff.audit.leaveRequests.accept', 'Approve leave request'),\n resourceKind: 'staff.leave_request',\n resourceId: result.requestId,\n tenantId: after?.tenantId ?? before?.tenantId ?? null,\n organizationId: after?.organizationId ?? before?.organizationId ?? null,\n snapshotBefore: before ?? null,\n snapshotAfter: after ?? null,\n payload: {\n undo: {\n before: before ?? null,\n after: after ?? null,\n availabilityRuleIds: result.ruleIds,\n } satisfies LeaveRequestUndoPayload,\n },\n }\n },\n async prepare(rawInput, ctx) {\n const parsed = staffLeaveRequestDecisionSchema.parse(rawInput)\n const em = (ctx.container.resolve('em') as EntityManager)\n const snapshot = await loadLeaveRequestSnapshot(em, parsed.id)\n return snapshot ? { before: snapshot } : {}\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<LeaveRequestUndoPayload>(logEntry)\n const before = payload?.before\n const availabilityRuleIds = payload?.availabilityRuleIds ?? []\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const request = await em.findOne(StaffLeaveRequest, { id: before.id })\n if (!request) return\n request.status = before.status\n request.decisionComment = before.decisionComment\n request.decidedByUserId = before.decidedByUserId\n request.decidedAt = before.decidedAt ? new Date(before.decidedAt) : null\n request.updatedAt = new Date()\n await em.flush()\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudUndoSideEffects({\n dataEngine: de,\n action: 'updated',\n entity: request,\n identifiers: {\n id: request.id,\n organizationId: request.organizationId,\n tenantId: request.tenantId,\n },\n indexer: leaveRequestCrudIndexer,\n })\n\n if (availabilityRuleIds.length) {\n const rules = await em.find(PlannerAvailabilityRule, { id: { $in: availabilityRuleIds } })\n const now = new Date()\n rules.forEach((rule) => {\n rule.deletedAt = now\n rule.updatedAt = now\n })\n await em.flush()\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n for (const rule of rules) {\n await emitCrudUndoSideEffects({\n dataEngine: de,\n action: 'deleted',\n entity: rule,\n identifiers: {\n id: rule.id,\n organizationId: rule.organizationId,\n tenantId: rule.tenantId,\n },\n indexer: availabilityRuleCrudIndexer,\n })\n }\n }\n await invalidateAvailabilityCache({\n container: ctx.container,\n tenantId: before.tenantId,\n organizationId: before.organizationId,\n ruleIds: availabilityRuleIds,\n })\n },\n}\n\nconst rejectLeaveRequestCommand: CommandHandler<StaffLeaveRequestDecisionInput, { requestId: string }> = {\n id: 'staff.leave-requests.reject',\n async execute(rawInput, ctx) {\n const parsed = staffLeaveRequestDecisionSchema.parse(rawInput)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const request = await requireLeaveRequest(em, parsed.id)\n ensureTenantScope(ctx, request.tenantId)\n ensureOrganizationScope(ctx, request.organizationId)\n ensurePendingStatus(request)\n\n request.status = 'rejected'\n request.decisionComment = parsed.decisionComment ?? null\n request.decidedByUserId = parsed.decidedByUserId ?? resolveAuthUserId(ctx)\n request.decidedAt = new Date()\n request.updatedAt = new Date()\n await em.flush()\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudSideEffects({\n dataEngine: de,\n action: 'updated',\n entity: request,\n identifiers: {\n id: request.id,\n organizationId: request.organizationId,\n tenantId: request.tenantId,\n },\n indexer: leaveRequestCrudIndexer,\n })\n\n // Send notification to the requester\n if (request.submittedByUserId) {\n try {\n const notificationService = resolveNotificationService(ctx.container)\n const typeDef = notificationTypes.find((type) => type.type === 'staff.leave_request.rejected')\n if (typeDef) {\n const startDateStr = request.startDate.toLocaleDateString()\n const endDateStr = request.endDate.toLocaleDateString()\n\n const notificationInput = buildNotificationFromType(typeDef, {\n recipientUserId: request.submittedByUserId,\n bodyVariables: {\n startDate: startDateStr,\n endDate: endDateStr,\n reason: request.decisionComment ?? '',\n },\n sourceEntityType: 'staff:leave_request',\n sourceEntityId: request.id,\n linkHref: `/backend/staff/leave-requests/${request.id}`,\n })\n\n await notificationService.create(notificationInput, {\n tenantId: request.tenantId,\n organizationId: request.organizationId,\n })\n }\n } catch {\n // Notification creation is non-critical, don't fail the command\n }\n }\n\n return { requestId: request.id }\n },\n async prepare(rawInput, ctx) {\n const parsed = staffLeaveRequestDecisionSchema.parse(rawInput)\n const em = (ctx.container.resolve('em') as EntityManager)\n const snapshot = await loadLeaveRequestSnapshot(em, parsed.id)\n return snapshot ? { before: snapshot } : {}\n },\n buildLog: async ({ result, ctx, snapshots }) => {\n const { translate } = await resolveTranslations()\n const before = snapshots.before as LeaveRequestSnapshot | undefined\n const em = (ctx.container.resolve('em') as EntityManager)\n const after = await loadLeaveRequestSnapshot(em, result.requestId)\n return {\n actionLabel: translate('staff.audit.leaveRequests.reject', 'Reject leave request'),\n resourceKind: 'staff.leave_request',\n resourceId: result.requestId,\n tenantId: after?.tenantId ?? before?.tenantId ?? null,\n organizationId: after?.organizationId ?? before?.organizationId ?? null,\n snapshotBefore: before ?? null,\n snapshotAfter: after ?? null,\n payload: {\n undo: {\n before: before ?? null,\n after: after ?? null,\n } satisfies LeaveRequestUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<LeaveRequestUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const request = await em.findOne(StaffLeaveRequest, { id: before.id })\n if (!request) return\n request.status = before.status\n request.decisionComment = before.decisionComment\n request.decidedByUserId = before.decidedByUserId\n request.decidedAt = before.decidedAt ? new Date(before.decidedAt) : null\n request.updatedAt = new Date()\n await em.flush()\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudUndoSideEffects({\n dataEngine: de,\n action: 'updated',\n entity: request,\n identifiers: {\n id: request.id,\n organizationId: request.organizationId,\n tenantId: request.tenantId,\n },\n indexer: leaveRequestCrudIndexer,\n })\n },\n}\n\nregisterCommand(createLeaveRequestCommand)\nregisterCommand(updateLeaveRequestCommand)\nregisterCommand(deleteLeaveRequestCommand)\nregisterCommand(acceptLeaveRequestCommand)\nregisterCommand(rejectLeaveRequestCommand)\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,kBAAkB;AAE3B,SAAS,uBAAuB;AAEhC,SAAS,qBAAqB;AAC9B,SAAS,2BAA2B;AACpC,SAAS,qBAAqB,yBAAyB,oBAAoB;AAG3E,SAAS,2BAA2B;AACpC,SAAS,6BAA6B;AACtC,S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yB;",
|
|
6
6
|
"names": ["de"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
const notificationTypes = [
|
|
2
|
+
{
|
|
3
|
+
type: "staff.leave_request.pending",
|
|
4
|
+
module: "staff",
|
|
5
|
+
titleKey: "staff.notifications.leaveRequest.pending.title",
|
|
6
|
+
bodyKey: "staff.notifications.leaveRequest.pending.body",
|
|
7
|
+
icon: "calendar-off",
|
|
8
|
+
severity: "warning",
|
|
9
|
+
actions: [
|
|
10
|
+
{
|
|
11
|
+
id: "approve",
|
|
12
|
+
labelKey: "staff.notifications.leaveRequest.actions.approve",
|
|
13
|
+
variant: "default",
|
|
14
|
+
icon: "check",
|
|
15
|
+
commandId: "staff.leave-requests.accept"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
id: "reject",
|
|
19
|
+
labelKey: "staff.notifications.leaveRequest.actions.reject",
|
|
20
|
+
variant: "destructive",
|
|
21
|
+
icon: "x",
|
|
22
|
+
commandId: "staff.leave-requests.reject"
|
|
23
|
+
}
|
|
24
|
+
],
|
|
25
|
+
primaryActionId: "approve",
|
|
26
|
+
linkHref: "/backend/staff/leave-requests/{sourceEntityId}",
|
|
27
|
+
expiresAfterHours: 168
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
type: "staff.leave_request.approved",
|
|
31
|
+
module: "staff",
|
|
32
|
+
titleKey: "staff.notifications.leaveRequest.approved.title",
|
|
33
|
+
bodyKey: "staff.notifications.leaveRequest.approved.body",
|
|
34
|
+
icon: "calendar-check",
|
|
35
|
+
severity: "success",
|
|
36
|
+
actions: [
|
|
37
|
+
{
|
|
38
|
+
id: "view",
|
|
39
|
+
labelKey: "common.view",
|
|
40
|
+
variant: "outline",
|
|
41
|
+
href: "/backend/staff/leave-requests/{sourceEntityId}",
|
|
42
|
+
icon: "external-link"
|
|
43
|
+
}
|
|
44
|
+
],
|
|
45
|
+
linkHref: "/backend/staff/leave-requests/{sourceEntityId}",
|
|
46
|
+
expiresAfterHours: 168
|
|
47
|
+
// 7 days
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
type: "staff.leave_request.rejected",
|
|
51
|
+
module: "staff",
|
|
52
|
+
titleKey: "staff.notifications.leaveRequest.rejected.title",
|
|
53
|
+
bodyKey: "staff.notifications.leaveRequest.rejected.body",
|
|
54
|
+
icon: "calendar-x",
|
|
55
|
+
severity: "warning",
|
|
56
|
+
actions: [
|
|
57
|
+
{
|
|
58
|
+
id: "view",
|
|
59
|
+
labelKey: "common.view",
|
|
60
|
+
variant: "outline",
|
|
61
|
+
href: "/backend/staff/leave-requests/{sourceEntityId}",
|
|
62
|
+
icon: "external-link"
|
|
63
|
+
}
|
|
64
|
+
],
|
|
65
|
+
linkHref: "/backend/staff/leave-requests/{sourceEntityId}",
|
|
66
|
+
expiresAfterHours: 168
|
|
67
|
+
// 7 days
|
|
68
|
+
}
|
|
69
|
+
];
|
|
70
|
+
var notifications_default = notificationTypes;
|
|
71
|
+
export {
|
|
72
|
+
notifications_default as default,
|
|
73
|
+
notificationTypes
|
|
74
|
+
};
|
|
75
|
+
//# sourceMappingURL=notifications.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/modules/staff/notifications.ts"],
|
|
4
|
+
"sourcesContent": ["import type { NotificationTypeDefinition } from '@open-mercato/shared/modules/notifications/types'\n\nexport const notificationTypes: NotificationTypeDefinition[] = [\n {\n type: 'staff.leave_request.pending',\n module: 'staff',\n titleKey: 'staff.notifications.leaveRequest.pending.title',\n bodyKey: 'staff.notifications.leaveRequest.pending.body',\n icon: 'calendar-off',\n severity: 'warning',\n actions: [\n {\n id: 'approve',\n labelKey: 'staff.notifications.leaveRequest.actions.approve',\n variant: 'default',\n icon: 'check',\n commandId: 'staff.leave-requests.accept',\n },\n {\n id: 'reject',\n labelKey: 'staff.notifications.leaveRequest.actions.reject',\n variant: 'destructive',\n icon: 'x',\n commandId: 'staff.leave-requests.reject',\n },\n ],\n primaryActionId: 'approve',\n linkHref: '/backend/staff/leave-requests/{sourceEntityId}',\n expiresAfterHours: 168,\n },\n {\n type: 'staff.leave_request.approved',\n module: 'staff',\n titleKey: 'staff.notifications.leaveRequest.approved.title',\n bodyKey: 'staff.notifications.leaveRequest.approved.body',\n icon: 'calendar-check',\n severity: 'success',\n actions: [\n {\n id: 'view',\n labelKey: 'common.view',\n variant: 'outline',\n href: '/backend/staff/leave-requests/{sourceEntityId}',\n icon: 'external-link',\n },\n ],\n linkHref: '/backend/staff/leave-requests/{sourceEntityId}',\n expiresAfterHours: 168, // 7 days\n },\n {\n type: 'staff.leave_request.rejected',\n module: 'staff',\n titleKey: 'staff.notifications.leaveRequest.rejected.title',\n bodyKey: 'staff.notifications.leaveRequest.rejected.body',\n icon: 'calendar-x',\n severity: 'warning',\n actions: [\n {\n id: 'view',\n labelKey: 'common.view',\n variant: 'outline',\n href: '/backend/staff/leave-requests/{sourceEntityId}',\n icon: 'external-link',\n },\n ],\n linkHref: '/backend/staff/leave-requests/{sourceEntityId}',\n expiresAfterHours: 168, // 7 days\n },\n]\n\nexport default notificationTypes\n"],
|
|
5
|
+
"mappings": "AAEO,MAAM,oBAAkD;AAAA,EAC7D;AAAA,IACE,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,UAAU;AAAA,IACV,SAAS;AAAA,IACT,MAAM;AAAA,IACN,UAAU;AAAA,IACV,SAAS;AAAA,MACP;AAAA,QACE,IAAI;AAAA,QACJ,UAAU;AAAA,QACV,SAAS;AAAA,QACT,MAAM;AAAA,QACN,WAAW;AAAA,MACb;AAAA,MACA;AAAA,QACE,IAAI;AAAA,QACJ,UAAU;AAAA,QACV,SAAS;AAAA,QACT,MAAM;AAAA,QACN,WAAW;AAAA,MACb;AAAA,IACF;AAAA,IACA,iBAAiB;AAAA,IACjB,UAAU;AAAA,IACV,mBAAmB;AAAA,EACrB;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,UAAU;AAAA,IACV,SAAS;AAAA,IACT,MAAM;AAAA,IACN,UAAU;AAAA,IACV,SAAS;AAAA,MACP;AAAA,QACE,IAAI;AAAA,QACJ,UAAU;AAAA,QACV,SAAS;AAAA,QACT,MAAM;AAAA,QACN,MAAM;AAAA,MACR;AAAA,IACF;AAAA,IACA,UAAU;AAAA,IACV,mBAAmB;AAAA;AAAA,EACrB;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,UAAU;AAAA,IACV,SAAS;AAAA,IACT,MAAM;AAAA,IACN,UAAU;AAAA,IACV,SAAS;AAAA,MACP;AAAA,QACE,IAAI;AAAA,QACJ,UAAU;AAAA,QACV,SAAS;AAAA,QACT,MAAM;AAAA,QACN,MAAM;AAAA,MACR;AAAA,IACF;AAAA,IACA,UAAU;AAAA,IACV,mBAAmB;AAAA;AAAA,EACrB;AACF;AAEA,IAAO,wBAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const notificationTypes = [
|
|
2
|
+
{
|
|
3
|
+
type: "workflows.task.assigned",
|
|
4
|
+
module: "workflows",
|
|
5
|
+
titleKey: "workflows.notifications.task.assigned.title",
|
|
6
|
+
bodyKey: "workflows.notifications.task.assigned.body",
|
|
7
|
+
icon: "clipboard-list",
|
|
8
|
+
severity: "info",
|
|
9
|
+
actions: [
|
|
10
|
+
{
|
|
11
|
+
id: "view",
|
|
12
|
+
labelKey: "common.view",
|
|
13
|
+
variant: "outline",
|
|
14
|
+
href: "/backend/workflows/tasks/{sourceEntityId}",
|
|
15
|
+
icon: "external-link"
|
|
16
|
+
}
|
|
17
|
+
],
|
|
18
|
+
linkHref: "/backend/workflows/tasks/{sourceEntityId}",
|
|
19
|
+
expiresAfterHours: 168
|
|
20
|
+
// 7 days
|
|
21
|
+
}
|
|
22
|
+
];
|
|
23
|
+
var notifications_default = notificationTypes;
|
|
24
|
+
export {
|
|
25
|
+
notifications_default as default,
|
|
26
|
+
notificationTypes
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=notifications.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/modules/workflows/notifications.ts"],
|
|
4
|
+
"sourcesContent": ["import type { NotificationTypeDefinition } from '@open-mercato/shared/modules/notifications/types'\n\nexport const notificationTypes: NotificationTypeDefinition[] = [\n {\n type: 'workflows.task.assigned',\n module: 'workflows',\n titleKey: 'workflows.notifications.task.assigned.title',\n bodyKey: 'workflows.notifications.task.assigned.body',\n icon: 'clipboard-list',\n severity: 'info',\n actions: [\n {\n id: 'view',\n labelKey: 'common.view',\n variant: 'outline',\n href: '/backend/workflows/tasks/{sourceEntityId}',\n icon: 'external-link',\n },\n ],\n linkHref: '/backend/workflows/tasks/{sourceEntityId}',\n expiresAfterHours: 168, // 7 days\n },\n]\n\nexport default notificationTypes\n"],
|
|
5
|
+
"mappings": "AAEO,MAAM,oBAAkD;AAAA,EAC7D;AAAA,IACE,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,UAAU;AAAA,IACV,SAAS;AAAA,IACT,MAAM;AAAA,IACN,UAAU;AAAA,IACV,SAAS;AAAA,MACP;AAAA,QACE,IAAI;AAAA,QACJ,UAAU;AAAA,QACV,SAAS;AAAA,QACT,MAAM;AAAA,QACN,MAAM;AAAA,MACR;AAAA,IACF;AAAA,IACA,UAAU;AAAA,IACV,mBAAmB;AAAA;AAAA,EACrB;AACF;AAEA,IAAO,wBAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { resolveNotificationService } from "../../notifications/lib/notificationService.js";
|
|
2
|
+
import { buildNotificationFromType } from "../../notifications/lib/notificationBuilder.js";
|
|
3
|
+
import { notificationTypes } from "../notifications.js";
|
|
4
|
+
const metadata = {
|
|
5
|
+
event: "workflows.task.assigned",
|
|
6
|
+
persistent: true,
|
|
7
|
+
id: "workflows:task-assigned-notification"
|
|
8
|
+
};
|
|
9
|
+
async function handle(payload, ctx) {
|
|
10
|
+
if (!payload.assignedUserId) return;
|
|
11
|
+
try {
|
|
12
|
+
const notificationService = resolveNotificationService(ctx);
|
|
13
|
+
const typeDef = notificationTypes.find((type) => type.type === "workflows.task.assigned");
|
|
14
|
+
if (!typeDef) return;
|
|
15
|
+
const notificationInput = buildNotificationFromType(typeDef, {
|
|
16
|
+
recipientUserId: payload.assignedUserId,
|
|
17
|
+
bodyVariables: {
|
|
18
|
+
taskName: payload.taskName,
|
|
19
|
+
workflowName: payload.workflowName,
|
|
20
|
+
dueDate: payload.dueDate ?? ""
|
|
21
|
+
},
|
|
22
|
+
sourceEntityType: "workflows:user_task",
|
|
23
|
+
sourceEntityId: payload.taskId,
|
|
24
|
+
linkHref: `/backend/workflows/tasks/${payload.taskId}`
|
|
25
|
+
});
|
|
26
|
+
await notificationService.create(notificationInput, {
|
|
27
|
+
tenantId: payload.tenantId,
|
|
28
|
+
organizationId: payload.organizationId ?? null
|
|
29
|
+
});
|
|
30
|
+
} catch (err) {
|
|
31
|
+
console.error("[workflows:task-assigned-notification] Failed to create notification:", err);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export {
|
|
35
|
+
handle as default,
|
|
36
|
+
metadata
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=task-assigned-notification.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/modules/workflows/subscribers/task-assigned-notification.ts"],
|
|
4
|
+
"sourcesContent": ["import type { EntityManager } from '@mikro-orm/postgresql'\nimport { resolveNotificationService } from '../../notifications/lib/notificationService'\nimport { buildNotificationFromType } from '../../notifications/lib/notificationBuilder'\nimport { notificationTypes } from '../notifications'\n\nexport const metadata = {\n event: 'workflows.task.assigned',\n persistent: true,\n id: 'workflows:task-assigned-notification',\n}\n\ntype TaskAssignedPayload = {\n taskId: string\n taskName: string\n workflowName: string\n assignedUserId: string\n dueDate?: string | null\n tenantId: string\n organizationId?: string | null\n}\n\ntype ResolverContext = {\n resolve: <T = unknown>(name: string) => T\n}\n\nexport default async function handle(payload: TaskAssignedPayload, ctx: ResolverContext) {\n if (!payload.assignedUserId) return\n\n try {\n const notificationService = resolveNotificationService(ctx)\n const typeDef = notificationTypes.find((type) => type.type === 'workflows.task.assigned')\n if (!typeDef) return\n\n const notificationInput = buildNotificationFromType(typeDef, {\n recipientUserId: payload.assignedUserId,\n bodyVariables: {\n taskName: payload.taskName,\n workflowName: payload.workflowName,\n dueDate: payload.dueDate ?? '',\n },\n sourceEntityType: 'workflows:user_task',\n sourceEntityId: payload.taskId,\n linkHref: `/backend/workflows/tasks/${payload.taskId}`,\n })\n\n await notificationService.create(notificationInput, {\n tenantId: payload.tenantId,\n organizationId: payload.organizationId ?? null,\n })\n } catch (err) {\n console.error('[workflows:task-assigned-notification] Failed to create notification:', err)\n }\n}\n"],
|
|
5
|
+
"mappings": "AACA,SAAS,kCAAkC;AAC3C,SAAS,iCAAiC;AAC1C,SAAS,yBAAyB;AAE3B,MAAM,WAAW;AAAA,EACtB,OAAO;AAAA,EACP,YAAY;AAAA,EACZ,IAAI;AACN;AAgBA,eAAO,OAA8B,SAA8B,KAAsB;AACvF,MAAI,CAAC,QAAQ,eAAgB;AAE7B,MAAI;AACF,UAAM,sBAAsB,2BAA2B,GAAG;AAC1D,UAAM,UAAU,kBAAkB,KAAK,CAAC,SAAS,KAAK,SAAS,yBAAyB;AACxF,QAAI,CAAC,QAAS;AAEd,UAAM,oBAAoB,0BAA0B,SAAS;AAAA,MAC3D,iBAAiB,QAAQ;AAAA,MACzB,eAAe;AAAA,QACb,UAAU,QAAQ;AAAA,QAClB,cAAc,QAAQ;AAAA,QACtB,SAAS,QAAQ,WAAW;AAAA,MAC9B;AAAA,MACA,kBAAkB;AAAA,MAClB,gBAAgB,QAAQ;AAAA,MACxB,UAAU,4BAA4B,QAAQ,MAAM;AAAA,IACtD,CAAC;AAED,UAAM,oBAAoB,OAAO,mBAAmB;AAAA,MAClD,UAAU,QAAQ;AAAA,MAClB,gBAAgB,QAAQ,kBAAkB;AAAA,IAC5C,CAAC;AAAA,EACH,SAAS,KAAK;AACZ,YAAQ,MAAM,yEAAyE,GAAG;AAAA,EAC5F;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export const id = 'id'
|
|
2
|
+
export const recipient_user_id = 'recipient_user_id'
|
|
3
|
+
export const type = 'type'
|
|
4
|
+
export const title_key = 'title_key'
|
|
5
|
+
export const body_key = 'body_key'
|
|
6
|
+
export const title_variables = 'title_variables'
|
|
7
|
+
export const body_variables = 'body_variables'
|
|
8
|
+
export const title = 'title'
|
|
9
|
+
export const body = 'body'
|
|
10
|
+
export const icon = 'icon'
|
|
11
|
+
export const severity = 'severity'
|
|
12
|
+
export const status = 'status'
|
|
13
|
+
export const action_data = 'action_data'
|
|
14
|
+
export const action_result = 'action_result'
|
|
15
|
+
export const action_taken = 'action_taken'
|
|
16
|
+
export const source_module = 'source_module'
|
|
17
|
+
export const source_entity_type = 'source_entity_type'
|
|
18
|
+
export const source_entity_id = 'source_entity_id'
|
|
19
|
+
export const link_href = 'link_href'
|
|
20
|
+
export const group_key = 'group_key'
|
|
21
|
+
export const created_at = 'created_at'
|
|
22
|
+
export const read_at = 'read_at'
|
|
23
|
+
export const actioned_at = 'actioned_at'
|
|
24
|
+
export const dismissed_at = 'dismissed_at'
|
|
25
|
+
export const expires_at = 'expires_at'
|
|
26
|
+
export const tenant_id = 'tenant_id'
|
|
27
|
+
export const organization_id = 'organization_id'
|
|
@@ -21,7 +21,8 @@ export const M = {
|
|
|
21
21
|
"currencies": "currencies",
|
|
22
22
|
"planner": "planner",
|
|
23
23
|
"resources": "resources",
|
|
24
|
-
"staff": "staff"
|
|
24
|
+
"staff": "staff",
|
|
25
|
+
"notifications": "notifications"
|
|
25
26
|
} as const
|
|
26
27
|
export const E = {
|
|
27
28
|
"dashboards": {
|
|
@@ -182,6 +183,9 @@ export const E = {
|
|
|
182
183
|
"staff_team_member_comment": "staff:staff_team_member_comment",
|
|
183
184
|
"staff_team_member_job_history": "staff:staff_team_member_job_history",
|
|
184
185
|
"staff_team_role": "staff:staff_team_role"
|
|
186
|
+
},
|
|
187
|
+
"notifications": {
|
|
188
|
+
"notification": "notifications:notification"
|
|
185
189
|
}
|
|
186
190
|
} as const
|
|
187
191
|
export type KnownModuleId = keyof typeof M
|
|
@@ -53,6 +53,7 @@ import * as feature_toggle_override from './entities/feature_toggle_override/ind
|
|
|
53
53
|
import * as indexer_error_log from './entities/indexer_error_log/index'
|
|
54
54
|
import * as indexer_status_log from './entities/indexer_status_log/index'
|
|
55
55
|
import * as module_config from './entities/module_config/index'
|
|
56
|
+
import * as notification from './entities/notification/index'
|
|
56
57
|
import * as organization from './entities/organization/index'
|
|
57
58
|
import * as password_reset from './entities/password_reset/index'
|
|
58
59
|
import * as perspective from './entities/perspective/index'
|
|
@@ -172,6 +173,7 @@ export const entityFieldsRegistry: Record<string, Record<string, string>> = {
|
|
|
172
173
|
indexer_error_log,
|
|
173
174
|
indexer_status_log,
|
|
174
175
|
module_config,
|
|
176
|
+
notification,
|
|
175
177
|
organization,
|
|
176
178
|
password_reset,
|
|
177
179
|
perspective,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-mercato/core",
|
|
3
|
-
"version": "0.4.2-canary-
|
|
3
|
+
"version": "0.4.2-canary-70c8402224",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -207,7 +207,7 @@
|
|
|
207
207
|
}
|
|
208
208
|
},
|
|
209
209
|
"dependencies": {
|
|
210
|
-
"@open-mercato/shared": "0.4.2-canary-
|
|
210
|
+
"@open-mercato/shared": "0.4.2-canary-70c8402224",
|
|
211
211
|
"@xyflow/react": "^12.6.0",
|
|
212
212
|
"date-fns": "^4.1.0",
|
|
213
213
|
"date-fns-tz": "^3.2.0"
|
|
@@ -2,6 +2,7 @@ import ApiDocsExplorer from './Explorer'
|
|
|
2
2
|
import { getModules } from '@open-mercato/shared/lib/i18n/server'
|
|
3
3
|
import { buildOpenApiDocument } from '@open-mercato/shared/lib/openapi'
|
|
4
4
|
import { resolveApiDocsBaseUrl } from '@open-mercato/core/modules/api_docs/lib/resources'
|
|
5
|
+
import { APP_VERSION } from '@open-mercato/shared/lib/version'
|
|
5
6
|
|
|
6
7
|
type ExplorerOperation = {
|
|
7
8
|
id: string
|
|
@@ -54,7 +55,7 @@ export default async function ApiDocsViewerPage() {
|
|
|
54
55
|
const modules = getModules()
|
|
55
56
|
const doc = buildOpenApiDocument(modules, {
|
|
56
57
|
title: 'Open Mercato API',
|
|
57
|
-
version:
|
|
58
|
+
version: APP_VERSION,
|
|
58
59
|
description: 'Auto-generated OpenAPI definition for all enabled modules.',
|
|
59
60
|
servers: [{ url: baseUrl, description: 'Default environment' }],
|
|
60
61
|
baseUrlForExamples: baseUrl,
|
|
@@ -67,7 +68,7 @@ export default async function ApiDocsViewerPage() {
|
|
|
67
68
|
return (
|
|
68
69
|
<ApiDocsExplorer
|
|
69
70
|
title={doc.info?.title ?? 'Open Mercato API'}
|
|
70
|
-
version={doc.info?.version ??
|
|
71
|
+
version={doc.info?.version ?? APP_VERSION}
|
|
71
72
|
description={doc.info?.description}
|
|
72
73
|
operations={operations}
|
|
73
74
|
tagOrder={tagOrder}
|
|
@@ -297,12 +297,16 @@ export async function GET(req: Request) {
|
|
|
297
297
|
const groupsWithRole = rolePreference ? applySidebarPreference(groups, rolePreference) : groups
|
|
298
298
|
const baseForUser = adoptSidebarDefaults(groupsWithRole)
|
|
299
299
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
300
|
+
// For API key auth, use userId (the actual user) if available; otherwise skip user preferences
|
|
301
|
+
const effectiveUserId = auth.isApiKey ? auth.userId : auth.sub
|
|
302
|
+
const preference = effectiveUserId
|
|
303
|
+
? await loadSidebarPreference(em, {
|
|
304
|
+
userId: effectiveUserId,
|
|
305
|
+
tenantId: auth.tenantId ?? null,
|
|
306
|
+
organizationId: auth.orgId ?? null,
|
|
307
|
+
locale,
|
|
308
|
+
})
|
|
309
|
+
: null
|
|
306
310
|
|
|
307
311
|
const withPreference = applySidebarPreference(baseForUser, preference)
|
|
308
312
|
|