@open-mercato/core 0.6.4-develop.4210.1.d412061cfe → 0.6.4-develop.4236.1.9fa6806b34
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/.turbo/turbo-build.log +2 -2
- package/dist/generated/entities/staff_time_entry/index.js +37 -0
- package/dist/generated/entities/staff_time_entry/index.js.map +7 -0
- package/dist/generated/entities/staff_time_entry_segment/index.js +23 -0
- package/dist/generated/entities/staff_time_entry_segment/index.js.map +7 -0
- package/dist/generated/entities/staff_time_project/index.js +35 -0
- package/dist/generated/entities/staff_time_project/index.js.map +7 -0
- package/dist/generated/entities/staff_time_project_member/index.js +29 -0
- package/dist/generated/entities/staff_time_project_member/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 +64 -0
- package/dist/generated/entity-fields-registry.js.map +2 -2
- package/dist/helpers/integration/timesheetFixtures.js +50 -0
- package/dist/helpers/integration/timesheetFixtures.js.map +7 -0
- package/dist/modules/attachments/api/library/[id]/route.js +20 -16
- package/dist/modules/attachments/api/library/[id]/route.js.map +2 -2
- package/dist/modules/attachments/api/route.js +18 -14
- package/dist/modules/attachments/api/route.js.map +2 -2
- package/dist/modules/auth/api/roles/acl/route.js +10 -4
- package/dist/modules/auth/api/roles/acl/route.js.map +2 -2
- package/dist/modules/auth/api/sidebar/preferences/route.js +27 -20
- package/dist/modules/auth/api/sidebar/preferences/route.js.map +2 -2
- package/dist/modules/auth/api/users/acl/route.js +16 -11
- package/dist/modules/auth/api/users/acl/route.js.map +2 -2
- package/dist/modules/auth/commands/users.js +87 -71
- package/dist/modules/auth/commands/users.js.map +2 -2
- package/dist/modules/auth/services/sidebarPreferencesService.js +39 -30
- package/dist/modules/auth/services/sidebarPreferencesService.js.map +2 -2
- package/dist/modules/catalog/commands/categories.js +61 -12
- package/dist/modules/catalog/commands/categories.js.map +2 -2
- package/dist/modules/catalog/commands/products.js +79 -54
- package/dist/modules/catalog/commands/products.js.map +2 -2
- package/dist/modules/catalog/commands/variants.js +29 -16
- package/dist/modules/catalog/commands/variants.js.map +2 -2
- package/dist/modules/currencies/commands/currencies.js +15 -8
- package/dist/modules/currencies/commands/currencies.js.map +2 -2
- package/dist/modules/customer_accounts/api/admin/users.js +27 -26
- package/dist/modules/customer_accounts/api/admin/users.js.map +2 -2
- package/dist/modules/customer_accounts/api/password/reset-confirm.js +5 -5
- package/dist/modules/customer_accounts/api/password/reset-confirm.js.map +2 -2
- package/dist/modules/customer_accounts/api/portal/users/[id]/roles.js +11 -10
- package/dist/modules/customer_accounts/api/portal/users/[id]/roles.js.map +2 -2
- package/dist/modules/customers/commands/addresses.js +35 -21
- package/dist/modules/customers/commands/addresses.js.map +2 -2
- package/dist/modules/customers/commands/companies.js +163 -162
- package/dist/modules/customers/commands/companies.js.map +2 -2
- package/dist/modules/customers/commands/deals.js +3 -4
- package/dist/modules/customers/commands/deals.js.map +2 -2
- package/dist/modules/customers/commands/interactions.js +19 -22
- package/dist/modules/customers/commands/interactions.js.map +2 -2
- package/dist/modules/customers/commands/people.js +18 -15
- package/dist/modules/customers/commands/people.js.map +2 -2
- package/dist/modules/customers/commands/personCompanyLinks.js +105 -94
- package/dist/modules/customers/commands/personCompanyLinks.js.map +2 -2
- package/dist/modules/customers/commands/pipeline-stages.js +30 -23
- package/dist/modules/customers/commands/pipeline-stages.js.map +2 -2
- package/dist/modules/customers/commands/pipelines.js +27 -20
- package/dist/modules/customers/commands/pipelines.js.map +2 -2
- package/dist/modules/customers/commands/tags.js +13 -5
- package/dist/modules/customers/commands/tags.js.map +2 -2
- package/dist/modules/dashboards/api/users/widgets/route.js +0 -1
- package/dist/modules/dashboards/api/users/widgets/route.js.map +2 -2
- package/dist/modules/dashboards/api/widgets/data/route.js +29 -1
- package/dist/modules/dashboards/api/widgets/data/route.js.map +2 -2
- package/dist/modules/data_sync/lib/sync-engine.js +4 -4
- package/dist/modules/data_sync/lib/sync-engine.js.map +2 -2
- package/dist/modules/data_sync/lib/sync-run-service.js +51 -27
- package/dist/modules/data_sync/lib/sync-run-service.js.map +2 -2
- package/dist/modules/directory/commands/organizations.js +192 -158
- package/dist/modules/directory/commands/organizations.js.map +3 -3
- package/dist/modules/inbox_ops/api/emails/[id]/reprocess/route.js +22 -16
- package/dist/modules/inbox_ops/api/emails/[id]/reprocess/route.js.map +2 -2
- package/dist/modules/messages/commands/messages.js +77 -75
- package/dist/modules/messages/commands/messages.js.map +2 -2
- package/dist/modules/messages/commands/shared.js +132 -132
- package/dist/modules/messages/commands/shared.js.map +2 -2
- package/dist/modules/perspectives/api/[tableId]/route.js +37 -26
- package/dist/modules/perspectives/api/[tableId]/route.js.map +2 -2
- package/dist/modules/resources/commands/resources.js +125 -117
- package/dist/modules/resources/commands/resources.js.map +2 -2
- package/dist/modules/resources/commands/tags.js +7 -3
- package/dist/modules/resources/commands/tags.js.map +2 -2
- package/dist/modules/sales/api/quotes/send/route.js +12 -11
- package/dist/modules/sales/api/quotes/send/route.js.map +2 -2
- package/dist/modules/sales/commands/documents.js +629 -478
- package/dist/modules/sales/commands/documents.js.map +2 -2
- package/dist/modules/sales/commands/payments.js +146 -146
- package/dist/modules/sales/commands/payments.js.map +2 -2
- package/dist/modules/sales/commands/returns.js +68 -60
- package/dist/modules/sales/commands/returns.js.map +2 -2
- package/dist/modules/staff/acl.js +10 -1
- package/dist/modules/staff/acl.js.map +2 -2
- package/dist/modules/staff/analytics.js +33 -0
- package/dist/modules/staff/analytics.js.map +7 -0
- package/dist/modules/staff/api/guards.js +31 -0
- package/dist/modules/staff/api/guards.js.map +7 -0
- package/dist/modules/staff/api/interceptors.js +96 -0
- package/dist/modules/staff/api/interceptors.js.map +7 -0
- package/dist/modules/staff/api/timesheets/my-projects/[projectId]/route.js +170 -0
- package/dist/modules/staff/api/timesheets/my-projects/[projectId]/route.js.map +7 -0
- package/dist/modules/staff/api/timesheets/my-projects/route.js +103 -0
- package/dist/modules/staff/api/timesheets/my-projects/route.js.map +7 -0
- package/dist/modules/staff/api/timesheets/projects/kpis/route.js +147 -0
- package/dist/modules/staff/api/timesheets/projects/kpis/route.js.map +7 -0
- package/dist/modules/staff/api/timesheets/time-entries/[id]/segments/[segmentId]/route.js +171 -0
- package/dist/modules/staff/api/timesheets/time-entries/[id]/segments/[segmentId]/route.js.map +7 -0
- package/dist/modules/staff/api/timesheets/time-entries/[id]/segments/route.js +180 -0
- package/dist/modules/staff/api/timesheets/time-entries/[id]/segments/route.js.map +7 -0
- package/dist/modules/staff/api/timesheets/time-entries/[id]/timer-start/route.js +155 -0
- package/dist/modules/staff/api/timesheets/time-entries/[id]/timer-start/route.js.map +7 -0
- package/dist/modules/staff/api/timesheets/time-entries/[id]/timer-stop/route.js +173 -0
- package/dist/modules/staff/api/timesheets/time-entries/[id]/timer-stop/route.js.map +7 -0
- package/dist/modules/staff/api/timesheets/time-entries/bulk/route.js +260 -0
- package/dist/modules/staff/api/timesheets/time-entries/bulk/route.js.map +7 -0
- package/dist/modules/staff/api/timesheets/time-entries/route.js +188 -0
- package/dist/modules/staff/api/timesheets/time-entries/route.js.map +7 -0
- package/dist/modules/staff/api/timesheets/time-projects/[id]/employees/route.js +159 -0
- package/dist/modules/staff/api/timesheets/time-projects/[id]/employees/route.js.map +7 -0
- package/dist/modules/staff/api/timesheets/time-projects/route.js +230 -0
- package/dist/modules/staff/api/timesheets/time-projects/route.js.map +7 -0
- package/dist/modules/staff/backend/staff/timesheets/page.js +710 -0
- package/dist/modules/staff/backend/staff/timesheets/page.js.map +7 -0
- package/dist/modules/staff/backend/staff/timesheets/page.meta.js +22 -0
- package/dist/modules/staff/backend/staff/timesheets/page.meta.js.map +7 -0
- package/dist/modules/staff/backend/staff/timesheets/projects/[id]/edit/page.js +125 -0
- package/dist/modules/staff/backend/staff/timesheets/projects/[id]/edit/page.js.map +7 -0
- package/dist/modules/staff/backend/staff/timesheets/projects/[id]/edit/page.meta.js +16 -0
- package/dist/modules/staff/backend/staff/timesheets/projects/[id]/edit/page.meta.js.map +7 -0
- package/dist/modules/staff/backend/staff/timesheets/projects/[id]/page.js +418 -0
- package/dist/modules/staff/backend/staff/timesheets/projects/[id]/page.js.map +7 -0
- package/dist/modules/staff/backend/staff/timesheets/projects/[id]/page.meta.js +16 -0
- package/dist/modules/staff/backend/staff/timesheets/projects/[id]/page.meta.js.map +7 -0
- package/dist/modules/staff/backend/staff/timesheets/projects/create/page.js +79 -0
- package/dist/modules/staff/backend/staff/timesheets/projects/create/page.js.map +7 -0
- package/dist/modules/staff/backend/staff/timesheets/projects/create/page.meta.js +16 -0
- package/dist/modules/staff/backend/staff/timesheets/projects/create/page.meta.js.map +7 -0
- package/dist/modules/staff/backend/staff/timesheets/projects/page.js +602 -0
- package/dist/modules/staff/backend/staff/timesheets/projects/page.js.map +7 -0
- package/dist/modules/staff/backend/staff/timesheets/projects/page.meta.js +25 -0
- package/dist/modules/staff/backend/staff/timesheets/projects/page.meta.js.map +7 -0
- package/dist/modules/staff/backend/staff/timesheets/projects/projectFormConfig.js +123 -0
- package/dist/modules/staff/backend/staff/timesheets/projects/projectFormConfig.js.map +7 -0
- package/dist/modules/staff/cli.js +38 -1
- package/dist/modules/staff/cli.js.map +2 -2
- package/dist/modules/staff/commands/index.js +2 -0
- package/dist/modules/staff/commands/index.js.map +2 -2
- package/dist/modules/staff/commands/leave-requests.js +30 -28
- package/dist/modules/staff/commands/leave-requests.js.map +3 -3
- package/dist/modules/staff/commands/team-members.js +21 -20
- package/dist/modules/staff/commands/team-members.js.map +2 -2
- package/dist/modules/staff/commands/timesheets-entries.js +409 -0
- package/dist/modules/staff/commands/timesheets-entries.js.map +7 -0
- package/dist/modules/staff/commands/timesheets-projects.js +618 -0
- package/dist/modules/staff/commands/timesheets-projects.js.map +7 -0
- package/dist/modules/staff/data/enrichers.js +104 -0
- package/dist/modules/staff/data/enrichers.js.map +7 -0
- package/dist/modules/staff/data/entities.js +226 -1
- package/dist/modules/staff/data/entities.js.map +2 -2
- package/dist/modules/staff/data/validators.js +113 -1
- package/dist/modules/staff/data/validators.js.map +2 -2
- package/dist/modules/staff/events.js +13 -1
- package/dist/modules/staff/events.js.map +2 -2
- package/dist/modules/staff/lib/crud.js +7 -1
- package/dist/modules/staff/lib/crud.js.map +2 -2
- package/dist/modules/staff/lib/staffMemberResolver.js +15 -0
- package/dist/modules/staff/lib/staffMemberResolver.js.map +7 -0
- package/dist/modules/staff/lib/timesheets-projects/computeProjectHoursTrend.js +60 -0
- package/dist/modules/staff/lib/timesheets-projects/computeProjectHoursTrend.js.map +7 -0
- package/dist/modules/staff/lib/timesheets-projects/computeProjectsKpis.js +260 -0
- package/dist/modules/staff/lib/timesheets-projects/computeProjectsKpis.js.map +7 -0
- package/dist/modules/staff/lib/timesheets-projects/dateBuckets.js +41 -0
- package/dist/modules/staff/lib/timesheets-projects/dateBuckets.js.map +7 -0
- package/dist/modules/staff/lib/timesheets-projects/initials.js +10 -0
- package/dist/modules/staff/lib/timesheets-projects/initials.js.map +7 -0
- package/dist/modules/staff/lib/timesheets-projects/kpiMath.js +12 -0
- package/dist/modules/staff/lib/timesheets-projects/kpiMath.js.map +7 -0
- package/dist/modules/staff/lib/timesheets-projects/listProjectMembersPreview.js +55 -0
- package/dist/modules/staff/lib/timesheets-projects/listProjectMembersPreview.js.map +7 -0
- package/dist/modules/staff/lib/timesheets-projects-ui/HoursSparkline.js +66 -0
- package/dist/modules/staff/lib/timesheets-projects-ui/HoursSparkline.js.map +7 -0
- package/dist/modules/staff/lib/timesheets-projects-ui/ProjectCard.js +81 -0
- package/dist/modules/staff/lib/timesheets-projects-ui/ProjectCard.js.map +7 -0
- package/dist/modules/staff/lib/timesheets-projects-ui/ProjectMembersAvatarStack.js +58 -0
- package/dist/modules/staff/lib/timesheets-projects-ui/ProjectMembersAvatarStack.js.map +7 -0
- package/dist/modules/staff/lib/timesheets-projects-ui/ProjectsKpiStrip.js +152 -0
- package/dist/modules/staff/lib/timesheets-projects-ui/ProjectsKpiStrip.js.map +7 -0
- package/dist/modules/staff/lib/timesheets-projects-ui/SavedViewTabs.js +37 -0
- package/dist/modules/staff/lib/timesheets-projects-ui/SavedViewTabs.js.map +7 -0
- package/dist/modules/staff/lib/timesheets-projects-ui/ViewModeToggle.js +57 -0
- package/dist/modules/staff/lib/timesheets-projects-ui/ViewModeToggle.js.map +7 -0
- package/dist/modules/staff/lib/timesheets-projects-ui/useProjectsViewMode.js +50 -0
- package/dist/modules/staff/lib/timesheets-projects-ui/useProjectsViewMode.js.map +7 -0
- package/dist/modules/staff/lib/timesheets-ui/AddRowDropdown.js +163 -0
- package/dist/modules/staff/lib/timesheets-ui/AddRowDropdown.js.map +7 -0
- package/dist/modules/staff/lib/timesheets-ui/CalendarPicker.js +209 -0
- package/dist/modules/staff/lib/timesheets-ui/CalendarPicker.js.map +7 -0
- package/dist/modules/staff/lib/timesheets-ui/ColorPicker.js +52 -0
- package/dist/modules/staff/lib/timesheets-ui/ColorPicker.js.map +7 -0
- package/dist/modules/staff/lib/timesheets-ui/CreateProjectDialog.js +77 -0
- package/dist/modules/staff/lib/timesheets-ui/CreateProjectDialog.js.map +7 -0
- package/dist/modules/staff/lib/timesheets-ui/ListView.js +173 -0
- package/dist/modules/staff/lib/timesheets-ui/ListView.js.map +7 -0
- package/dist/modules/staff/lib/timesheets-ui/ProjectColorDot.js +32 -0
- package/dist/modules/staff/lib/timesheets-ui/ProjectColorDot.js.map +7 -0
- package/dist/modules/staff/lib/timesheets-ui/TimerBar.js +270 -0
- package/dist/modules/staff/lib/timesheets-ui/TimerBar.js.map +7 -0
- package/dist/modules/staff/lib/timesheets-ui/ViewSwitcher.js +57 -0
- package/dist/modules/staff/lib/timesheets-ui/ViewSwitcher.js.map +7 -0
- package/dist/modules/staff/lib/timesheets-ui/colors.js +43 -0
- package/dist/modules/staff/lib/timesheets-ui/colors.js.map +7 -0
- package/dist/modules/staff/migrations/Migration20260326135612.js +24 -0
- package/dist/modules/staff/migrations/Migration20260326135612.js.map +7 -0
- package/dist/modules/staff/migrations/Migration20260413102715.js +23 -0
- package/dist/modules/staff/migrations/Migration20260413102715.js.map +7 -0
- package/dist/modules/staff/migrations/Migration20260413111602.js +13 -0
- package/dist/modules/staff/migrations/Migration20260413111602.js.map +7 -0
- package/dist/modules/staff/migrations/Migration20260511112759.js +19 -0
- package/dist/modules/staff/migrations/Migration20260511112759.js.map +7 -0
- package/dist/modules/staff/search.js +35 -0
- package/dist/modules/staff/search.js.map +2 -2
- package/dist/modules/staff/setup.js +15 -1
- package/dist/modules/staff/setup.js.map +2 -2
- package/dist/modules/staff/widgets/dashboard/timesheets-hours-by-project/config.js +16 -0
- package/dist/modules/staff/widgets/dashboard/timesheets-hours-by-project/config.js.map +7 -0
- package/dist/modules/staff/widgets/dashboard/timesheets-hours-by-project/widget.client.js +126 -0
- package/dist/modules/staff/widgets/dashboard/timesheets-hours-by-project/widget.client.js.map +7 -0
- package/dist/modules/staff/widgets/dashboard/timesheets-hours-by-project/widget.js +26 -0
- package/dist/modules/staff/widgets/dashboard/timesheets-hours-by-project/widget.js.map +7 -0
- package/dist/modules/staff/widgets/dashboard/timesheets-time-reporting/config.js +15 -0
- package/dist/modules/staff/widgets/dashboard/timesheets-time-reporting/config.js.map +7 -0
- package/dist/modules/staff/widgets/dashboard/timesheets-time-reporting/widget.client.js +238 -0
- package/dist/modules/staff/widgets/dashboard/timesheets-time-reporting/widget.client.js.map +7 -0
- package/dist/modules/staff/widgets/dashboard/timesheets-time-reporting/widget.js +26 -0
- package/dist/modules/staff/widgets/dashboard/timesheets-time-reporting/widget.js.map +7 -0
- package/dist/modules/staff/widgets/injection/timer-sidebar-indicator/widget.js +145 -0
- package/dist/modules/staff/widgets/injection/timer-sidebar-indicator/widget.js.map +7 -0
- package/dist/modules/staff/widgets/injection-table.js +12 -0
- package/dist/modules/staff/widgets/injection-table.js.map +7 -0
- package/dist/modules/sync_excel/api/import/route.js +19 -17
- package/dist/modules/sync_excel/api/import/route.js.map +2 -2
- package/dist/modules/translations/commands/translations.js +22 -19
- package/dist/modules/translations/commands/translations.js.map +2 -2
- package/generated/entities/staff_time_entry/index.ts +17 -0
- package/generated/entities/staff_time_entry_segment/index.ts +10 -0
- package/generated/entities/staff_time_project/index.ts +16 -0
- package/generated/entities/staff_time_project_member/index.ts +13 -0
- package/generated/entities.ids.generated.ts +5 -1
- package/generated/entity-fields-registry.ts +64 -0
- package/package.json +7 -7
- package/src/helpers/integration/timesheetFixtures.ts +61 -0
- package/src/modules/attachments/api/library/[id]/route.ts +24 -17
- package/src/modules/attachments/api/route.ts +20 -14
- package/src/modules/auth/api/roles/acl/route.ts +11 -5
- package/src/modules/auth/api/sidebar/preferences/route.ts +33 -24
- package/src/modules/auth/api/users/acl/route.ts +17 -12
- package/src/modules/auth/commands/users.ts +96 -80
- package/src/modules/auth/services/sidebarPreferencesService.ts +40 -32
- package/src/modules/catalog/commands/categories.ts +61 -12
- package/src/modules/catalog/commands/products.ts +93 -60
- package/src/modules/catalog/commands/variants.ts +29 -16
- package/src/modules/currencies/commands/currencies.ts +27 -14
- package/src/modules/customer_accounts/api/admin/users.ts +31 -26
- package/src/modules/customer_accounts/api/password/reset-confirm.ts +5 -6
- package/src/modules/customer_accounts/api/portal/users/[id]/roles.ts +14 -13
- package/src/modules/customers/commands/addresses.ts +35 -23
- package/src/modules/customers/commands/companies.ts +166 -165
- package/src/modules/customers/commands/deals.ts +2 -4
- package/src/modules/customers/commands/interactions.ts +20 -26
- package/src/modules/customers/commands/people.ts +18 -15
- package/src/modules/customers/commands/personCompanyLinks.ts +109 -100
- package/src/modules/customers/commands/pipeline-stages.ts +31 -27
- package/src/modules/customers/commands/pipelines.ts +29 -23
- package/src/modules/customers/commands/tags.ts +13 -5
- package/src/modules/dashboards/api/users/widgets/route.ts +0 -1
- package/src/modules/dashboards/api/widgets/data/route.ts +36 -1
- package/src/modules/data_sync/lib/sync-engine.ts +4 -5
- package/src/modules/data_sync/lib/sync-run-service.ts +57 -28
- package/src/modules/directory/commands/organizations.ts +203 -166
- package/src/modules/inbox_ops/api/emails/[id]/reprocess/route.ts +26 -18
- package/src/modules/messages/commands/messages.ts +82 -80
- package/src/modules/messages/commands/shared.ts +138 -133
- package/src/modules/perspectives/api/[tableId]/route.ts +38 -27
- package/src/modules/resources/commands/resources.ts +127 -117
- package/src/modules/resources/commands/tags.ts +7 -3
- package/src/modules/sales/api/quotes/send/route.ts +17 -12
- package/src/modules/sales/commands/documents.ts +673 -481
- package/src/modules/sales/commands/payments.ts +158 -152
- package/src/modules/sales/commands/returns.ts +74 -63
- package/src/modules/staff/acl.ts +11 -0
- package/src/modules/staff/analytics.ts +30 -0
- package/src/modules/staff/api/guards.ts +59 -0
- package/src/modules/staff/api/interceptors.ts +122 -0
- package/src/modules/staff/api/timesheets/my-projects/[projectId]/route.ts +191 -0
- package/src/modules/staff/api/timesheets/my-projects/route.ts +115 -0
- package/src/modules/staff/api/timesheets/projects/kpis/route.ts +159 -0
- package/src/modules/staff/api/timesheets/time-entries/[id]/segments/[segmentId]/route.ts +187 -0
- package/src/modules/staff/api/timesheets/time-entries/[id]/segments/route.ts +191 -0
- package/src/modules/staff/api/timesheets/time-entries/[id]/timer-start/route.ts +168 -0
- package/src/modules/staff/api/timesheets/time-entries/[id]/timer-stop/route.ts +191 -0
- package/src/modules/staff/api/timesheets/time-entries/bulk/route.ts +292 -0
- package/src/modules/staff/api/timesheets/time-entries/route.ts +193 -0
- package/src/modules/staff/api/timesheets/time-projects/[id]/employees/route.ts +167 -0
- package/src/modules/staff/api/timesheets/time-projects/route.ts +244 -0
- package/src/modules/staff/backend/staff/timesheets/page.meta.ts +20 -0
- package/src/modules/staff/backend/staff/timesheets/page.tsx +899 -0
- package/src/modules/staff/backend/staff/timesheets/projects/[id]/edit/page.meta.ts +12 -0
- package/src/modules/staff/backend/staff/timesheets/projects/[id]/edit/page.tsx +141 -0
- package/src/modules/staff/backend/staff/timesheets/projects/[id]/page.meta.ts +12 -0
- package/src/modules/staff/backend/staff/timesheets/projects/[id]/page.tsx +579 -0
- package/src/modules/staff/backend/staff/timesheets/projects/create/page.meta.ts +12 -0
- package/src/modules/staff/backend/staff/timesheets/projects/create/page.tsx +90 -0
- package/src/modules/staff/backend/staff/timesheets/projects/page.meta.ts +23 -0
- package/src/modules/staff/backend/staff/timesheets/projects/page.tsx +765 -0
- package/src/modules/staff/backend/staff/timesheets/projects/projectFormConfig.ts +138 -0
- package/src/modules/staff/cli.ts +40 -1
- package/src/modules/staff/commands/index.ts +2 -0
- package/src/modules/staff/commands/leave-requests.ts +37 -29
- package/src/modules/staff/commands/team-members.ts +25 -20
- package/src/modules/staff/commands/timesheets-entries.ts +504 -0
- package/src/modules/staff/commands/timesheets-projects.ts +699 -0
- package/src/modules/staff/data/enrichers.ts +134 -0
- package/src/modules/staff/data/entities.ts +198 -0
- package/src/modules/staff/data/validators.ts +129 -0
- package/src/modules/staff/events.ts +13 -0
- package/src/modules/staff/i18n/de.json +209 -1
- package/src/modules/staff/i18n/en.json +209 -1
- package/src/modules/staff/i18n/es.json +209 -1
- package/src/modules/staff/i18n/pl.json +209 -1
- package/src/modules/staff/lib/crud.ts +8 -0
- package/src/modules/staff/lib/staffMemberResolver.ts +22 -0
- package/src/modules/staff/lib/timesheets-projects/computeProjectHoursTrend.ts +89 -0
- package/src/modules/staff/lib/timesheets-projects/computeProjectsKpis.ts +311 -0
- package/src/modules/staff/lib/timesheets-projects/dateBuckets.ts +37 -0
- package/src/modules/staff/lib/timesheets-projects/initials.ts +6 -0
- package/src/modules/staff/lib/timesheets-projects/kpiMath.ts +8 -0
- package/src/modules/staff/lib/timesheets-projects/listProjectMembersPreview.ts +83 -0
- package/src/modules/staff/lib/timesheets-projects-ui/HoursSparkline.tsx +75 -0
- package/src/modules/staff/lib/timesheets-projects-ui/ProjectCard.tsx +110 -0
- package/src/modules/staff/lib/timesheets-projects-ui/ProjectMembersAvatarStack.tsx +73 -0
- package/src/modules/staff/lib/timesheets-projects-ui/ProjectsKpiStrip.tsx +185 -0
- package/src/modules/staff/lib/timesheets-projects-ui/SavedViewTabs.tsx +53 -0
- package/src/modules/staff/lib/timesheets-projects-ui/ViewModeToggle.tsx +63 -0
- package/src/modules/staff/lib/timesheets-projects-ui/useProjectsViewMode.ts +63 -0
- package/src/modules/staff/lib/timesheets-ui/AddRowDropdown.tsx +188 -0
- package/src/modules/staff/lib/timesheets-ui/CalendarPicker.tsx +229 -0
- package/src/modules/staff/lib/timesheets-ui/ColorPicker.tsx +65 -0
- package/src/modules/staff/lib/timesheets-ui/CreateProjectDialog.tsx +99 -0
- package/src/modules/staff/lib/timesheets-ui/ListView.tsx +230 -0
- package/src/modules/staff/lib/timesheets-ui/ProjectColorDot.tsx +40 -0
- package/src/modules/staff/lib/timesheets-ui/TimerBar.tsx +327 -0
- package/src/modules/staff/lib/timesheets-ui/ViewSwitcher.tsx +60 -0
- package/src/modules/staff/lib/timesheets-ui/colors.ts +58 -0
- package/src/modules/staff/migrations/.snapshot-open-mercato.json +1148 -0
- package/src/modules/staff/migrations/Migration20260326135612.ts +26 -0
- package/src/modules/staff/migrations/Migration20260413102715.ts +25 -0
- package/src/modules/staff/migrations/Migration20260413111602.ts +13 -0
- package/src/modules/staff/migrations/Migration20260511112759.ts +21 -0
- package/src/modules/staff/search.ts +35 -0
- package/src/modules/staff/setup.ts +15 -0
- package/src/modules/staff/widgets/dashboard/timesheets-hours-by-project/config.ts +17 -0
- package/src/modules/staff/widgets/dashboard/timesheets-hours-by-project/widget.client.tsx +158 -0
- package/src/modules/staff/widgets/dashboard/timesheets-hours-by-project/widget.ts +25 -0
- package/src/modules/staff/widgets/dashboard/timesheets-time-reporting/config.ts +15 -0
- package/src/modules/staff/widgets/dashboard/timesheets-time-reporting/widget.client.tsx +297 -0
- package/src/modules/staff/widgets/dashboard/timesheets-time-reporting/widget.ts +25 -0
- package/src/modules/staff/widgets/injection/timer-sidebar-indicator/widget.tsx +161 -0
- package/src/modules/staff/widgets/injection-table.ts +10 -0
- package/src/modules/sync_excel/api/import/route.ts +23 -18
- package/src/modules/translations/commands/translations.ts +49 -41
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { NextResponse } from 'next/server'
|
|
2
|
+
import { z } from 'zod'
|
|
3
|
+
import { createRequestContainer } from '@open-mercato/shared/lib/di/container'
|
|
4
|
+
import { getAuthFromRequest } from '@open-mercato/shared/lib/auth/server'
|
|
5
|
+
import { resolveOrganizationScopeForRequest } from '@open-mercato/core/modules/directory/utils/organizationScope'
|
|
6
|
+
import { CrudHttpError } from '@open-mercato/shared/lib/crud/errors'
|
|
7
|
+
import { resolveTranslations } from '@open-mercato/shared/lib/i18n/server'
|
|
8
|
+
import { findOneWithDecryption, findWithDecryption } from '@open-mercato/shared/lib/encryption/find'
|
|
9
|
+
import type { EntityManager } from '@mikro-orm/postgresql'
|
|
10
|
+
import type { OpenApiRouteDoc } from '@open-mercato/shared/lib/openapi'
|
|
11
|
+
import { StaffTimeEntry, StaffTimeEntrySegment } from '../../../../../data/entities'
|
|
12
|
+
import { getStaffMemberByUserId } from '../../../../../lib/staffMemberResolver'
|
|
13
|
+
import {
|
|
14
|
+
resolveUserFeatures,
|
|
15
|
+
runStaffMutationGuardAfterSuccess,
|
|
16
|
+
runStaffMutationGuards,
|
|
17
|
+
} from '../../../../guards'
|
|
18
|
+
import { emitStaffEvent } from '../../../../../events'
|
|
19
|
+
|
|
20
|
+
function extractEntryIdFromUrl(request?: Request): string | null {
|
|
21
|
+
if (!request?.url) return null
|
|
22
|
+
try {
|
|
23
|
+
const url = new URL(request.url)
|
|
24
|
+
const match = url.pathname.match(/\/time-entries\/([^/]+)\/timer-stop/)
|
|
25
|
+
return match?.[1] ?? null
|
|
26
|
+
} catch {
|
|
27
|
+
return null
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const metadata = {
|
|
32
|
+
POST: { requireAuth: true, requireFeatures: ['staff.timesheets.manage_own'] },
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export async function POST(req: Request) {
|
|
36
|
+
try {
|
|
37
|
+
const container = await createRequestContainer()
|
|
38
|
+
const auth = await getAuthFromRequest(req)
|
|
39
|
+
const { translate } = await resolveTranslations()
|
|
40
|
+
if (!auth) throw new CrudHttpError(401, { error: translate('staff.errors.unauthorized', 'Unauthorized') })
|
|
41
|
+
|
|
42
|
+
const scope = await resolveOrganizationScopeForRequest({ container, auth, request: req })
|
|
43
|
+
const tenantId = scope?.tenantId ?? auth.tenantId ?? null
|
|
44
|
+
const organizationId = scope?.selectedId ?? auth.orgId ?? null
|
|
45
|
+
if (!tenantId || !organizationId) {
|
|
46
|
+
throw new CrudHttpError(400, { error: translate('staff.errors.missingScope', 'Missing tenant or organization scope.') })
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const em = (container.resolve('em') as EntityManager).fork()
|
|
50
|
+
const scopeCtx = { tenantId, organizationId }
|
|
51
|
+
|
|
52
|
+
const entryId = extractEntryIdFromUrl(req)
|
|
53
|
+
if (!entryId) {
|
|
54
|
+
throw new CrudHttpError(400, { error: translate('staff.timesheets.errors.missingEntryId', 'Missing entry ID.') })
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const entry = await findOneWithDecryption(
|
|
58
|
+
em,
|
|
59
|
+
StaffTimeEntry,
|
|
60
|
+
{ id: entryId, tenantId, organizationId, deletedAt: null },
|
|
61
|
+
{},
|
|
62
|
+
scopeCtx,
|
|
63
|
+
)
|
|
64
|
+
if (!entry) {
|
|
65
|
+
throw new CrudHttpError(404, { error: translate('staff.timesheets.errors.entryNotFound', 'Time entry not found.') })
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const staffMember = await getStaffMemberByUserId(em, auth.sub, tenantId, organizationId)
|
|
69
|
+
if (!staffMember || entry.staffMemberId !== staffMember.id) {
|
|
70
|
+
throw new CrudHttpError(403, { error: translate('staff.timesheets.errors.notOwner', 'You can only manage your own time entries.') })
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const segments = await findWithDecryption(
|
|
74
|
+
em,
|
|
75
|
+
StaffTimeEntrySegment,
|
|
76
|
+
{ timeEntryId: entry.id, tenantId, organizationId, deletedAt: null },
|
|
77
|
+
{},
|
|
78
|
+
scopeCtx,
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
const activeSegment = segments.find((segment) => !segment.endedAt)
|
|
82
|
+
if (!activeSegment) {
|
|
83
|
+
return NextResponse.json(
|
|
84
|
+
{ error: translate('staff.timesheets.errors.noActiveSegment', 'No active timer segment found for this entry.') },
|
|
85
|
+
{ status: 409 },
|
|
86
|
+
)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const guardResult = await runStaffMutationGuards(
|
|
90
|
+
container,
|
|
91
|
+
{
|
|
92
|
+
tenantId,
|
|
93
|
+
organizationId,
|
|
94
|
+
userId: auth.sub ?? '',
|
|
95
|
+
resourceKind: 'staff.timesheets.time_entry',
|
|
96
|
+
resourceId: entry.id,
|
|
97
|
+
operation: 'update',
|
|
98
|
+
requestMethod: req.method,
|
|
99
|
+
requestHeaders: req.headers,
|
|
100
|
+
},
|
|
101
|
+
resolveUserFeatures(auth),
|
|
102
|
+
)
|
|
103
|
+
if (!guardResult.ok) {
|
|
104
|
+
return NextResponse.json(
|
|
105
|
+
guardResult.errorBody ?? { error: 'Operation blocked by guard' },
|
|
106
|
+
{ status: guardResult.errorStatus ?? 422 },
|
|
107
|
+
)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const now = new Date()
|
|
111
|
+
activeSegment.endedAt = now
|
|
112
|
+
entry.endedAt = now
|
|
113
|
+
|
|
114
|
+
const allSegments = segments.map((segment) => {
|
|
115
|
+
if (segment.id === activeSegment.id) {
|
|
116
|
+
return { ...segment, endedAt: now }
|
|
117
|
+
}
|
|
118
|
+
return segment
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
const totalWorkMinutes = allSegments
|
|
122
|
+
.filter((segment) => segment.segmentType === 'work' && segment.startedAt && segment.endedAt)
|
|
123
|
+
.reduce((sum, segment) => {
|
|
124
|
+
const startMs = new Date(segment.startedAt).getTime()
|
|
125
|
+
const endMs = new Date(segment.endedAt!).getTime()
|
|
126
|
+
return sum + (endMs - startMs)
|
|
127
|
+
}, 0)
|
|
128
|
+
|
|
129
|
+
const durationMinutes = Math.round(totalWorkMinutes / 60000)
|
|
130
|
+
entry.durationMinutes = durationMinutes
|
|
131
|
+
|
|
132
|
+
await em.flush()
|
|
133
|
+
|
|
134
|
+
void emitStaffEvent('staff.timesheets.time_entry.timer_stopped', {
|
|
135
|
+
id: entry.id,
|
|
136
|
+
staffMemberId: entry.staffMemberId,
|
|
137
|
+
tenantId: entry.tenantId,
|
|
138
|
+
organizationId: entry.organizationId,
|
|
139
|
+
stoppedAt: now.toISOString(),
|
|
140
|
+
durationMinutes,
|
|
141
|
+
}, { persistent: true }).catch((err) => {
|
|
142
|
+
console.error('[staff.timesheets] emit timer_stopped failed', err)
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
if (guardResult.afterSuccessCallbacks.length) {
|
|
146
|
+
await runStaffMutationGuardAfterSuccess(guardResult.afterSuccessCallbacks, {
|
|
147
|
+
tenantId,
|
|
148
|
+
organizationId,
|
|
149
|
+
userId: auth.sub ?? '',
|
|
150
|
+
resourceKind: 'staff.timesheets.time_entry',
|
|
151
|
+
resourceId: entry.id,
|
|
152
|
+
operation: 'update',
|
|
153
|
+
requestMethod: req.method,
|
|
154
|
+
requestHeaders: req.headers,
|
|
155
|
+
})
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return NextResponse.json({ ok: true, durationMinutes }, { status: 200 })
|
|
159
|
+
} catch (err) {
|
|
160
|
+
if (err instanceof CrudHttpError) {
|
|
161
|
+
return NextResponse.json(err.body, { status: err.status })
|
|
162
|
+
}
|
|
163
|
+
const { translate } = await resolveTranslations()
|
|
164
|
+
console.error('staff.timesheets.time-entries.timer-stop failed', err)
|
|
165
|
+
return NextResponse.json(
|
|
166
|
+
{ error: translate('staff.timesheets.errors.timerStop', 'Failed to stop timer.') },
|
|
167
|
+
{ status: 400 },
|
|
168
|
+
)
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export const openApi: OpenApiRouteDoc = {
|
|
173
|
+
tag: 'Staff',
|
|
174
|
+
summary: 'Stop timer for a time entry',
|
|
175
|
+
methods: {
|
|
176
|
+
POST: {
|
|
177
|
+
summary: 'Stop timer for a time entry',
|
|
178
|
+
description: 'Stops the active timer segment, recalculates total work duration in minutes, and updates the time entry.',
|
|
179
|
+
responses: [
|
|
180
|
+
{
|
|
181
|
+
status: 200,
|
|
182
|
+
description: 'Timer stopped',
|
|
183
|
+
schema: z.object({ ok: z.literal(true), durationMinutes: z.number() }),
|
|
184
|
+
},
|
|
185
|
+
{ status: 404, description: 'Time entry not found', schema: z.object({ error: z.string() }) },
|
|
186
|
+
{ status: 409, description: 'No active timer segment', schema: z.object({ error: z.string() }) },
|
|
187
|
+
{ status: 401, description: 'Unauthorized', schema: z.object({ error: z.string() }) },
|
|
188
|
+
],
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
}
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
import { NextResponse } from 'next/server'
|
|
2
|
+
import { z } from 'zod'
|
|
3
|
+
import { createRequestContainer } from '@open-mercato/shared/lib/di/container'
|
|
4
|
+
import { getAuthFromRequest } from '@open-mercato/shared/lib/auth/server'
|
|
5
|
+
import { resolveOrganizationScopeForRequest } from '@open-mercato/core/modules/directory/utils/organizationScope'
|
|
6
|
+
import { CrudHttpError } from '@open-mercato/shared/lib/crud/errors'
|
|
7
|
+
import { resolveTranslations } from '@open-mercato/shared/lib/i18n/server'
|
|
8
|
+
import { findOneWithDecryption, findWithDecryption } from '@open-mercato/shared/lib/encryption/find'
|
|
9
|
+
import { readJsonSafe } from '@open-mercato/shared/lib/http/readJsonSafe'
|
|
10
|
+
import { emitCrudSideEffects, flushCrudSideEffects } from '@open-mercato/shared/lib/commands/helpers'
|
|
11
|
+
import type { DataEngine } from '@open-mercato/shared/lib/data/engine'
|
|
12
|
+
import type { EntityManager } from '@mikro-orm/postgresql'
|
|
13
|
+
import type { OpenApiRouteDoc } from '@open-mercato/shared/lib/openapi'
|
|
14
|
+
import { StaffTimeEntry, StaffTeamMember, StaffTimeProject } from '../../../../data/entities'
|
|
15
|
+
import { staffTimeEntryBulkSaveSchema } from '../../../../data/validators'
|
|
16
|
+
import { staffTimeEntryCrudEvents } from '../../../../lib/crud'
|
|
17
|
+
import {
|
|
18
|
+
resolveUserFeatures,
|
|
19
|
+
runStaffMutationGuardAfterSuccess,
|
|
20
|
+
runStaffMutationGuards,
|
|
21
|
+
} from '../../../guards'
|
|
22
|
+
|
|
23
|
+
export const metadata = {
|
|
24
|
+
POST: { requireAuth: true, requireFeatures: ['staff.timesheets.manage_own'] },
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export async function POST(req: Request) {
|
|
28
|
+
try {
|
|
29
|
+
const container = await createRequestContainer()
|
|
30
|
+
const auth = await getAuthFromRequest(req)
|
|
31
|
+
const { translate } = await resolveTranslations()
|
|
32
|
+
if (!auth) throw new CrudHttpError(401, { error: translate('staff.errors.unauthorized', 'Unauthorized') })
|
|
33
|
+
|
|
34
|
+
const scope = await resolveOrganizationScopeForRequest({ container, auth, request: req })
|
|
35
|
+
const tenantId = scope?.tenantId ?? auth.tenantId ?? null
|
|
36
|
+
const organizationId = scope?.selectedId ?? auth.orgId ?? null
|
|
37
|
+
if (!tenantId || !organizationId) {
|
|
38
|
+
throw new CrudHttpError(400, { error: translate('staff.errors.missingScope', 'Missing tenant or organization scope.') })
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const body = await readJsonSafe(req, {})
|
|
42
|
+
const parsed = staffTimeEntryBulkSaveSchema.safeParse(body)
|
|
43
|
+
if (!parsed.success) {
|
|
44
|
+
const errors = parsed.error.issues.map((issue) => ({
|
|
45
|
+
path: issue.path.join('.'),
|
|
46
|
+
message: issue.message,
|
|
47
|
+
}))
|
|
48
|
+
return NextResponse.json({ ok: false, errors }, { status: 422 })
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const { entries } = parsed.data
|
|
52
|
+
|
|
53
|
+
const em = (container.resolve('em') as EntityManager).fork()
|
|
54
|
+
const scopeCtx = { tenantId, organizationId }
|
|
55
|
+
|
|
56
|
+
const staffMember = await findOneWithDecryption(
|
|
57
|
+
em,
|
|
58
|
+
StaffTeamMember,
|
|
59
|
+
{ userId: auth.sub, tenantId, organizationId, deletedAt: null },
|
|
60
|
+
{},
|
|
61
|
+
scopeCtx,
|
|
62
|
+
)
|
|
63
|
+
if (!staffMember) {
|
|
64
|
+
throw new CrudHttpError(403, { error: translate('staff.timesheets.errors.noStaffMember', 'No staff member linked to your account.') })
|
|
65
|
+
}
|
|
66
|
+
const staffMemberId = staffMember.id
|
|
67
|
+
|
|
68
|
+
// Validate that all referenced timeProjectIds exist and are in-scope
|
|
69
|
+
const referencedProjectIds = [
|
|
70
|
+
...new Set(
|
|
71
|
+
entries
|
|
72
|
+
.map((e) => e.timeProjectId)
|
|
73
|
+
.filter((id): id is string => typeof id === 'string' && id.length > 0),
|
|
74
|
+
),
|
|
75
|
+
]
|
|
76
|
+
if (referencedProjectIds.length > 0) {
|
|
77
|
+
const validProjects = await em.find(StaffTimeProject, {
|
|
78
|
+
id: { $in: referencedProjectIds },
|
|
79
|
+
tenantId,
|
|
80
|
+
organizationId,
|
|
81
|
+
deletedAt: null,
|
|
82
|
+
}, { fields: ['id'] })
|
|
83
|
+
const validIds = new Set(validProjects.map((p) => p.id))
|
|
84
|
+
const invalidIds = referencedProjectIds.filter((id) => !validIds.has(id))
|
|
85
|
+
if (invalidIds.length > 0) {
|
|
86
|
+
return NextResponse.json(
|
|
87
|
+
{
|
|
88
|
+
ok: false,
|
|
89
|
+
errors: invalidIds.map((id) => ({
|
|
90
|
+
path: 'entries[].timeProjectId',
|
|
91
|
+
message: translate('staff.timesheets.errors.projectNotFound', 'Time project not found or not accessible.'),
|
|
92
|
+
value: id,
|
|
93
|
+
})),
|
|
94
|
+
},
|
|
95
|
+
{ status: 422 },
|
|
96
|
+
)
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const guardInput = {
|
|
101
|
+
tenantId,
|
|
102
|
+
organizationId,
|
|
103
|
+
userId: auth.sub ?? '',
|
|
104
|
+
resourceKind: 'staff.timesheets.time_entry',
|
|
105
|
+
resourceId: staffMemberId,
|
|
106
|
+
operation: 'update' as const,
|
|
107
|
+
requestMethod: req.method,
|
|
108
|
+
requestHeaders: req.headers,
|
|
109
|
+
mutationPayload: parsed.data as unknown as Record<string, unknown>,
|
|
110
|
+
}
|
|
111
|
+
const guardResult = await runStaffMutationGuards(container, guardInput, resolveUserFeatures(auth))
|
|
112
|
+
if (!guardResult.ok) {
|
|
113
|
+
return NextResponse.json(
|
|
114
|
+
guardResult.errorBody ?? { error: 'Operation blocked by guard' },
|
|
115
|
+
{ status: guardResult.errorStatus ?? 422 },
|
|
116
|
+
)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const existingIds = entries
|
|
120
|
+
.map((entry) => entry.id)
|
|
121
|
+
.filter((id): id is string => typeof id === 'string' && id.length > 0)
|
|
122
|
+
|
|
123
|
+
// Validate referenced entry IDs upfront: a stale or foreign UUID would
|
|
124
|
+
// otherwise fall through to the create branch in the loop below and insert
|
|
125
|
+
// a duplicate row with that ID-less new identity. Reject as 422 instead.
|
|
126
|
+
if (existingIds.length > 0) {
|
|
127
|
+
const resolvedExisting = await em.find(
|
|
128
|
+
StaffTimeEntry,
|
|
129
|
+
{ id: { $in: existingIds }, tenantId, organizationId, staffMemberId, deletedAt: null },
|
|
130
|
+
{ fields: ['id'] },
|
|
131
|
+
)
|
|
132
|
+
const resolvedIdSet = new Set(resolvedExisting.map((entry) => entry.id))
|
|
133
|
+
const invalidIds = existingIds.filter((id) => !resolvedIdSet.has(id))
|
|
134
|
+
if (invalidIds.length > 0) {
|
|
135
|
+
return NextResponse.json(
|
|
136
|
+
{
|
|
137
|
+
ok: false,
|
|
138
|
+
errors: invalidIds.map((id) => ({
|
|
139
|
+
path: 'entries[].id',
|
|
140
|
+
message: translate(
|
|
141
|
+
'staff.timesheets.errors.entryNotFound',
|
|
142
|
+
'Time entry not found, deleted, or not owned by you.',
|
|
143
|
+
),
|
|
144
|
+
value: id,
|
|
145
|
+
})),
|
|
146
|
+
},
|
|
147
|
+
{ status: 422 },
|
|
148
|
+
)
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
type PendingChange = {
|
|
153
|
+
action: 'created' | 'updated' | 'deleted'
|
|
154
|
+
entity: StaffTimeEntry
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const { counts, pendingChanges } = await em.transactional(async (trx) => {
|
|
158
|
+
let created = 0
|
|
159
|
+
let updated = 0
|
|
160
|
+
let deleted = 0
|
|
161
|
+
const changes: PendingChange[] = []
|
|
162
|
+
|
|
163
|
+
const existingEntries = existingIds.length > 0
|
|
164
|
+
? await findWithDecryption(
|
|
165
|
+
trx,
|
|
166
|
+
StaffTimeEntry,
|
|
167
|
+
{ id: { $in: existingIds }, tenantId, organizationId, staffMemberId, deletedAt: null },
|
|
168
|
+
{},
|
|
169
|
+
scopeCtx,
|
|
170
|
+
)
|
|
171
|
+
: []
|
|
172
|
+
|
|
173
|
+
const existingMap = new Map(existingEntries.map((entry) => [entry.id, entry]))
|
|
174
|
+
|
|
175
|
+
for (const entry of entries) {
|
|
176
|
+
if (entry.id && existingMap.has(entry.id)) {
|
|
177
|
+
const existing = existingMap.get(entry.id)!
|
|
178
|
+
if (entry.durationMinutes === 0) {
|
|
179
|
+
existing.deletedAt = new Date()
|
|
180
|
+
deleted++
|
|
181
|
+
changes.push({ action: 'deleted', entity: existing })
|
|
182
|
+
} else {
|
|
183
|
+
existing.date = entry.date
|
|
184
|
+
existing.timeProjectId = entry.timeProjectId
|
|
185
|
+
existing.durationMinutes = entry.durationMinutes
|
|
186
|
+
existing.notes = entry.notes ?? existing.notes
|
|
187
|
+
existing.updatedAt = new Date()
|
|
188
|
+
updated++
|
|
189
|
+
changes.push({ action: 'updated', entity: existing })
|
|
190
|
+
}
|
|
191
|
+
} else {
|
|
192
|
+
const now = new Date()
|
|
193
|
+
const newEntry = trx.create(StaffTimeEntry, {
|
|
194
|
+
tenantId,
|
|
195
|
+
organizationId,
|
|
196
|
+
staffMemberId,
|
|
197
|
+
date: entry.date,
|
|
198
|
+
timeProjectId: entry.timeProjectId,
|
|
199
|
+
durationMinutes: entry.durationMinutes,
|
|
200
|
+
notes: entry.notes ?? null,
|
|
201
|
+
source: 'manual',
|
|
202
|
+
createdAt: now,
|
|
203
|
+
updatedAt: now,
|
|
204
|
+
})
|
|
205
|
+
created++
|
|
206
|
+
changes.push({ action: 'created', entity: newEntry })
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
await trx.flush()
|
|
211
|
+
return { counts: { created, updated, deleted }, pendingChanges: changes }
|
|
212
|
+
})
|
|
213
|
+
|
|
214
|
+
const dataEngine = container.resolve<DataEngine>('dataEngine')
|
|
215
|
+
for (const change of pendingChanges) {
|
|
216
|
+
await emitCrudSideEffects({
|
|
217
|
+
dataEngine,
|
|
218
|
+
action: change.action,
|
|
219
|
+
entity: change.entity,
|
|
220
|
+
identifiers: {
|
|
221
|
+
id: change.entity.id,
|
|
222
|
+
organizationId: change.entity.organizationId,
|
|
223
|
+
tenantId: change.entity.tenantId,
|
|
224
|
+
},
|
|
225
|
+
events: staffTimeEntryCrudEvents,
|
|
226
|
+
})
|
|
227
|
+
}
|
|
228
|
+
await flushCrudSideEffects(dataEngine)
|
|
229
|
+
|
|
230
|
+
if (guardResult.afterSuccessCallbacks.length) {
|
|
231
|
+
await runStaffMutationGuardAfterSuccess(guardResult.afterSuccessCallbacks, {
|
|
232
|
+
tenantId,
|
|
233
|
+
organizationId,
|
|
234
|
+
userId: auth.sub ?? '',
|
|
235
|
+
resourceKind: 'staff.timesheets.time_entry',
|
|
236
|
+
resourceId: staffMemberId,
|
|
237
|
+
operation: 'update',
|
|
238
|
+
requestMethod: req.method,
|
|
239
|
+
requestHeaders: req.headers,
|
|
240
|
+
})
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
return NextResponse.json({ ok: true, ...counts }, { status: 200 })
|
|
244
|
+
} catch (err) {
|
|
245
|
+
if (err instanceof CrudHttpError) {
|
|
246
|
+
return NextResponse.json(err.body, { status: err.status })
|
|
247
|
+
}
|
|
248
|
+
const { translate } = await resolveTranslations()
|
|
249
|
+
console.error('staff.timesheets.time-entries.bulk failed', err)
|
|
250
|
+
return NextResponse.json(
|
|
251
|
+
{ error: translate('staff.timesheets.errors.bulkSave', 'Failed to bulk save time entries.') },
|
|
252
|
+
{ status: 400 },
|
|
253
|
+
)
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export const openApi: OpenApiRouteDoc = {
|
|
258
|
+
tag: 'Staff',
|
|
259
|
+
summary: 'Bulk save time entries',
|
|
260
|
+
methods: {
|
|
261
|
+
POST: {
|
|
262
|
+
summary: 'Bulk save time entries',
|
|
263
|
+
description: 'Creates, updates, or soft-deletes multiple time entries in a single request. Entries with durationMinutes=0 and an existing id are soft-deleted.',
|
|
264
|
+
requestBody: {
|
|
265
|
+
contentType: 'application/json',
|
|
266
|
+
schema: staffTimeEntryBulkSaveSchema,
|
|
267
|
+
},
|
|
268
|
+
responses: [
|
|
269
|
+
{
|
|
270
|
+
status: 200,
|
|
271
|
+
description: 'Bulk save completed',
|
|
272
|
+
schema: z.object({
|
|
273
|
+
ok: z.literal(true),
|
|
274
|
+
created: z.number(),
|
|
275
|
+
updated: z.number(),
|
|
276
|
+
deleted: z.number(),
|
|
277
|
+
}),
|
|
278
|
+
},
|
|
279
|
+
{
|
|
280
|
+
status: 422,
|
|
281
|
+
description: 'Validation error',
|
|
282
|
+
schema: z.object({
|
|
283
|
+
ok: z.literal(false),
|
|
284
|
+
errors: z.array(z.object({ path: z.string(), message: z.string() })),
|
|
285
|
+
}),
|
|
286
|
+
},
|
|
287
|
+
{ status: 401, description: 'Unauthorized', schema: z.object({ error: z.string() }) },
|
|
288
|
+
{ status: 403, description: 'Forbidden', schema: z.object({ error: z.string() }) },
|
|
289
|
+
],
|
|
290
|
+
},
|
|
291
|
+
},
|
|
292
|
+
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
import { makeCrudRoute } from '@open-mercato/shared/lib/crud/factory'
|
|
3
|
+
import { resolveTranslations } from '@open-mercato/shared/lib/i18n/server'
|
|
4
|
+
import { resolveCrudRecordId, parseScopedCommandInput } from '@open-mercato/shared/lib/api/scoped'
|
|
5
|
+
import { StaffTimeEntry } from '../../../data/entities'
|
|
6
|
+
import { staffTimeEntryCreateSchema, staffTimeEntryUpdateSchema } from '../../../data/validators'
|
|
7
|
+
import { createStaffCrudOpenApi, createPagedListResponseSchema, defaultOkResponseSchema } from '../../openapi'
|
|
8
|
+
|
|
9
|
+
const F = {
|
|
10
|
+
id: 'id',
|
|
11
|
+
tenant_id: 'tenant_id',
|
|
12
|
+
organization_id: 'organization_id',
|
|
13
|
+
staff_member_id: 'staff_member_id',
|
|
14
|
+
date: 'date',
|
|
15
|
+
duration_minutes: 'duration_minutes',
|
|
16
|
+
started_at: 'started_at',
|
|
17
|
+
ended_at: 'ended_at',
|
|
18
|
+
notes: 'notes',
|
|
19
|
+
time_project_id: 'time_project_id',
|
|
20
|
+
customer_id: 'customer_id',
|
|
21
|
+
deal_id: 'deal_id',
|
|
22
|
+
order_id: 'order_id',
|
|
23
|
+
source: 'source',
|
|
24
|
+
created_at: 'created_at',
|
|
25
|
+
updated_at: 'updated_at',
|
|
26
|
+
deleted_at: 'deleted_at',
|
|
27
|
+
} as const
|
|
28
|
+
|
|
29
|
+
const routeMetadata = {
|
|
30
|
+
GET: { requireAuth: true, requireFeatures: ['staff.timesheets.view'] },
|
|
31
|
+
POST: { requireAuth: true, requireFeatures: ['staff.timesheets.manage_own'] },
|
|
32
|
+
PUT: { requireAuth: true, requireFeatures: ['staff.timesheets.manage_own'] },
|
|
33
|
+
DELETE: { requireAuth: true, requireFeatures: ['staff.timesheets.manage_own'] },
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const metadata = routeMetadata
|
|
37
|
+
|
|
38
|
+
const rawBodySchema = z.object({}).passthrough()
|
|
39
|
+
|
|
40
|
+
const listSchema = z
|
|
41
|
+
.object({
|
|
42
|
+
page: z.coerce.number().min(1).default(1),
|
|
43
|
+
pageSize: z.coerce.number().min(1).max(100).default(50),
|
|
44
|
+
staffMemberId: z.string().uuid().optional(),
|
|
45
|
+
from: z.string().optional(),
|
|
46
|
+
to: z.string().optional(),
|
|
47
|
+
projectId: z.string().uuid().optional(),
|
|
48
|
+
ids: z.string().optional(),
|
|
49
|
+
sortField: z.string().optional(),
|
|
50
|
+
sortDir: z.enum(['asc', 'desc']).optional(),
|
|
51
|
+
})
|
|
52
|
+
.passthrough()
|
|
53
|
+
|
|
54
|
+
const crud = makeCrudRoute({
|
|
55
|
+
metadata: routeMetadata,
|
|
56
|
+
orm: {
|
|
57
|
+
entity: StaffTimeEntry,
|
|
58
|
+
idField: 'id',
|
|
59
|
+
orgField: 'organizationId',
|
|
60
|
+
tenantField: 'tenantId',
|
|
61
|
+
softDeleteField: 'deletedAt',
|
|
62
|
+
},
|
|
63
|
+
indexer: { entityType: 'staff:staff_time_entry' },
|
|
64
|
+
list: {
|
|
65
|
+
schema: listSchema,
|
|
66
|
+
entityId: 'staff:staff_time_entry',
|
|
67
|
+
fields: [
|
|
68
|
+
F.id,
|
|
69
|
+
F.organization_id,
|
|
70
|
+
F.tenant_id,
|
|
71
|
+
F.staff_member_id,
|
|
72
|
+
F.date,
|
|
73
|
+
F.duration_minutes,
|
|
74
|
+
F.started_at,
|
|
75
|
+
F.ended_at,
|
|
76
|
+
F.notes,
|
|
77
|
+
F.time_project_id,
|
|
78
|
+
F.customer_id,
|
|
79
|
+
F.deal_id,
|
|
80
|
+
F.order_id,
|
|
81
|
+
F.source,
|
|
82
|
+
F.created_at,
|
|
83
|
+
F.updated_at,
|
|
84
|
+
],
|
|
85
|
+
sortFieldMap: {
|
|
86
|
+
date: F.date,
|
|
87
|
+
createdAt: F.created_at,
|
|
88
|
+
updatedAt: F.updated_at,
|
|
89
|
+
durationMinutes: F.duration_minutes,
|
|
90
|
+
},
|
|
91
|
+
buildFilters: async (query) => {
|
|
92
|
+
const filters: Record<string, unknown> = {}
|
|
93
|
+
if (typeof query.ids === 'string' && query.ids.trim().length > 0) {
|
|
94
|
+
const ids = query.ids
|
|
95
|
+
.split(',')
|
|
96
|
+
.map((value) => value.trim())
|
|
97
|
+
.filter((value) => value.length > 0)
|
|
98
|
+
if (ids.length > 0) {
|
|
99
|
+
filters[F.id] = { $in: ids }
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (typeof query.staffMemberId === 'string' && query.staffMemberId.length > 0) {
|
|
103
|
+
filters[F.staff_member_id] = query.staffMemberId
|
|
104
|
+
}
|
|
105
|
+
if (typeof query.from === 'string' && query.from.length > 0) {
|
|
106
|
+
filters[F.date] = { ...((filters[F.date] as Record<string, unknown>) ?? {}), $gte: query.from }
|
|
107
|
+
}
|
|
108
|
+
if (typeof query.to === 'string' && query.to.length > 0) {
|
|
109
|
+
filters[F.date] = { ...((filters[F.date] as Record<string, unknown>) ?? {}), $lte: query.to }
|
|
110
|
+
}
|
|
111
|
+
if (typeof query.projectId === 'string' && query.projectId.length > 0) {
|
|
112
|
+
filters[F.time_project_id] = query.projectId
|
|
113
|
+
}
|
|
114
|
+
return filters
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
actions: {
|
|
118
|
+
create: {
|
|
119
|
+
commandId: 'staff.timesheets.time_entries.create',
|
|
120
|
+
schema: rawBodySchema,
|
|
121
|
+
mapInput: async ({ raw, ctx }) => {
|
|
122
|
+
const { translate } = await resolveTranslations()
|
|
123
|
+
return parseScopedCommandInput(staffTimeEntryCreateSchema, raw ?? {}, ctx, translate)
|
|
124
|
+
},
|
|
125
|
+
response: ({ result }) => ({ id: result?.timeEntryId ?? null }),
|
|
126
|
+
status: 201,
|
|
127
|
+
},
|
|
128
|
+
update: {
|
|
129
|
+
commandId: 'staff.timesheets.time_entries.update',
|
|
130
|
+
schema: rawBodySchema,
|
|
131
|
+
mapInput: async ({ raw, ctx }) => {
|
|
132
|
+
const { translate } = await resolveTranslations()
|
|
133
|
+
return parseScopedCommandInput(staffTimeEntryUpdateSchema, raw ?? {}, ctx, translate)
|
|
134
|
+
},
|
|
135
|
+
response: () => ({ ok: true }),
|
|
136
|
+
},
|
|
137
|
+
delete: {
|
|
138
|
+
commandId: 'staff.timesheets.time_entries.delete',
|
|
139
|
+
schema: rawBodySchema,
|
|
140
|
+
mapInput: async ({ parsed, ctx }) => {
|
|
141
|
+
const { translate } = await resolveTranslations()
|
|
142
|
+
const id = resolveCrudRecordId(parsed, ctx, translate)
|
|
143
|
+
return { id }
|
|
144
|
+
},
|
|
145
|
+
response: () => ({ ok: true }),
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
export const GET = crud.GET
|
|
151
|
+
export const POST = crud.POST
|
|
152
|
+
export const PUT = crud.PUT
|
|
153
|
+
export const DELETE = crud.DELETE
|
|
154
|
+
|
|
155
|
+
const timeEntryListItemSchema = z.object({
|
|
156
|
+
id: z.string().uuid().nullable().optional(),
|
|
157
|
+
organization_id: z.string().uuid().nullable().optional(),
|
|
158
|
+
tenant_id: z.string().uuid().nullable().optional(),
|
|
159
|
+
staff_member_id: z.string().uuid().nullable().optional(),
|
|
160
|
+
date: z.string().nullable().optional(),
|
|
161
|
+
duration_minutes: z.number().nullable().optional(),
|
|
162
|
+
started_at: z.string().nullable().optional(),
|
|
163
|
+
ended_at: z.string().nullable().optional(),
|
|
164
|
+
notes: z.string().nullable().optional(),
|
|
165
|
+
time_project_id: z.string().uuid().nullable().optional(),
|
|
166
|
+
customer_id: z.string().uuid().nullable().optional(),
|
|
167
|
+
deal_id: z.string().uuid().nullable().optional(),
|
|
168
|
+
order_id: z.string().uuid().nullable().optional(),
|
|
169
|
+
source: z.string().nullable().optional(),
|
|
170
|
+
created_at: z.string().nullable().optional(),
|
|
171
|
+
updated_at: z.string().nullable().optional(),
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
export const openApi = createStaffCrudOpenApi({
|
|
175
|
+
resourceName: 'TimeEntry',
|
|
176
|
+
pluralName: 'TimeEntries',
|
|
177
|
+
querySchema: listSchema,
|
|
178
|
+
listResponseSchema: createPagedListResponseSchema(timeEntryListItemSchema),
|
|
179
|
+
create: {
|
|
180
|
+
schema: staffTimeEntryCreateSchema,
|
|
181
|
+
description: 'Creates a time entry for a staff member.',
|
|
182
|
+
},
|
|
183
|
+
update: {
|
|
184
|
+
schema: staffTimeEntryUpdateSchema,
|
|
185
|
+
responseSchema: defaultOkResponseSchema,
|
|
186
|
+
description: 'Updates a time entry by id.',
|
|
187
|
+
},
|
|
188
|
+
del: {
|
|
189
|
+
schema: z.object({ id: z.string().uuid() }),
|
|
190
|
+
responseSchema: defaultOkResponseSchema,
|
|
191
|
+
description: 'Deletes a time entry by id.',
|
|
192
|
+
},
|
|
193
|
+
})
|