@open-mercato/core 0.6.4-develop.4217.1.c9aa050183 → 0.6.4-develop.4239.1.4a264a5828
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/business_rules/backend/logs/[id]/page.js +24 -5
- package/dist/modules/business_rules/backend/logs/[id]/page.js.map +2 -2
- package/dist/modules/catalog/api/offers/route.js +15 -5
- package/dist/modules/catalog/api/offers/route.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/backend/currencies/[id]/page.js +19 -2
- package/dist/modules/currencies/backend/currencies/[id]/page.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/customer_accounts/backend/customer_accounts/roles/[id]/page.js +27 -7
- package/dist/modules/customer_accounts/backend/customer_accounts/roles/[id]/page.js.map +2 -2
- package/dist/modules/customer_accounts/backend/customer_accounts/users/[id]/page.js +27 -7
- package/dist/modules/customer_accounts/backend/customer_accounts/users/[id]/page.js.map +2 -2
- package/dist/modules/customers/backend/customers/people/[id]/page.js +29 -8
- package/dist/modules/customers/backend/customers/people/[id]/page.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/progress/acl.js +8 -4
- package/dist/modules/progress/acl.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/dist/modules/workflows/backend/events/[id]/page.js +24 -6
- package/dist/modules/workflows/backend/events/[id]/page.js.map +2 -2
- package/dist/modules/workflows/backend/instances/[id]/page.js +27 -5
- package/dist/modules/workflows/backend/instances/[id]/page.js.map +2 -2
- package/dist/modules/workflows/backend/tasks/[id]/page.js +25 -6
- package/dist/modules/workflows/backend/tasks/[id]/page.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/business_rules/backend/logs/[id]/page.tsx +32 -7
- package/src/modules/catalog/api/offers/route.ts +20 -5
- 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/backend/currencies/[id]/page.tsx +21 -2
- package/src/modules/currencies/commands/currencies.ts +27 -14
- package/src/modules/currencies/i18n/de.json +1 -0
- package/src/modules/currencies/i18n/en.json +1 -0
- package/src/modules/currencies/i18n/es.json +1 -0
- package/src/modules/currencies/i18n/pl.json +1 -0
- 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/customer_accounts/backend/customer_accounts/roles/[id]/page.tsx +34 -11
- package/src/modules/customer_accounts/backend/customer_accounts/users/[id]/page.tsx +34 -11
- package/src/modules/customers/backend/customers/people/[id]/page.tsx +35 -11
- 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/progress/acl.ts +4 -0
- 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
- package/src/modules/workflows/backend/events/[id]/page.tsx +32 -10
- package/src/modules/workflows/backend/instances/[id]/page.tsx +33 -9
- package/src/modules/workflows/backend/tasks/[id]/page.tsx +33 -10
- package/src/modules/workflows/i18n/de.json +1 -0
- package/src/modules/workflows/i18n/en.json +1 -0
- package/src/modules/workflows/i18n/es.json +1 -0
- package/src/modules/workflows/i18n/pl.json +1 -0
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { NextResponse } from 'next/server'
|
|
2
|
+
import { z } from 'zod'
|
|
3
|
+
import type { OpenApiRouteDoc } from '@open-mercato/shared/lib/openapi'
|
|
4
|
+
import { getAuthFromRequest } from '@open-mercato/shared/lib/auth/server'
|
|
5
|
+
import { createRequestContainer } from '@open-mercato/shared/lib/di/container'
|
|
6
|
+
import { resolveOrganizationScopeForRequest } from '@open-mercato/core/modules/directory/utils/organizationScope'
|
|
7
|
+
import { findOneWithDecryption } from '@open-mercato/shared/lib/encryption/find'
|
|
8
|
+
import { readJsonSafe } from '@open-mercato/shared/lib/http/readJsonSafe'
|
|
9
|
+
import type { EntityManager } from '@mikro-orm/postgresql'
|
|
10
|
+
import { StaffTimeEntry, StaffTimeEntrySegment } from '../../../../../../data/entities'
|
|
11
|
+
import { staffTimeEntrySegmentUpdateSchema } from '../../../../../../data/validators'
|
|
12
|
+
import { getStaffMemberByUserId } from '../../../../../../lib/staffMemberResolver'
|
|
13
|
+
import {
|
|
14
|
+
resolveUserFeatures,
|
|
15
|
+
runStaffMutationGuardAfterSuccess,
|
|
16
|
+
runStaffMutationGuards,
|
|
17
|
+
} from '../../../../../guards'
|
|
18
|
+
|
|
19
|
+
const routeMetadata = {
|
|
20
|
+
PATCH: { requireAuth: true, requireFeatures: ['staff.timesheets.manage_own'] },
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const metadata = routeMetadata
|
|
24
|
+
|
|
25
|
+
function extractIdsFromUrl(request?: Request): { entryId: string; segmentId: string } | null {
|
|
26
|
+
if (!request?.url) return null
|
|
27
|
+
try {
|
|
28
|
+
const url = new URL(request.url)
|
|
29
|
+
const match = url.pathname.match(/\/time-entries\/([^/]+)\/segments\/([^/]+)/)
|
|
30
|
+
if (!match?.[1] || !match?.[2]) return null
|
|
31
|
+
return { entryId: match[1], segmentId: match[2] }
|
|
32
|
+
} catch {
|
|
33
|
+
return null
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export async function PATCH(req: Request) {
|
|
38
|
+
const auth = await getAuthFromRequest(req)
|
|
39
|
+
if (!auth) {
|
|
40
|
+
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const ids = extractIdsFromUrl(req)
|
|
44
|
+
if (!ids) {
|
|
45
|
+
return NextResponse.json({ error: 'Segment id is required' }, { status: 400 })
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const rawBody = await readJsonSafe<Record<string, unknown>>(req, null)
|
|
49
|
+
if (!rawBody) {
|
|
50
|
+
return NextResponse.json({ error: 'Invalid payload' }, { status: 400 })
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const parsed = staffTimeEntrySegmentUpdateSchema.safeParse({ ...rawBody, id: ids.segmentId })
|
|
54
|
+
if (!parsed.success) {
|
|
55
|
+
return NextResponse.json({ error: 'Invalid payload', details: parsed.error.flatten() }, { status: 400 })
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const container = await createRequestContainer()
|
|
59
|
+
const scope = await resolveOrganizationScopeForRequest({ container, auth, request: req })
|
|
60
|
+
const tenantId = scope?.tenantId ?? auth.tenantId ?? null
|
|
61
|
+
const organizationId = scope?.selectedId ?? auth.orgId ?? null
|
|
62
|
+
if (!tenantId || !organizationId) {
|
|
63
|
+
return NextResponse.json({ error: 'Missing tenant or organization scope.' }, { status: 400 })
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const em = (container.resolve('em') as EntityManager).fork()
|
|
67
|
+
const scopeCtx = { tenantId, organizationId }
|
|
68
|
+
|
|
69
|
+
const entry = await findOneWithDecryption(em, StaffTimeEntry, { id: ids.entryId, tenantId, organizationId, deletedAt: null }, {}, scopeCtx)
|
|
70
|
+
if (!entry) {
|
|
71
|
+
return NextResponse.json({ error: 'Time entry not found' }, { status: 404 })
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const staffMember = await getStaffMemberByUserId(em, auth.sub, tenantId, organizationId)
|
|
75
|
+
if (!staffMember || entry.staffMemberId !== staffMember.id) {
|
|
76
|
+
return NextResponse.json({ error: 'You can only manage your own time entries.' }, { status: 403 })
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const segment = await findOneWithDecryption(em, StaffTimeEntrySegment, {
|
|
80
|
+
id: ids.segmentId,
|
|
81
|
+
timeEntryId: ids.entryId,
|
|
82
|
+
tenantId,
|
|
83
|
+
organizationId,
|
|
84
|
+
deletedAt: null,
|
|
85
|
+
}, {}, scopeCtx)
|
|
86
|
+
|
|
87
|
+
if (!segment) {
|
|
88
|
+
return NextResponse.json({ error: 'Segment not found' }, { status: 404 })
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const guardResult = await runStaffMutationGuards(
|
|
92
|
+
container,
|
|
93
|
+
{
|
|
94
|
+
tenantId,
|
|
95
|
+
organizationId,
|
|
96
|
+
userId: auth.sub ?? '',
|
|
97
|
+
resourceKind: 'staff.timesheets.time_entry_segment',
|
|
98
|
+
resourceId: segment.id,
|
|
99
|
+
operation: 'update',
|
|
100
|
+
requestMethod: req.method,
|
|
101
|
+
requestHeaders: req.headers,
|
|
102
|
+
mutationPayload: parsed.data as unknown as Record<string, unknown>,
|
|
103
|
+
},
|
|
104
|
+
resolveUserFeatures(auth),
|
|
105
|
+
)
|
|
106
|
+
if (!guardResult.ok) {
|
|
107
|
+
return NextResponse.json(
|
|
108
|
+
guardResult.errorBody ?? { error: 'Operation blocked by guard' },
|
|
109
|
+
{ status: guardResult.errorStatus ?? 422 },
|
|
110
|
+
)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (parsed.data.startedAt !== undefined) {
|
|
114
|
+
segment.startedAt = parsed.data.startedAt
|
|
115
|
+
}
|
|
116
|
+
if (parsed.data.endedAt !== undefined) {
|
|
117
|
+
segment.endedAt = parsed.data.endedAt ?? null
|
|
118
|
+
}
|
|
119
|
+
if (parsed.data.segmentType !== undefined) {
|
|
120
|
+
segment.segmentType = parsed.data.segmentType
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
await em.flush()
|
|
124
|
+
|
|
125
|
+
if (guardResult.afterSuccessCallbacks.length) {
|
|
126
|
+
await runStaffMutationGuardAfterSuccess(guardResult.afterSuccessCallbacks, {
|
|
127
|
+
tenantId,
|
|
128
|
+
organizationId,
|
|
129
|
+
userId: auth.sub ?? '',
|
|
130
|
+
resourceKind: 'staff.timesheets.time_entry_segment',
|
|
131
|
+
resourceId: segment.id,
|
|
132
|
+
operation: 'update',
|
|
133
|
+
requestMethod: req.method,
|
|
134
|
+
requestHeaders: req.headers,
|
|
135
|
+
})
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return NextResponse.json({
|
|
139
|
+
ok: true,
|
|
140
|
+
item: {
|
|
141
|
+
id: segment.id,
|
|
142
|
+
timeEntryId: segment.timeEntryId,
|
|
143
|
+
startedAt: segment.startedAt,
|
|
144
|
+
endedAt: segment.endedAt,
|
|
145
|
+
segmentType: segment.segmentType,
|
|
146
|
+
createdAt: segment.createdAt,
|
|
147
|
+
updatedAt: segment.updatedAt,
|
|
148
|
+
},
|
|
149
|
+
})
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const errorSchema = z.object({ error: z.string() })
|
|
153
|
+
const segmentResponseSchema = z.object({
|
|
154
|
+
ok: z.literal(true),
|
|
155
|
+
item: z.object({
|
|
156
|
+
id: z.string(),
|
|
157
|
+
timeEntryId: z.string(),
|
|
158
|
+
startedAt: z.string(),
|
|
159
|
+
endedAt: z.string().nullable(),
|
|
160
|
+
segmentType: z.enum(['work', 'break']),
|
|
161
|
+
createdAt: z.string(),
|
|
162
|
+
updatedAt: z.string(),
|
|
163
|
+
}),
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
export const openApi: OpenApiRouteDoc = {
|
|
167
|
+
tag: 'Staff',
|
|
168
|
+
summary: 'Time entry segment management',
|
|
169
|
+
methods: {
|
|
170
|
+
PATCH: {
|
|
171
|
+
summary: 'Update a time entry segment',
|
|
172
|
+
description: 'Updates fields on an existing time entry segment (startedAt, endedAt, segmentType).',
|
|
173
|
+
requestBody: {
|
|
174
|
+
contentType: 'application/json',
|
|
175
|
+
schema: staffTimeEntrySegmentUpdateSchema.omit({ id: true }),
|
|
176
|
+
},
|
|
177
|
+
responses: [
|
|
178
|
+
{ status: 200, description: 'Segment updated successfully', schema: segmentResponseSchema },
|
|
179
|
+
],
|
|
180
|
+
errors: [
|
|
181
|
+
{ status: 400, description: 'Invalid payload or missing segment id', schema: errorSchema },
|
|
182
|
+
{ status: 401, description: 'Unauthorized', schema: errorSchema },
|
|
183
|
+
{ status: 404, description: 'Segment not found', schema: errorSchema },
|
|
184
|
+
],
|
|
185
|
+
},
|
|
186
|
+
},
|
|
187
|
+
}
|
|
@@ -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 { parseScopedCommandInput } from '@open-mercato/shared/lib/api/scoped'
|
|
9
|
+
import { findOneWithDecryption } from '@open-mercato/shared/lib/encryption/find'
|
|
10
|
+
import { readJsonSafe } from '@open-mercato/shared/lib/http/readJsonSafe'
|
|
11
|
+
import type { EntityManager } from '@mikro-orm/postgresql'
|
|
12
|
+
import type { OpenApiRouteDoc } from '@open-mercato/shared/lib/openapi'
|
|
13
|
+
import { StaffTimeEntry, StaffTimeEntrySegment } from '../../../../../data/entities'
|
|
14
|
+
import { staffTimeEntrySegmentCreateSchema } from '../../../../../data/validators'
|
|
15
|
+
import { getStaffMemberByUserId } from '../../../../../lib/staffMemberResolver'
|
|
16
|
+
import {
|
|
17
|
+
resolveUserFeatures,
|
|
18
|
+
runStaffMutationGuardAfterSuccess,
|
|
19
|
+
runStaffMutationGuards,
|
|
20
|
+
} from '../../../../guards'
|
|
21
|
+
|
|
22
|
+
function extractEntryIdFromUrl(request?: Request): string | null {
|
|
23
|
+
if (!request?.url) return null
|
|
24
|
+
try {
|
|
25
|
+
const url = new URL(request.url)
|
|
26
|
+
const match = url.pathname.match(/\/time-entries\/([^/]+)\/segments/)
|
|
27
|
+
return match?.[1] ?? null
|
|
28
|
+
} catch {
|
|
29
|
+
return null
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const metadata = {
|
|
34
|
+
POST: { requireAuth: true, requireFeatures: ['staff.timesheets.manage_own'] },
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export async function POST(req: Request) {
|
|
38
|
+
try {
|
|
39
|
+
const container = await createRequestContainer()
|
|
40
|
+
const auth = await getAuthFromRequest(req)
|
|
41
|
+
const { translate } = await resolveTranslations()
|
|
42
|
+
if (!auth) throw new CrudHttpError(401, { error: translate('staff.errors.unauthorized', 'Unauthorized') })
|
|
43
|
+
|
|
44
|
+
const scope = await resolveOrganizationScopeForRequest({ container, auth, request: req })
|
|
45
|
+
const tenantId = scope?.tenantId ?? auth.tenantId ?? null
|
|
46
|
+
const organizationId = scope?.selectedId ?? auth.orgId ?? null
|
|
47
|
+
if (!tenantId || !organizationId) {
|
|
48
|
+
throw new CrudHttpError(400, { error: translate('staff.errors.missingScope', 'Missing tenant or organization scope.') })
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const em = (container.resolve('em') as EntityManager).fork()
|
|
52
|
+
const scopeCtx = { tenantId, organizationId }
|
|
53
|
+
|
|
54
|
+
const entryId = extractEntryIdFromUrl(req)
|
|
55
|
+
if (!entryId) {
|
|
56
|
+
throw new CrudHttpError(400, { error: translate('staff.timesheets.errors.missingEntryId', 'Missing entry ID.') })
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const entry = await findOneWithDecryption(
|
|
60
|
+
em,
|
|
61
|
+
StaffTimeEntry,
|
|
62
|
+
{ id: entryId, tenantId, organizationId, deletedAt: null },
|
|
63
|
+
{},
|
|
64
|
+
scopeCtx,
|
|
65
|
+
)
|
|
66
|
+
if (!entry) {
|
|
67
|
+
throw new CrudHttpError(404, { error: translate('staff.timesheets.errors.entryNotFound', 'Time entry not found.') })
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const staffMember = await getStaffMemberByUserId(em, auth.sub, tenantId, organizationId)
|
|
71
|
+
if (!staffMember || entry.staffMemberId !== staffMember.id) {
|
|
72
|
+
throw new CrudHttpError(403, { error: translate('staff.timesheets.errors.notOwner', 'You can only manage your own time entries.') })
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const body = await readJsonSafe(req, {})
|
|
76
|
+
const input = parseScopedCommandInput(
|
|
77
|
+
staffTimeEntrySegmentCreateSchema,
|
|
78
|
+
{ ...body, timeEntryId: entryId },
|
|
79
|
+
{
|
|
80
|
+
container,
|
|
81
|
+
auth,
|
|
82
|
+
organizationScope: scope,
|
|
83
|
+
selectedOrganizationId: organizationId,
|
|
84
|
+
organizationIds: scope?.filterIds ?? (auth.orgId ? [auth.orgId] : null),
|
|
85
|
+
request: req,
|
|
86
|
+
},
|
|
87
|
+
translate,
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
const guardResult = await runStaffMutationGuards(
|
|
91
|
+
container,
|
|
92
|
+
{
|
|
93
|
+
tenantId,
|
|
94
|
+
organizationId,
|
|
95
|
+
userId: auth.sub ?? '',
|
|
96
|
+
resourceKind: 'staff.timesheets.time_entry_segment',
|
|
97
|
+
resourceId: entry.id,
|
|
98
|
+
operation: 'create',
|
|
99
|
+
requestMethod: req.method,
|
|
100
|
+
requestHeaders: req.headers,
|
|
101
|
+
mutationPayload: input as unknown as Record<string, unknown>,
|
|
102
|
+
},
|
|
103
|
+
resolveUserFeatures(auth),
|
|
104
|
+
)
|
|
105
|
+
if (!guardResult.ok) {
|
|
106
|
+
return NextResponse.json(
|
|
107
|
+
guardResult.errorBody ?? { error: 'Operation blocked by guard' },
|
|
108
|
+
{ status: guardResult.errorStatus ?? 422 },
|
|
109
|
+
)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const segmentData = {
|
|
113
|
+
tenantId: input.tenantId,
|
|
114
|
+
organizationId: input.organizationId,
|
|
115
|
+
timeEntryId: input.timeEntryId,
|
|
116
|
+
startedAt: input.startedAt,
|
|
117
|
+
endedAt: input.endedAt ?? null,
|
|
118
|
+
segmentType: input.segmentType,
|
|
119
|
+
}
|
|
120
|
+
const segment = em.create(StaffTimeEntrySegment, segmentData as never)
|
|
121
|
+
|
|
122
|
+
await em.flush()
|
|
123
|
+
|
|
124
|
+
if (guardResult.afterSuccessCallbacks.length) {
|
|
125
|
+
await runStaffMutationGuardAfterSuccess(guardResult.afterSuccessCallbacks, {
|
|
126
|
+
tenantId,
|
|
127
|
+
organizationId,
|
|
128
|
+
userId: auth.sub ?? '',
|
|
129
|
+
resourceKind: 'staff.timesheets.time_entry_segment',
|
|
130
|
+
resourceId: segment.id,
|
|
131
|
+
operation: 'create',
|
|
132
|
+
requestMethod: req.method,
|
|
133
|
+
requestHeaders: req.headers,
|
|
134
|
+
})
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return NextResponse.json(
|
|
138
|
+
{
|
|
139
|
+
id: segment.id,
|
|
140
|
+
timeEntryId: segment.timeEntryId,
|
|
141
|
+
startedAt: segment.startedAt,
|
|
142
|
+
endedAt: segment.endedAt ?? null,
|
|
143
|
+
segmentType: segment.segmentType,
|
|
144
|
+
createdAt: segment.createdAt,
|
|
145
|
+
},
|
|
146
|
+
{ status: 201 },
|
|
147
|
+
)
|
|
148
|
+
} catch (err) {
|
|
149
|
+
if (err instanceof CrudHttpError) {
|
|
150
|
+
return NextResponse.json(err.body, { status: err.status })
|
|
151
|
+
}
|
|
152
|
+
const { translate } = await resolveTranslations()
|
|
153
|
+
console.error('staff.timesheets.time-entries.segments.create failed', err)
|
|
154
|
+
return NextResponse.json(
|
|
155
|
+
{ error: translate('staff.timesheets.errors.segmentCreate', 'Failed to create time entry segment.') },
|
|
156
|
+
{ status: 400 },
|
|
157
|
+
)
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export const openApi: OpenApiRouteDoc = {
|
|
162
|
+
tag: 'Staff',
|
|
163
|
+
summary: 'Add a segment to a time entry',
|
|
164
|
+
methods: {
|
|
165
|
+
POST: {
|
|
166
|
+
summary: 'Add a segment to a time entry',
|
|
167
|
+
description: 'Creates a new work or break segment for the specified time entry.',
|
|
168
|
+
requestBody: {
|
|
169
|
+
contentType: 'application/json',
|
|
170
|
+
schema: staffTimeEntrySegmentCreateSchema,
|
|
171
|
+
},
|
|
172
|
+
responses: [
|
|
173
|
+
{
|
|
174
|
+
status: 201,
|
|
175
|
+
description: 'Segment created',
|
|
176
|
+
schema: z.object({
|
|
177
|
+
id: z.string().uuid(),
|
|
178
|
+
timeEntryId: z.string().uuid(),
|
|
179
|
+
startedAt: z.string(),
|
|
180
|
+
endedAt: z.string().nullable(),
|
|
181
|
+
segmentType: z.enum(['work', 'break']),
|
|
182
|
+
createdAt: z.string(),
|
|
183
|
+
}),
|
|
184
|
+
},
|
|
185
|
+
{ status: 404, description: 'Time entry not found', schema: z.object({ error: z.string() }) },
|
|
186
|
+
{ status: 400, description: 'Invalid payload', schema: z.object({ error: z.string() }) },
|
|
187
|
+
{ status: 401, description: 'Unauthorized', schema: z.object({ error: z.string() }) },
|
|
188
|
+
],
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
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 } 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-start/)
|
|
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
|
+
if (entry.startedAt) {
|
|
74
|
+
return NextResponse.json(
|
|
75
|
+
{ error: translate('staff.timesheets.errors.timerAlreadyStarted', 'Timer is already started for this entry.') },
|
|
76
|
+
{ status: 409 },
|
|
77
|
+
)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const guardResult = await runStaffMutationGuards(
|
|
81
|
+
container,
|
|
82
|
+
{
|
|
83
|
+
tenantId,
|
|
84
|
+
organizationId,
|
|
85
|
+
userId: auth.sub ?? '',
|
|
86
|
+
resourceKind: 'staff.timesheets.time_entry',
|
|
87
|
+
resourceId: entry.id,
|
|
88
|
+
operation: 'update',
|
|
89
|
+
requestMethod: req.method,
|
|
90
|
+
requestHeaders: req.headers,
|
|
91
|
+
},
|
|
92
|
+
resolveUserFeatures(auth),
|
|
93
|
+
)
|
|
94
|
+
if (!guardResult.ok) {
|
|
95
|
+
return NextResponse.json(
|
|
96
|
+
guardResult.errorBody ?? { error: 'Operation blocked by guard' },
|
|
97
|
+
{ status: guardResult.errorStatus ?? 422 },
|
|
98
|
+
)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const now = new Date()
|
|
102
|
+
entry.startedAt = now
|
|
103
|
+
entry.source = 'timer'
|
|
104
|
+
|
|
105
|
+
const segmentData = {
|
|
106
|
+
tenantId,
|
|
107
|
+
organizationId,
|
|
108
|
+
timeEntryId: entry.id,
|
|
109
|
+
startedAt: now,
|
|
110
|
+
segmentType: 'work' as const,
|
|
111
|
+
}
|
|
112
|
+
em.create(StaffTimeEntrySegment, segmentData as never)
|
|
113
|
+
|
|
114
|
+
await em.flush()
|
|
115
|
+
|
|
116
|
+
void emitStaffEvent('staff.timesheets.time_entry.timer_started', {
|
|
117
|
+
id: entry.id,
|
|
118
|
+
staffMemberId: entry.staffMemberId,
|
|
119
|
+
tenantId: entry.tenantId,
|
|
120
|
+
organizationId: entry.organizationId,
|
|
121
|
+
startedAt: now.toISOString(),
|
|
122
|
+
}, { persistent: true }).catch((err) => {
|
|
123
|
+
console.error('[staff.timesheets] emit timer_started failed', err)
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
if (guardResult.afterSuccessCallbacks.length) {
|
|
127
|
+
await runStaffMutationGuardAfterSuccess(guardResult.afterSuccessCallbacks, {
|
|
128
|
+
tenantId,
|
|
129
|
+
organizationId,
|
|
130
|
+
userId: auth.sub ?? '',
|
|
131
|
+
resourceKind: 'staff.timesheets.time_entry',
|
|
132
|
+
resourceId: entry.id,
|
|
133
|
+
operation: 'update',
|
|
134
|
+
requestMethod: req.method,
|
|
135
|
+
requestHeaders: req.headers,
|
|
136
|
+
})
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return NextResponse.json({ ok: true }, { status: 200 })
|
|
140
|
+
} catch (err) {
|
|
141
|
+
if (err instanceof CrudHttpError) {
|
|
142
|
+
return NextResponse.json(err.body, { status: err.status })
|
|
143
|
+
}
|
|
144
|
+
const { translate } = await resolveTranslations()
|
|
145
|
+
console.error('staff.timesheets.time-entries.timer-start failed', err)
|
|
146
|
+
return NextResponse.json(
|
|
147
|
+
{ error: translate('staff.timesheets.errors.timerStart', 'Failed to start timer.') },
|
|
148
|
+
{ status: 400 },
|
|
149
|
+
)
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export const openApi: OpenApiRouteDoc = {
|
|
154
|
+
tag: 'Staff',
|
|
155
|
+
summary: 'Start timer for a time entry',
|
|
156
|
+
methods: {
|
|
157
|
+
POST: {
|
|
158
|
+
summary: 'Start timer for a time entry',
|
|
159
|
+
description: 'Starts the timer on a time entry by setting startedAt and creating an initial work segment.',
|
|
160
|
+
responses: [
|
|
161
|
+
{ status: 200, description: 'Timer started', schema: z.object({ ok: z.literal(true) }) },
|
|
162
|
+
{ status: 404, description: 'Time entry not found', schema: z.object({ error: z.string() }) },
|
|
163
|
+
{ status: 409, description: 'Timer already started', schema: z.object({ error: z.string() }) },
|
|
164
|
+
{ status: 401, description: 'Unauthorized', schema: z.object({ error: z.string() }) },
|
|
165
|
+
],
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
}
|