@frigear-nu/shifts 0.0.0-stage → 0.0.1
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/README.md +53 -2
- package/dist/module.d.mts +716 -0
- package/dist/module.json +9 -0
- package/dist/module.mjs +272 -0
- package/dist/runtime/access.d.ts +2 -0
- package/dist/runtime/access.js +84 -0
- package/dist/runtime/app/components/ShiftBroadcastSlideover.d.vue.ts +19 -0
- package/dist/runtime/app/components/ShiftBroadcastSlideover.vue +142 -0
- package/dist/runtime/app/components/ShiftBroadcastSlideover.vue.d.ts +19 -0
- package/dist/runtime/app/components/ShiftBroadcastsCard.d.vue.ts +9 -0
- package/dist/runtime/app/components/ShiftBroadcastsCard.vue +74 -0
- package/dist/runtime/app/components/ShiftBroadcastsCard.vue.d.ts +9 -0
- package/dist/runtime/app/components/ShiftBulkSlideover.d.vue.ts +15 -0
- package/dist/runtime/app/components/ShiftBulkSlideover.vue +185 -0
- package/dist/runtime/app/components/ShiftBulkSlideover.vue.d.ts +15 -0
- package/dist/runtime/app/components/ShiftCheckInCard.d.vue.ts +13 -0
- package/dist/runtime/app/components/ShiftCheckInCard.vue +238 -0
- package/dist/runtime/app/components/ShiftCheckInCard.vue.d.ts +13 -0
- package/dist/runtime/app/components/ShiftCopySlideover.d.vue.ts +11 -0
- package/dist/runtime/app/components/ShiftCopySlideover.vue +71 -0
- package/dist/runtime/app/components/ShiftCopySlideover.vue.d.ts +11 -0
- package/dist/runtime/app/components/ShiftDayView.d.vue.ts +16 -0
- package/dist/runtime/app/components/ShiftDayView.vue +124 -0
- package/dist/runtime/app/components/ShiftDayView.vue.d.ts +16 -0
- package/dist/runtime/app/components/ShiftFeedSlideover.d.vue.ts +7 -0
- package/dist/runtime/app/components/ShiftFeedSlideover.vue +172 -0
- package/dist/runtime/app/components/ShiftFeedSlideover.vue.d.ts +7 -0
- package/dist/runtime/app/components/ShiftNowCard.d.vue.ts +6 -0
- package/dist/runtime/app/components/ShiftNowCard.vue +83 -0
- package/dist/runtime/app/components/ShiftNowCard.vue.d.ts +6 -0
- package/dist/runtime/app/components/ShiftPassFullscreen.d.vue.ts +13 -0
- package/dist/runtime/app/components/ShiftPassFullscreen.vue +79 -0
- package/dist/runtime/app/components/ShiftPassFullscreen.vue.d.ts +13 -0
- package/dist/runtime/app/components/ShiftPerkSlideover.d.vue.ts +14 -0
- package/dist/runtime/app/components/ShiftPerkSlideover.vue +103 -0
- package/dist/runtime/app/components/ShiftPerkSlideover.vue.d.ts +14 -0
- package/dist/runtime/app/components/ShiftPerksCard.d.vue.ts +8 -0
- package/dist/runtime/app/components/ShiftPerksCard.vue +66 -0
- package/dist/runtime/app/components/ShiftPerksCard.vue.d.ts +8 -0
- package/dist/runtime/app/components/ShiftQrScanner.d.vue.ts +10 -0
- package/dist/runtime/app/components/ShiftQrScanner.vue +44 -0
- package/dist/runtime/app/components/ShiftQrScanner.vue.d.ts +10 -0
- package/dist/runtime/app/components/ShiftRoleSlideover.d.vue.ts +15 -0
- package/dist/runtime/app/components/ShiftRoleSlideover.vue +88 -0
- package/dist/runtime/app/components/ShiftRoleSlideover.vue.d.ts +15 -0
- package/dist/runtime/app/components/ShiftScheduleSettingsFields.d.vue.ts +11 -0
- package/dist/runtime/app/components/ShiftScheduleSettingsFields.vue +61 -0
- package/dist/runtime/app/components/ShiftScheduleSettingsFields.vue.d.ts +11 -0
- package/dist/runtime/app/components/ShiftScheduleSlideover.d.vue.ts +12 -0
- package/dist/runtime/app/components/ShiftScheduleSlideover.vue +129 -0
- package/dist/runtime/app/components/ShiftScheduleSlideover.vue.d.ts +12 -0
- package/dist/runtime/app/components/ShiftSlideover.d.vue.ts +13 -0
- package/dist/runtime/app/components/ShiftSlideover.vue +353 -0
- package/dist/runtime/app/components/ShiftSlideover.vue.d.ts +13 -0
- package/dist/runtime/app/components/ShiftStationSlideover.d.vue.ts +15 -0
- package/dist/runtime/app/components/ShiftStationSlideover.vue +92 -0
- package/dist/runtime/app/components/ShiftStationSlideover.vue.d.ts +15 -0
- package/dist/runtime/app/composables/index.d.ts +6 -0
- package/dist/runtime/app/composables/index.js +5 -0
- package/dist/runtime/app/composables/useShiftsActions.d.ts +61 -0
- package/dist/runtime/app/composables/useShiftsActions.js +224 -0
- package/dist/runtime/app/composables/useShiftsFormat.d.ts +12 -0
- package/dist/runtime/app/composables/useShiftsFormat.js +14 -0
- package/dist/runtime/app/composables/useShiftsLinks.d.ts +12 -0
- package/dist/runtime/app/composables/useShiftsLinks.js +6 -0
- package/dist/runtime/app/composables/useShiftsTranslate.d.ts +5 -0
- package/dist/runtime/app/composables/useShiftsTranslate.js +12 -0
- package/dist/runtime/app/composables/useShiftsVenueFeatures.d.ts +17 -0
- package/dist/runtime/app/composables/useShiftsVenueFeatures.js +18 -0
- package/dist/runtime/app/dashboard/NextShift.d.vue.ts +3 -0
- package/dist/runtime/app/dashboard/NextShift.vue +69 -0
- package/dist/runtime/app/dashboard/NextShift.vue.d.ts +3 -0
- package/dist/runtime/app/dashboard/OpenSwaps.d.vue.ts +3 -0
- package/dist/runtime/app/dashboard/OpenSwaps.vue +69 -0
- package/dist/runtime/app/dashboard/OpenSwaps.vue.d.ts +3 -0
- package/dist/runtime/app/dashboard/TeamOnNow.d.vue.ts +3 -0
- package/dist/runtime/app/dashboard/TeamOnNow.vue +72 -0
- package/dist/runtime/app/dashboard/TeamOnNow.vue.d.ts +3 -0
- package/dist/runtime/app/pages/check-in.d.vue.ts +3 -0
- package/dist/runtime/app/pages/check-in.vue +93 -0
- package/dist/runtime/app/pages/check-in.vue.d.ts +3 -0
- package/dist/runtime/app/pages/lead.d.vue.ts +3 -0
- package/dist/runtime/app/pages/lead.vue +300 -0
- package/dist/runtime/app/pages/lead.vue.d.ts +3 -0
- package/dist/runtime/app/pages/shift.d.vue.ts +3 -0
- package/dist/runtime/app/pages/shift.vue +482 -0
- package/dist/runtime/app/pages/shift.vue.d.ts +3 -0
- package/dist/runtime/app/pages/shifts.d.vue.ts +3 -0
- package/dist/runtime/app/pages/shifts.vue +21 -0
- package/dist/runtime/app/pages/shifts.vue.d.ts +3 -0
- package/dist/runtime/app/pages/station.d.vue.ts +3 -0
- package/dist/runtime/app/pages/station.vue +104 -0
- package/dist/runtime/app/pages/station.vue.d.ts +3 -0
- package/dist/runtime/app/pages/swaps.d.vue.ts +3 -0
- package/dist/runtime/app/pages/swaps.vue +32 -0
- package/dist/runtime/app/pages/swaps.vue.d.ts +3 -0
- package/dist/runtime/app/tabs/HomeShifts.d.vue.ts +6 -0
- package/dist/runtime/app/tabs/HomeShifts.vue +194 -0
- package/dist/runtime/app/tabs/HomeShifts.vue.d.ts +6 -0
- package/dist/runtime/app/tabs/HomeSwaps.d.vue.ts +3 -0
- package/dist/runtime/app/tabs/HomeSwaps.vue +188 -0
- package/dist/runtime/app/tabs/HomeSwaps.vue.d.ts +3 -0
- package/dist/runtime/app/tabs/Shifts.d.vue.ts +9 -0
- package/dist/runtime/app/tabs/Shifts.vue +487 -0
- package/dist/runtime/app/tabs/Shifts.vue.d.ts +9 -0
- package/dist/runtime/app/utils/admin-shifts.d.ts +42 -0
- package/dist/runtime/app/utils/admin-shifts.js +36 -0
- package/dist/runtime/dashboard.d.ts +8 -0
- package/dist/runtime/dashboard.js +30 -0
- package/dist/runtime/emails/shifts-broadcast.d.vue.ts +8 -0
- package/dist/runtime/emails/shifts-broadcast.vue +24 -0
- package/dist/runtime/emails/shifts-broadcast.vue.d.ts +8 -0
- package/dist/runtime/emails/shifts-reminder.d.vue.ts +12 -0
- package/dist/runtime/emails/shifts-reminder.vue +34 -0
- package/dist/runtime/emails/shifts-reminder.vue.d.ts +12 -0
- package/dist/runtime/emails/shifts-swap-accepted.d.vue.ts +11 -0
- package/dist/runtime/emails/shifts-swap-accepted.vue +32 -0
- package/dist/runtime/emails/shifts-swap-accepted.vue.d.ts +11 -0
- package/dist/runtime/emails/shifts-swap-completed.d.vue.ts +11 -0
- package/dist/runtime/emails/shifts-swap-completed.vue +32 -0
- package/dist/runtime/emails/shifts-swap-completed.vue.d.ts +11 -0
- package/dist/runtime/emails/shifts-swap-offered.d.vue.ts +11 -0
- package/dist/runtime/emails/shifts-swap-offered.vue +32 -0
- package/dist/runtime/emails/shifts-swap-offered.vue.d.ts +11 -0
- package/dist/runtime/emails/shifts-swap-pending.d.vue.ts +11 -0
- package/dist/runtime/emails/shifts-swap-pending.vue +32 -0
- package/dist/runtime/emails/shifts-swap-pending.vue.d.ts +11 -0
- package/dist/runtime/emails/shifts-swap-proposed.d.vue.ts +11 -0
- package/dist/runtime/emails/shifts-swap-proposed.vue +32 -0
- package/dist/runtime/emails/shifts-swap-proposed.vue.d.ts +11 -0
- package/dist/runtime/emails/shifts-swap-rejected.d.vue.ts +11 -0
- package/dist/runtime/emails/shifts-swap-rejected.vue +32 -0
- package/dist/runtime/emails/shifts-swap-rejected.vue.d.ts +11 -0
- package/dist/runtime/i18n/lang/da.json +627 -0
- package/dist/runtime/i18n/lang/en.json +627 -0
- package/dist/runtime/notifications.d.ts +9 -0
- package/dist/runtime/notifications.js +36 -0
- package/dist/runtime/server/db/schema.postgresql.d.ts +2151 -0
- package/dist/runtime/server/db/schema.postgresql.js +228 -0
- package/dist/runtime/server/db/schema.sqlite.d.ts +2263 -0
- package/dist/runtime/server/db/schema.sqlite.js +228 -0
- package/dist/runtime/server/digest-email.d.ts +17 -0
- package/dist/runtime/server/digest-email.js +42 -0
- package/dist/runtime/server/plugins/station-key.d.ts +2 -0
- package/dist/runtime/server/plugins/station-key.js +5 -0
- package/dist/runtime/server/plugins/teams.d.ts +2 -0
- package/dist/runtime/server/plugins/teams.js +19 -0
- package/dist/runtime/server/policies.d.ts +2 -0
- package/dist/runtime/server/policies.js +41 -0
- package/dist/runtime/server/reminder-email.d.ts +67 -0
- package/dist/runtime/server/reminder-email.js +109 -0
- package/dist/runtime/server/routes/admin/assignment.delete.d.ts +2 -0
- package/dist/runtime/server/routes/admin/assignment.delete.js +10 -0
- package/dist/runtime/server/routes/admin/assignments.post.d.ts +2 -0
- package/dist/runtime/server/routes/admin/assignments.post.js +11 -0
- package/dist/runtime/server/routes/admin/broadcasts.get.d.ts +2 -0
- package/dist/runtime/server/routes/admin/broadcasts.get.js +8 -0
- package/dist/runtime/server/routes/admin/broadcasts.post.d.ts +2 -0
- package/dist/runtime/server/routes/admin/broadcasts.post.js +9 -0
- package/dist/runtime/server/routes/admin/candidates.get.d.ts +2 -0
- package/dist/runtime/server/routes/admin/candidates.get.js +10 -0
- package/dist/runtime/server/routes/admin/operation-teams.get.d.ts +2 -0
- package/dist/runtime/server/routes/admin/operation-teams.get.js +9 -0
- package/dist/runtime/server/routes/admin/perk.delete.d.ts +2 -0
- package/dist/runtime/server/routes/admin/perk.delete.js +10 -0
- package/dist/runtime/server/routes/admin/perk.patch.d.ts +2 -0
- package/dist/runtime/server/routes/admin/perk.patch.js +10 -0
- package/dist/runtime/server/routes/admin/perks.get.d.ts +2 -0
- package/dist/runtime/server/routes/admin/perks.get.js +9 -0
- package/dist/runtime/server/routes/admin/perks.post.d.ts +2 -0
- package/dist/runtime/server/routes/admin/perks.post.js +10 -0
- package/dist/runtime/server/routes/admin/role.delete.d.ts +2 -0
- package/dist/runtime/server/routes/admin/role.delete.js +11 -0
- package/dist/runtime/server/routes/admin/role.patch.d.ts +2 -0
- package/dist/runtime/server/routes/admin/role.patch.js +11 -0
- package/dist/runtime/server/routes/admin/roles.get.d.ts +2 -0
- package/dist/runtime/server/routes/admin/roles.get.js +9 -0
- package/dist/runtime/server/routes/admin/roles.post.d.ts +2 -0
- package/dist/runtime/server/routes/admin/roles.post.js +10 -0
- package/dist/runtime/server/routes/admin/schedule-copy.post.d.ts +2 -0
- package/dist/runtime/server/routes/admin/schedule-copy.post.js +12 -0
- package/dist/runtime/server/routes/admin/schedule-publish.post.d.ts +2 -0
- package/dist/runtime/server/routes/admin/schedule-publish.post.js +9 -0
- package/dist/runtime/server/routes/admin/schedule.delete.d.ts +2 -0
- package/dist/runtime/server/routes/admin/schedule.delete.js +10 -0
- package/dist/runtime/server/routes/admin/schedule.get.d.ts +2 -0
- package/dist/runtime/server/routes/admin/schedule.get.js +9 -0
- package/dist/runtime/server/routes/admin/schedule.patch.d.ts +2 -0
- package/dist/runtime/server/routes/admin/schedule.patch.js +10 -0
- package/dist/runtime/server/routes/admin/schedules.get.d.ts +2 -0
- package/dist/runtime/server/routes/admin/schedules.get.js +10 -0
- package/dist/runtime/server/routes/admin/schedules.post.d.ts +2 -0
- package/dist/runtime/server/routes/admin/schedules.post.js +9 -0
- package/dist/runtime/server/routes/admin/shift.delete.d.ts +2 -0
- package/dist/runtime/server/routes/admin/shift.delete.js +10 -0
- package/dist/runtime/server/routes/admin/shift.patch.d.ts +2 -0
- package/dist/runtime/server/routes/admin/shift.patch.js +10 -0
- package/dist/runtime/server/routes/admin/shifts-bulk.post.d.ts +2 -0
- package/dist/runtime/server/routes/admin/shifts-bulk.post.js +10 -0
- package/dist/runtime/server/routes/admin/shifts.get.d.ts +2 -0
- package/dist/runtime/server/routes/admin/shifts.get.js +10 -0
- package/dist/runtime/server/routes/admin/station.delete.d.ts +2 -0
- package/dist/runtime/server/routes/admin/station.delete.js +11 -0
- package/dist/runtime/server/routes/admin/station.patch.d.ts +2 -0
- package/dist/runtime/server/routes/admin/station.patch.js +11 -0
- package/dist/runtime/server/routes/admin/stations.get.d.ts +2 -0
- package/dist/runtime/server/routes/admin/stations.get.js +9 -0
- package/dist/runtime/server/routes/admin/stations.post.d.ts +2 -0
- package/dist/runtime/server/routes/admin/stations.post.js +10 -0
- package/dist/runtime/server/routes/admin/swap-cancel.post.d.ts +2 -0
- package/dist/runtime/server/routes/admin/swap-cancel.post.js +10 -0
- package/dist/runtime/server/routes/admin/swaps.get.d.ts +2 -0
- package/dist/runtime/server/routes/admin/swaps.get.js +10 -0
- package/dist/runtime/server/routes/feed/feed.get.d.ts +2 -0
- package/dist/runtime/server/routes/feed/feed.get.js +9 -0
- package/dist/runtime/server/routes/lead/attended.post.d.ts +2 -0
- package/dist/runtime/server/routes/lead/attended.post.js +11 -0
- package/dist/runtime/server/routes/lead/broadcast.post.d.ts +2 -0
- package/dist/runtime/server/routes/lead/broadcast.post.js +12 -0
- package/dist/runtime/server/routes/lead/check-in.post.d.ts +2 -0
- package/dist/runtime/server/routes/lead/check-in.post.js +9 -0
- package/dist/runtime/server/routes/lead/exceptions.get.d.ts +2 -0
- package/dist/runtime/server/routes/lead/exceptions.get.js +8 -0
- package/dist/runtime/server/routes/lead/no-show.post.d.ts +2 -0
- package/dist/runtime/server/routes/lead/no-show.post.js +11 -0
- package/dist/runtime/server/routes/lead/now.get.d.ts +2 -0
- package/dist/runtime/server/routes/lead/now.get.js +9 -0
- package/dist/runtime/server/routes/lead/on-duty.get.d.ts +2 -0
- package/dist/runtime/server/routes/lead/on-duty.get.js +10 -0
- package/dist/runtime/server/routes/lead/stations.get.d.ts +2 -0
- package/dist/runtime/server/routes/lead/stations.get.js +8 -0
- package/dist/runtime/server/routes/lead/team-shifts.get.d.ts +2 -0
- package/dist/runtime/server/routes/lead/team-shifts.get.js +9 -0
- package/dist/runtime/server/routes/lead/team-swaps.get.d.ts +2 -0
- package/dist/runtime/server/routes/lead/team-swaps.get.js +9 -0
- package/dist/runtime/server/routes/me/check-in.post.d.ts +2 -0
- package/dist/runtime/server/routes/me/check-in.post.js +11 -0
- package/dist/runtime/server/routes/me/earned-perk-claim.post.d.ts +2 -0
- package/dist/runtime/server/routes/me/earned-perk-claim.post.js +10 -0
- package/dist/runtime/server/routes/me/earned-perks.get.d.ts +2 -0
- package/dist/runtime/server/routes/me/earned-perks.get.js +9 -0
- package/dist/runtime/server/routes/me/feed-token.delete.d.ts +2 -0
- package/dist/runtime/server/routes/me/feed-token.delete.js +7 -0
- package/dist/runtime/server/routes/me/feed-token.get.d.ts +2 -0
- package/dist/runtime/server/routes/me/feed-token.get.js +6 -0
- package/dist/runtime/server/routes/me/feed-token.post.d.ts +2 -0
- package/dist/runtime/server/routes/me/feed-token.post.js +7 -0
- package/dist/runtime/server/routes/me/leads.get.d.ts +2 -0
- package/dist/runtime/server/routes/me/leads.get.js +5 -0
- package/dist/runtime/server/routes/me/now.get.d.ts +2 -0
- package/dist/runtime/server/routes/me/now.get.js +5 -0
- package/dist/runtime/server/routes/me/pass.get.d.ts +2 -0
- package/dist/runtime/server/routes/me/pass.get.js +11 -0
- package/dist/runtime/server/routes/me/settle.post.d.ts +2 -0
- package/dist/runtime/server/routes/me/settle.post.js +14 -0
- package/dist/runtime/server/routes/me/shift.get.d.ts +2 -0
- package/dist/runtime/server/routes/me/shift.get.js +10 -0
- package/dist/runtime/server/routes/me/shifts.get.d.ts +2 -0
- package/dist/runtime/server/routes/me/shifts.get.js +6 -0
- package/dist/runtime/server/routes/me/swap.delete.d.ts +2 -0
- package/dist/runtime/server/routes/me/swap.delete.js +11 -0
- package/dist/runtime/server/routes/me/swap.post.d.ts +2 -0
- package/dist/runtime/server/routes/me/swap.post.js +11 -0
- package/dist/runtime/server/routes/stations/token.get.d.ts +2 -0
- package/dist/runtime/server/routes/stations/token.get.js +12 -0
- package/dist/runtime/server/routes/swaps/approve.post.d.ts +2 -0
- package/dist/runtime/server/routes/swaps/approve.post.js +9 -0
- package/dist/runtime/server/routes/swaps/list.get.d.ts +2 -0
- package/dist/runtime/server/routes/swaps/list.get.js +5 -0
- package/dist/runtime/server/routes/swaps/offer-accept.post.d.ts +2 -0
- package/dist/runtime/server/routes/swaps/offer-accept.post.js +9 -0
- package/dist/runtime/server/routes/swaps/offer-reject.post.d.ts +2 -0
- package/dist/runtime/server/routes/swaps/offer-reject.post.js +9 -0
- package/dist/runtime/server/routes/swaps/offer.delete.d.ts +2 -0
- package/dist/runtime/server/routes/swaps/offer.delete.js +11 -0
- package/dist/runtime/server/routes/swaps/offer.post.d.ts +2 -0
- package/dist/runtime/server/routes/swaps/offer.post.js +11 -0
- package/dist/runtime/server/routes/swaps/reject.post.d.ts +2 -0
- package/dist/runtime/server/routes/swaps/reject.post.js +9 -0
- package/dist/runtime/server/swap-email.d.ts +28 -0
- package/dist/runtime/server/swap-email.js +49 -0
- package/dist/runtime/server/tasks/close-shifts.d.ts +2 -0
- package/dist/runtime/server/tasks/close-shifts.js +9 -0
- package/dist/runtime/server/tasks/send-reminders.d.ts +2 -0
- package/dist/runtime/server/tasks/send-reminders.js +9 -0
- package/dist/runtime/server/utils/shifts-admin.d.ts +67 -0
- package/dist/runtime/server/utils/shifts-admin.js +312 -0
- package/dist/runtime/server/utils/shifts-assign.d.ts +89 -0
- package/dist/runtime/server/utils/shifts-assign.js +264 -0
- package/dist/runtime/server/utils/shifts-automation.d.ts +37 -0
- package/dist/runtime/server/utils/shifts-automation.js +171 -0
- package/dist/runtime/server/utils/shifts-broadcasts.d.ts +38 -0
- package/dist/runtime/server/utils/shifts-broadcasts.js +113 -0
- package/dist/runtime/server/utils/shifts-core.d.ts +78 -0
- package/dist/runtime/server/utils/shifts-core.js +142 -0
- package/dist/runtime/server/utils/shifts-dto.d.ts +32 -0
- package/dist/runtime/server/utils/shifts-dto.js +127 -0
- package/dist/runtime/server/utils/shifts-emails.d.ts +16 -0
- package/dist/runtime/server/utils/shifts-emails.js +44 -0
- package/dist/runtime/server/utils/shifts-exceptions.d.ts +7 -0
- package/dist/runtime/server/utils/shifts-exceptions.js +32 -0
- package/dist/runtime/server/utils/shifts-feed.d.ts +16 -0
- package/dist/runtime/server/utils/shifts-feed.js +73 -0
- package/dist/runtime/server/utils/shifts-notify.d.ts +40 -0
- package/dist/runtime/server/utils/shifts-notify.js +22 -0
- package/dist/runtime/server/utils/shifts-on-duty.d.ts +12 -0
- package/dist/runtime/server/utils/shifts-on-duty.js +37 -0
- package/dist/runtime/server/utils/shifts-perks.d.ts +46 -0
- package/dist/runtime/server/utils/shifts-perks.js +183 -0
- package/dist/runtime/server/utils/shifts-reminders.d.ts +30 -0
- package/dist/runtime/server/utils/shifts-reminders.js +102 -0
- package/dist/runtime/server/utils/shifts-schemas.d.ts +318 -0
- package/dist/runtime/server/utils/shifts-schemas.js +177 -0
- package/dist/runtime/server/utils/shifts-station-key.d.ts +7 -0
- package/dist/runtime/server/utils/shifts-station-key.js +22 -0
- package/dist/runtime/server/utils/shifts-stations.d.ts +28 -0
- package/dist/runtime/server/utils/shifts-stations.js +109 -0
- package/dist/runtime/server/utils/shifts-swaps.d.ts +114 -0
- package/dist/runtime/server/utils/shifts-swaps.js +559 -0
- package/dist/runtime/server/utils/shifts-views.d.ts +62 -0
- package/dist/runtime/server/utils/shifts-views.js +212 -0
- package/dist/runtime/utils/api.d.ts +108 -0
- package/dist/runtime/utils/api.js +111 -0
- package/dist/runtime/utils/checkin.d.ts +59 -0
- package/dist/runtime/utils/checkin.js +57 -0
- package/dist/runtime/utils/guards.d.ts +21 -0
- package/dist/runtime/utils/guards.js +36 -0
- package/dist/runtime/utils/ics.d.ts +32 -0
- package/dist/runtime/utils/ics.js +56 -0
- package/dist/runtime/utils/index.d.ts +16 -0
- package/dist/runtime/utils/index.js +15 -0
- package/dist/runtime/utils/links.d.ts +44 -0
- package/dist/runtime/utils/links.js +21 -0
- package/dist/runtime/utils/reminders.d.ts +27 -0
- package/dist/runtime/utils/reminders.js +28 -0
- package/dist/runtime/utils/settings.d.ts +28 -0
- package/dist/runtime/utils/settings.js +18 -0
- package/dist/runtime/utils/station-key.d.ts +9 -0
- package/dist/runtime/utils/station-key.js +12 -0
- package/dist/runtime/utils/status.d.ts +23 -0
- package/dist/runtime/utils/status.js +46 -0
- package/dist/runtime/utils/time.d.ts +22 -0
- package/dist/runtime/utils/time.js +14 -0
- package/dist/types.d.mts +5 -0
- package/package.json +131 -3
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { db, schema } from "@nuxthub/db";
|
|
2
|
+
import { and, asc, eq, gt, gte, inArray, lt, lte, ne } from "drizzle-orm";
|
|
3
|
+
import { renderSVG } from "uqr";
|
|
4
|
+
import { inChunks } from "@frigear-nu/module-kit/server";
|
|
5
|
+
import { shiftsAccess } from "../../access.js";
|
|
6
|
+
import { scheduleSettingsOf } from "../../utils/settings.js";
|
|
7
|
+
import { ACTIVE_ASSIGNMENT_STATUSES } from "../../utils/status.js";
|
|
8
|
+
import { toShiftAssignmentDto, toShiftDto, toShiftPersonDto } from "./shifts-dto.js";
|
|
9
|
+
import { shiftsActiveAssignmentOf, shiftsEligibility, shiftsGuardWarningsFor, shiftsRoleById, shiftsRoleOfOr400, shiftsTeamsById, shiftsUsersById } from "./shifts-core.js";
|
|
10
|
+
import { shiftsCheckInOpen, shiftsPassWindow, shiftsStillEligible } from "./shifts-assign.js";
|
|
11
|
+
import { shiftsPassPerks } from "./shifts-perks.js";
|
|
12
|
+
import { shiftsStationKeyConfigured } from "./shifts-station-key.js";
|
|
13
|
+
import { checkInRuleFor } from "../../utils/checkin.js";
|
|
14
|
+
import { shiftsWithAssignees } from "./shifts-admin.js";
|
|
15
|
+
import { findLiveShiftSwapOf, shiftsSwapDtos } from "./shifts-swaps.js";
|
|
16
|
+
export async function shiftsMyShifts(userId, range = {}) {
|
|
17
|
+
const rows = await db.select({ assignment: schema.shiftAssignments, shift: schema.shifts, schedule: schema.shiftSchedules }).from(schema.shiftAssignments).innerJoin(schema.shifts, eq(schema.shifts.id, schema.shiftAssignments.shiftId)).innerJoin(schema.shiftSchedules, eq(schema.shiftSchedules.id, schema.shifts.scheduleId)).where(and(
|
|
18
|
+
eq(schema.shiftAssignments.userId, userId),
|
|
19
|
+
ne(schema.shiftAssignments.status, "cancelled"),
|
|
20
|
+
eq(schema.shiftSchedules.status, "published"),
|
|
21
|
+
range.from ? gt(schema.shifts.endsAt, range.from) : void 0,
|
|
22
|
+
range.to ? lt(schema.shifts.startsAt, range.to) : void 0
|
|
23
|
+
)).orderBy(asc(schema.shifts.startsAt), asc(schema.shiftAssignments.id)).limit(1e3);
|
|
24
|
+
return shiftsMyShiftDtos(rows);
|
|
25
|
+
}
|
|
26
|
+
export async function shiftsMyShiftDtos(rows) {
|
|
27
|
+
if (!rows.length) return [];
|
|
28
|
+
const operationIds = [...new Set(rows.map((row) => row.schedule.operationId))];
|
|
29
|
+
const roleIds = [...new Set(rows.flatMap((row) => row.assignment.shiftRoleId ? [row.assignment.shiftRoleId] : []))];
|
|
30
|
+
const [operations, roles, teams, swaps] = await Promise.all([
|
|
31
|
+
inChunks(operationIds, (part) => db.select({ id: schema.operations.id, name: schema.operations.name }).from(schema.operations).where(inArray(schema.operations.id, part))),
|
|
32
|
+
inChunks(roleIds, (part) => db.select().from(schema.shiftRoles).where(inArray(schema.shiftRoles.id, part))),
|
|
33
|
+
shiftsTeamsById(rows.map((row) => row.shift.teamId)),
|
|
34
|
+
inChunks(rows.map((row) => row.assignment.id), (part) => db.select().from(schema.shiftSwaps).where(and(
|
|
35
|
+
inArray(schema.shiftSwaps.assignmentId, part),
|
|
36
|
+
inArray(schema.shiftSwaps.status, ["open", "offered", "accepted", "pending_approval"])
|
|
37
|
+
)))
|
|
38
|
+
]);
|
|
39
|
+
return rows.map(({ assignment, shift, schedule }) => {
|
|
40
|
+
const swap = swaps.find((item) => item.assignmentId === assignment.id);
|
|
41
|
+
return {
|
|
42
|
+
assignment: toShiftAssignmentDto(assignment),
|
|
43
|
+
shift: toShiftDto(shift, schedule),
|
|
44
|
+
operationId: schedule.operationId,
|
|
45
|
+
operationName: operations.find((item) => item.id === schedule.operationId)?.name ?? schedule.operationId,
|
|
46
|
+
scheduleName: schedule.name,
|
|
47
|
+
teamName: teams.get(shift.teamId)?.name ?? shift.teamId,
|
|
48
|
+
roleName: roles.find((role) => role.id === assignment.shiftRoleId)?.name ?? null,
|
|
49
|
+
swap: swap ? { id: swap.id, status: swap.status, kind: swap.kind } : null,
|
|
50
|
+
settings: scheduleSettingsOf(schedule)
|
|
51
|
+
};
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
export async function shiftsLeadsOnDuty(event, teamId, startsAt, endsAt, exclude) {
|
|
55
|
+
const rows = await db.select({ userId: schema.shiftAssignments.userId }).from(schema.shiftAssignments).innerJoin(schema.shifts, eq(schema.shifts.id, schema.shiftAssignments.shiftId)).innerJoin(schema.shiftSchedules, eq(schema.shiftSchedules.id, schema.shifts.scheduleId)).where(and(
|
|
56
|
+
eq(schema.shifts.teamId, teamId),
|
|
57
|
+
eq(schema.shiftSchedules.status, "published"),
|
|
58
|
+
inArray(schema.shiftAssignments.status, [...ACTIVE_ASSIGNMENT_STATUSES]),
|
|
59
|
+
lt(schema.shifts.startsAt, endsAt),
|
|
60
|
+
gt(schema.shifts.endsAt, startsAt)
|
|
61
|
+
));
|
|
62
|
+
const ids = [...new Set(rows.map((row) => row.userId))].filter((id) => id !== exclude);
|
|
63
|
+
const leads = [];
|
|
64
|
+
for (const id of ids) if (await isTeamLead(event, id, teamId)) leads.push(id);
|
|
65
|
+
const users = await shiftsUsersById(leads);
|
|
66
|
+
return leads.map((id) => toShiftPersonDto(id, users.get(id), false));
|
|
67
|
+
}
|
|
68
|
+
export async function shiftsMyShiftDetail(event, entry) {
|
|
69
|
+
const [base] = await shiftsMyShiftDtos([entry]);
|
|
70
|
+
const swap = await findLiveShiftSwapOf(entry.assignment.id);
|
|
71
|
+
const [swapDetail] = swap ? await shiftsSwapDtos([swap], { offers: true }) : [];
|
|
72
|
+
const { opensAt, closesAt } = shiftsPassWindow(event, entry.shift);
|
|
73
|
+
return {
|
|
74
|
+
...base,
|
|
75
|
+
leadsOnDuty: await shiftsLeadsOnDuty(event, entry.shift.teamId, entry.shift.startsAt, entry.shift.endsAt, entry.assignment.userId),
|
|
76
|
+
swapDetail: swapDetail ?? null,
|
|
77
|
+
passOpensAt: opensAt.toISOString(),
|
|
78
|
+
passClosesAt: closesAt.toISOString()
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
export function shiftsPassOf(event, entry) {
|
|
82
|
+
const { opensAt, closesAt } = shiftsPassWindow(event, entry.shift);
|
|
83
|
+
const available = (entry.assignment.status === "assigned" || entry.assignment.status === "attended") && shiftsCheckInOpen(event, entry.shift);
|
|
84
|
+
return {
|
|
85
|
+
assignmentId: entry.assignment.id,
|
|
86
|
+
available,
|
|
87
|
+
opensAt: opensAt.toISOString(),
|
|
88
|
+
closesAt: closesAt.toISOString(),
|
|
89
|
+
code: available ? entry.assignment.checkInCode : null,
|
|
90
|
+
svg: available ? renderSVG(entry.assignment.checkInCode, { border: 1 }) : null
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
export async function shiftsPassDto(event, entry) {
|
|
94
|
+
const rule = checkInRuleFor(entry.schedule.checkIn, entry.shift.teamId);
|
|
95
|
+
const checkIn = shiftsStationKeyConfigured(event) ? rule : { ...rule, modes: rule.modes.filter((mode) => mode !== "station") };
|
|
96
|
+
const pass = { ...shiftsPassOf(event, entry), checkIn, eligible: true };
|
|
97
|
+
if (pass.available && !await shiftsStillEligible(event, entry.assignment, entry.shift.teamId)) {
|
|
98
|
+
return { ...pass, available: false, eligible: false, code: null, svg: null, perks: [] };
|
|
99
|
+
}
|
|
100
|
+
return { ...pass, perks: entry.assignment.status === "cancelled" ? [] : await shiftsPassPerks(entry) };
|
|
101
|
+
}
|
|
102
|
+
export async function shiftsTeamShifts(teamId, range, pii) {
|
|
103
|
+
const rows = await db.select({ shift: schema.shifts, schedule: schema.shiftSchedules }).from(schema.shifts).innerJoin(schema.shiftSchedules, eq(schema.shiftSchedules.id, schema.shifts.scheduleId)).where(and(
|
|
104
|
+
eq(schema.shifts.teamId, teamId),
|
|
105
|
+
eq(schema.shiftSchedules.status, "published"),
|
|
106
|
+
range.from ? gt(schema.shifts.endsAt, range.from) : void 0,
|
|
107
|
+
range.to ? lt(schema.shifts.startsAt, range.to) : void 0
|
|
108
|
+
)).orderBy(asc(schema.shifts.startsAt), asc(schema.shifts.id)).limit(1e3);
|
|
109
|
+
const schedules = new Map(rows.map((row) => [row.schedule.id, row.schedule]));
|
|
110
|
+
return shiftsWithAssignees(rows.map((row) => row.shift), schedules, pii);
|
|
111
|
+
}
|
|
112
|
+
export async function shiftsNow(event, operationId, pii, at = /* @__PURE__ */ new Date(), teamIds) {
|
|
113
|
+
const inQuery = teamIds && teamIds.length <= 50;
|
|
114
|
+
const rows = await db.select({ shift: schema.shifts, schedule: schema.shiftSchedules }).from(schema.shifts).innerJoin(schema.shiftSchedules, eq(schema.shiftSchedules.id, schema.shifts.scheduleId)).where(and(
|
|
115
|
+
eq(schema.shiftSchedules.operationId, operationId),
|
|
116
|
+
eq(schema.shiftSchedules.status, "published"),
|
|
117
|
+
lte(schema.shifts.startsAt, at),
|
|
118
|
+
gte(schema.shifts.endsAt, at),
|
|
119
|
+
inQuery ? inArray(schema.shifts.teamId, teamIds) : void 0
|
|
120
|
+
)).orderBy(asc(schema.shifts.startsAt), asc(schema.shifts.id)).limit(1e3);
|
|
121
|
+
if (teamIds && !inQuery) rows.splice(0, rows.length, ...rows.filter((row) => teamIds.includes(row.shift.teamId)));
|
|
122
|
+
const schedules = new Map(rows.map((row) => [row.schedule.id, row.schedule]));
|
|
123
|
+
const shifts = await shiftsWithAssignees(rows.map((row) => row.shift), schedules, pii);
|
|
124
|
+
const teams = await shiftsTeamsById(shifts.map((shift) => shift.teamId));
|
|
125
|
+
const byTeam = /* @__PURE__ */ new Map();
|
|
126
|
+
for (const shift of shifts) {
|
|
127
|
+
let team = byTeam.get(shift.teamId);
|
|
128
|
+
if (!team) byTeam.set(shift.teamId, team = { teamId: shift.teamId, teamName: teams.get(shift.teamId)?.name ?? shift.teamId, leads: [], shifts: [] });
|
|
129
|
+
const assignees = shift.assignees.filter((item) => item.status === "assigned" || item.status === "attended");
|
|
130
|
+
const { teamName: _teamName, filled: _filled, ...rest } = shift;
|
|
131
|
+
team.shifts.push({ ...rest, assignees });
|
|
132
|
+
for (const assignee of assignees) {
|
|
133
|
+
if (team.leads.some((lead) => lead.userId === assignee.userId)) continue;
|
|
134
|
+
if (await isTeamLead(event, assignee.userId, shift.teamId)) team.leads.push(assignee.person);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return { operationId, at: at.toISOString(), teams: [...byTeam.values()] };
|
|
138
|
+
}
|
|
139
|
+
export async function shiftsMyNow(event, userId, at = /* @__PURE__ */ new Date()) {
|
|
140
|
+
const grants = (await resolveAllTeamRoles(event, userId)).filter((grant) => grant.ownerType === "operation" && grant.ownerId);
|
|
141
|
+
if (!grants.length) return { at: at.toISOString(), teams: [] };
|
|
142
|
+
const myTeamIds = new Set(grants.map((grant) => grant.teamId));
|
|
143
|
+
const operationIds = [...new Set(grants.map((grant) => grant.ownerId))];
|
|
144
|
+
const operations = await db.select({ id: schema.operations.id, name: schema.operations.name }).from(schema.operations).where(inArray(schema.operations.id, operationIds));
|
|
145
|
+
const names = new Map(operations.map((operation) => [operation.id, operation.name]));
|
|
146
|
+
const teams = [];
|
|
147
|
+
for (const operationId of operationIds) {
|
|
148
|
+
if (!names.has(operationId)) continue;
|
|
149
|
+
if (!await allows(event, shiftsAccess.permissions.read, { operationId })) continue;
|
|
150
|
+
const now = await shiftsNow(event, operationId, false, at, [...myTeamIds]);
|
|
151
|
+
for (const team of now.teams) {
|
|
152
|
+
const people = /* @__PURE__ */ new Map();
|
|
153
|
+
for (const shift of team.shifts) for (const assignee of shift.assignees) people.set(assignee.userId, assignee.person);
|
|
154
|
+
teams.push({ operationId, operationName: names.get(operationId), teamId: team.teamId, teamName: team.teamName, leads: team.leads, people: [...people.values()] });
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return { at: at.toISOString(), teams };
|
|
158
|
+
}
|
|
159
|
+
export async function shiftsCandidates(event, entry, q, pii, shiftRoleId) {
|
|
160
|
+
const { shift, schedule } = entry;
|
|
161
|
+
const members = await db.select({ userId: schema.teamMembers.userId, role: schema.teamMembers.role, status: schema.teamMembers.status }).from(schema.teamMembers).where(eq(schema.teamMembers.teamId, shift.teamId)).limit(1e3);
|
|
162
|
+
const holding = members.filter((member) => teamMemberStatusGrants(member.status));
|
|
163
|
+
const users = await shiftsUsersById(holding.map((member) => member.userId));
|
|
164
|
+
const needle = q?.toLowerCase();
|
|
165
|
+
const role = shiftRoleId ? await shiftsRoleOfOr400(schedule.id, shift.teamId, shiftRoleId) : await shiftsRoleById(shift.shiftRoleId);
|
|
166
|
+
const result = [];
|
|
167
|
+
for (const member of holding) {
|
|
168
|
+
const user = users.get(member.userId);
|
|
169
|
+
if (needle && !(user?.name ?? "").toLowerCase().includes(needle) && !(pii && (user?.email ?? "").toLowerCase().includes(needle))) continue;
|
|
170
|
+
const eligibility = await shiftsEligibility(event, member.userId, shift.teamId, role);
|
|
171
|
+
const assigned = !!await shiftsActiveAssignmentOf(shift.id, member.userId);
|
|
172
|
+
result.push({
|
|
173
|
+
...toShiftPersonDto(member.userId, user, pii),
|
|
174
|
+
role: eligibility.role ?? member.role,
|
|
175
|
+
eligible: eligibility.eligible && !assigned,
|
|
176
|
+
reason: assigned ? "assigned" : eligibility.reason === "role" ? "role" : null,
|
|
177
|
+
warnings: assigned ? [] : await shiftsGuardWarningsFor(event, member.userId, entry)
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
return result.sort((a, b) => Number(b.eligible) - Number(a.eligible) || (a.name ?? "").localeCompare(b.name ?? ""));
|
|
181
|
+
}
|
|
182
|
+
export async function shiftsLedTeams(event, userId) {
|
|
183
|
+
const grants = (await resolveAllTeamRoles(event, userId)).filter((grant) => grant.ownerType === "operation" && grant.ownerId);
|
|
184
|
+
const led = [];
|
|
185
|
+
for (const grant of grants) if (await isTeamLead(event, userId, grant.teamId)) led.push(grant);
|
|
186
|
+
if (!led.length) return [];
|
|
187
|
+
const [teams, operations] = await Promise.all([
|
|
188
|
+
shiftsTeamsById(led.map((grant) => grant.teamId)),
|
|
189
|
+
db.select({ id: schema.operations.id, name: schema.operations.name }).from(schema.operations).where(inArray(schema.operations.id, led.map((grant) => grant.ownerId)))
|
|
190
|
+
]);
|
|
191
|
+
return led.map((grant) => ({
|
|
192
|
+
teamId: grant.teamId,
|
|
193
|
+
teamName: teams.get(grant.teamId)?.name ?? grant.teamId,
|
|
194
|
+
operationId: grant.ownerId,
|
|
195
|
+
operationName: operations.find((item) => item.id === grant.ownerId)?.name ?? grant.ownerId
|
|
196
|
+
}));
|
|
197
|
+
}
|
|
198
|
+
export async function shiftsOperationTeams(event, operationId) {
|
|
199
|
+
const [rows, ladders] = await Promise.all([
|
|
200
|
+
db.select().from(schema.teams).where(and(eq(schema.teams.ownerType, "operation"), eq(schema.teams.ownerId, operationId))).orderBy(asc(schema.teams.sort), asc(schema.teams.createdAt), asc(schema.teams.id)),
|
|
201
|
+
loadTeamLadders(event)
|
|
202
|
+
]);
|
|
203
|
+
return rows.map((team) => {
|
|
204
|
+
const ladder = ladders[team.kind];
|
|
205
|
+
return {
|
|
206
|
+
id: team.id,
|
|
207
|
+
kind: team.kind,
|
|
208
|
+
name: team.name,
|
|
209
|
+
ladder: ladder ? { roles: ladder.roles.map((role) => ({ key: role.key, label: role.label })), leadFrom: ladder.leadFrom ?? null } : null
|
|
210
|
+
};
|
|
211
|
+
});
|
|
212
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
export declare const shiftsApi: {
|
|
2
|
+
readonly me: {
|
|
3
|
+
/** `GET` my shifts in published schedules (`?from&to`, ISO instants). */
|
|
4
|
+
readonly shifts: "/api/shifts/me";
|
|
5
|
+
/** `GET` one of my shifts: the shift, the lead on duty and my swap. */
|
|
6
|
+
readonly shift: (assignmentId: string) => string;
|
|
7
|
+
/** `GET` the QR pass of one of my shifts (the code only while check-in is open). */
|
|
8
|
+
readonly pass: (assignmentId: string) => string;
|
|
9
|
+
/** `POST` after a pass said `eligible: false`: cancels my future shifts on the team my role no longer meets, answers the pass. */
|
|
10
|
+
readonly settle: (assignmentId: string) => string;
|
|
11
|
+
/** `POST` `{ mode: 'station', token }` or `{ mode: 'location', latitude, longitude, accuracy }` to check in on one of my shifts myself. */
|
|
12
|
+
readonly checkIn: (assignmentId: string) => string;
|
|
13
|
+
/** `GET` (`?status=unclaimed|claimed|all`) the perks I earned (`perks:read`). */
|
|
14
|
+
readonly earnedPerks: "/api/shifts/me/earned-perks";
|
|
15
|
+
/** `POST` `{ client? }` to claim one of my earned perks, idempotently (`perks:claim`). */
|
|
16
|
+
readonly claimEarnedPerk: (earnedPerkId: string) => string;
|
|
17
|
+
/** `POST` to open a swap of one of my shifts, `DELETE` to withdraw it. */
|
|
18
|
+
readonly swap: (assignmentId: string) => string;
|
|
19
|
+
/** `GET` the teams I work on that have a shift running now, with who is on it. */
|
|
20
|
+
readonly now: "/api/shifts/me/now";
|
|
21
|
+
/** `GET` the teams I lead. */
|
|
22
|
+
readonly leads: "/api/shifts/me/leads";
|
|
23
|
+
/** `GET` whether I have a calendar feed, `POST` to mint one (shown once, revokes the old one), `DELETE` to revoke it. Session only. */
|
|
24
|
+
readonly feedToken: "/api/shifts/me/feed-token";
|
|
25
|
+
};
|
|
26
|
+
/** `GET` a person's shifts as an iCal feed; the secret token is the credential (`.ics` suffix optional). Public. */
|
|
27
|
+
readonly feed: (token: string) => string;
|
|
28
|
+
/** `GET` the open swaps I can take. */
|
|
29
|
+
readonly swaps: "/api/shifts/swaps";
|
|
30
|
+
/** `POST` `{ assignmentId? }` to offer to take a swap (optionally giving one of my shifts back). */
|
|
31
|
+
readonly offers: (swapId: string) => string;
|
|
32
|
+
/** `DELETE` to withdraw my offer. */
|
|
33
|
+
readonly offer: (swapId: string, offerId: string) => string;
|
|
34
|
+
/** `POST` (the swap's owner) to accept an offer. */
|
|
35
|
+
readonly acceptOffer: (swapId: string, offerId: string) => string;
|
|
36
|
+
/** `POST` (the swap's owner) to reject an offer. */
|
|
37
|
+
readonly rejectOffer: (swapId: string, offerId: string) => string;
|
|
38
|
+
/** `POST` (a lead of the team, or staff) to approve a swap waiting for approval. */
|
|
39
|
+
readonly approveSwap: (swapId: string) => string;
|
|
40
|
+
/** `POST` (a lead of the team, or staff) to reject a swap waiting for approval: it is open again. */
|
|
41
|
+
readonly rejectSwap: (swapId: string) => string;
|
|
42
|
+
readonly teams: {
|
|
43
|
+
/** `POST` `{ code }` to check a person in with their QR pass (a lead of the team, or staff). */
|
|
44
|
+
readonly checkIn: (teamId: string) => string;
|
|
45
|
+
/** `GET` (`?from&to`) the team's shifts in published schedules with who works them (a lead of the team, or staff). */
|
|
46
|
+
readonly shifts: (teamId: string) => string;
|
|
47
|
+
/** `GET` (`?status`) the team's swaps, e.g. those waiting for approval (a lead of the team, or staff). */
|
|
48
|
+
readonly swaps: (teamId: string) => string;
|
|
49
|
+
/** `POST` `{ audience?, channels?, subject, message }` to message the team (a lead of it, or staff). Email unless `channels` adds `sms`. */
|
|
50
|
+
readonly broadcasts: (teamId: string) => string;
|
|
51
|
+
/** `GET` the exceptions of the team's recent shifts: no-shows, late, not checked in (a lead of the team, or staff). */
|
|
52
|
+
readonly exceptions: (teamId: string) => string;
|
|
53
|
+
/** `GET` the team's check-in stations on published schedules (a lead of the team, or staff). */
|
|
54
|
+
readonly stations: (teamId: string) => string;
|
|
55
|
+
};
|
|
56
|
+
/** `GET` the current rotating QR code of a check-in station (a lead of its team, or staff). */
|
|
57
|
+
readonly stationToken: (stationId: string) => string;
|
|
58
|
+
/** `POST` to mark an assignment attended (a lead of the team, or staff). */
|
|
59
|
+
readonly attended: (assignmentId: string) => string;
|
|
60
|
+
/** `POST` to mark an assignment a no-show (a lead of the team, or staff). */
|
|
61
|
+
readonly noShow: (assignmentId: string) => string;
|
|
62
|
+
/** `GET` who is on shift now in an operation, and the leads on duty per team. */
|
|
63
|
+
readonly now: (operationId: string) => string;
|
|
64
|
+
/** `GET` the `shifts.on-duty` live layer: GeoJSON points on the operation's venue layout, a team per shift location. */
|
|
65
|
+
readonly onDuty: (operationId: string) => string;
|
|
66
|
+
readonly admin: {
|
|
67
|
+
/** `GET` (`?operationId`) / `POST` schedules. */
|
|
68
|
+
readonly schedules: "/api/admin/shifts/schedules";
|
|
69
|
+
/** `GET` / `PATCH` / `DELETE` one schedule. */
|
|
70
|
+
readonly schedule: (scheduleId: string) => string;
|
|
71
|
+
/** `POST` to publish a draft schedule. */
|
|
72
|
+
readonly publish: (scheduleId: string) => string;
|
|
73
|
+
/** `POST` `{ scheduleId, offsetDays }` to copy another schedule's roles and shifts into this one. */
|
|
74
|
+
readonly copyFrom: (scheduleId: string) => string;
|
|
75
|
+
/** `GET` / `POST` a schedule's shift roles. */
|
|
76
|
+
readonly roles: (scheduleId: string) => string;
|
|
77
|
+
/** `GET` / `POST` a schedule's check-in stations. */
|
|
78
|
+
readonly stations: (scheduleId: string) => string;
|
|
79
|
+
/** `PATCH` / `DELETE` one check-in station. */
|
|
80
|
+
readonly station: (stationId: string) => string;
|
|
81
|
+
/** `PATCH` / `DELETE` one shift role. */
|
|
82
|
+
readonly role: (roleId: string) => string;
|
|
83
|
+
/** `GET` (`?teamId&from&to`) a schedule's shifts with their assignments. */
|
|
84
|
+
readonly shifts: (scheduleId: string) => string;
|
|
85
|
+
/** `POST` `{ teamId, days, slots, capacity?, shiftRoleId? }` to create shifts in bulk. */
|
|
86
|
+
readonly bulk: (scheduleId: string) => string;
|
|
87
|
+
/** `PATCH` / `DELETE` one shift. */
|
|
88
|
+
readonly shift: (shiftId: string) => string;
|
|
89
|
+
/** `POST` `{ userId, shiftRoleId?, force? }` to assign a person to a shift. */
|
|
90
|
+
readonly assignments: (shiftId: string) => string;
|
|
91
|
+
/** `GET` (`?q`) the people of the shift's team staff could assign, with the guards they would break. */
|
|
92
|
+
readonly candidates: (shiftId: string) => string;
|
|
93
|
+
/** `DELETE` to cancel an assignment. */
|
|
94
|
+
readonly assignment: (assignmentId: string) => string;
|
|
95
|
+
/** `GET` (`?operationId&status`) swaps, for staff. */
|
|
96
|
+
readonly swaps: "/api/admin/shifts/swaps";
|
|
97
|
+
/** `POST` to cancel a live swap, settling one stuck while being carried out. */
|
|
98
|
+
readonly cancelSwap: (swapId: string) => string;
|
|
99
|
+
/** `GET` an operation's teams with their kind's ladder. */
|
|
100
|
+
readonly teams: (operationId: string) => string;
|
|
101
|
+
/** `GET` (`?operationId`) the broadcasts of an operation, `POST` `{ operationId, audience, channels, subject, message }` to send one (`shifts:broadcast`). */
|
|
102
|
+
readonly broadcasts: "/api/admin/shifts/broadcasts";
|
|
103
|
+
/** `GET` / `POST` an operation's perks (what an attended shift earns). */
|
|
104
|
+
readonly perks: (operationId: string) => string;
|
|
105
|
+
/** `PATCH` / `DELETE` one perk. */
|
|
106
|
+
readonly perk: (perkId: string) => string;
|
|
107
|
+
};
|
|
108
|
+
};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
const enc = encodeURIComponent;
|
|
2
|
+
const BASE = "/api/shifts";
|
|
3
|
+
const ADMIN_BASE = "/api/admin/shifts";
|
|
4
|
+
export const shiftsApi = {
|
|
5
|
+
me: {
|
|
6
|
+
/** `GET` my shifts in published schedules (`?from&to`, ISO instants). */
|
|
7
|
+
shifts: `${BASE}/me`,
|
|
8
|
+
/** `GET` one of my shifts: the shift, the lead on duty and my swap. */
|
|
9
|
+
shift: (assignmentId) => `${BASE}/me/${enc(assignmentId)}`,
|
|
10
|
+
/** `GET` the QR pass of one of my shifts (the code only while check-in is open). */
|
|
11
|
+
pass: (assignmentId) => `${BASE}/me/${enc(assignmentId)}/pass`,
|
|
12
|
+
/** `POST` after a pass said `eligible: false`: cancels my future shifts on the team my role no longer meets, answers the pass. */
|
|
13
|
+
settle: (assignmentId) => `${BASE}/me/${enc(assignmentId)}/settle`,
|
|
14
|
+
/** `POST` `{ mode: 'station', token }` or `{ mode: 'location', latitude, longitude, accuracy }` to check in on one of my shifts myself. */
|
|
15
|
+
checkIn: (assignmentId) => `${BASE}/me/${enc(assignmentId)}/check-in`,
|
|
16
|
+
/** `GET` (`?status=unclaimed|claimed|all`) the perks I earned (`perks:read`). */
|
|
17
|
+
earnedPerks: `${BASE}/me/earned-perks`,
|
|
18
|
+
/** `POST` `{ client? }` to claim one of my earned perks, idempotently (`perks:claim`). */
|
|
19
|
+
claimEarnedPerk: (earnedPerkId) => `${BASE}/me/earned-perks/${enc(earnedPerkId)}/claim`,
|
|
20
|
+
/** `POST` to open a swap of one of my shifts, `DELETE` to withdraw it. */
|
|
21
|
+
swap: (assignmentId) => `${BASE}/me/${enc(assignmentId)}/swap`,
|
|
22
|
+
/** `GET` the teams I work on that have a shift running now, with who is on it. */
|
|
23
|
+
now: `${BASE}/me/now`,
|
|
24
|
+
/** `GET` the teams I lead. */
|
|
25
|
+
leads: `${BASE}/me/leads`,
|
|
26
|
+
/** `GET` whether I have a calendar feed, `POST` to mint one (shown once, revokes the old one), `DELETE` to revoke it. Session only. */
|
|
27
|
+
feedToken: `${BASE}/me/feed-token`
|
|
28
|
+
},
|
|
29
|
+
/** `GET` a person's shifts as an iCal feed; the secret token is the credential (`.ics` suffix optional). Public. */
|
|
30
|
+
feed: (token) => `${BASE}/feed/${enc(token)}.ics`,
|
|
31
|
+
/** `GET` the open swaps I can take. */
|
|
32
|
+
swaps: `${BASE}/swaps`,
|
|
33
|
+
/** `POST` `{ assignmentId? }` to offer to take a swap (optionally giving one of my shifts back). */
|
|
34
|
+
offers: (swapId) => `${BASE}/swaps/${enc(swapId)}/offers`,
|
|
35
|
+
/** `DELETE` to withdraw my offer. */
|
|
36
|
+
offer: (swapId, offerId) => `${BASE}/swaps/${enc(swapId)}/offers/${enc(offerId)}`,
|
|
37
|
+
/** `POST` (the swap's owner) to accept an offer. */
|
|
38
|
+
acceptOffer: (swapId, offerId) => `${BASE}/swaps/${enc(swapId)}/offers/${enc(offerId)}/accept`,
|
|
39
|
+
/** `POST` (the swap's owner) to reject an offer. */
|
|
40
|
+
rejectOffer: (swapId, offerId) => `${BASE}/swaps/${enc(swapId)}/offers/${enc(offerId)}/reject`,
|
|
41
|
+
/** `POST` (a lead of the team, or staff) to approve a swap waiting for approval. */
|
|
42
|
+
approveSwap: (swapId) => `${BASE}/swaps/${enc(swapId)}/approve`,
|
|
43
|
+
/** `POST` (a lead of the team, or staff) to reject a swap waiting for approval: it is open again. */
|
|
44
|
+
rejectSwap: (swapId) => `${BASE}/swaps/${enc(swapId)}/reject`,
|
|
45
|
+
teams: {
|
|
46
|
+
/** `POST` `{ code }` to check a person in with their QR pass (a lead of the team, or staff). */
|
|
47
|
+
checkIn: (teamId) => `${BASE}/teams/${enc(teamId)}/check-in`,
|
|
48
|
+
/** `GET` (`?from&to`) the team's shifts in published schedules with who works them (a lead of the team, or staff). */
|
|
49
|
+
shifts: (teamId) => `${BASE}/teams/${enc(teamId)}/shifts`,
|
|
50
|
+
/** `GET` (`?status`) the team's swaps, e.g. those waiting for approval (a lead of the team, or staff). */
|
|
51
|
+
swaps: (teamId) => `${BASE}/teams/${enc(teamId)}/swaps`,
|
|
52
|
+
/** `POST` `{ audience?, channels?, subject, message }` to message the team (a lead of it, or staff). Email unless `channels` adds `sms`. */
|
|
53
|
+
broadcasts: (teamId) => `${BASE}/teams/${enc(teamId)}/broadcasts`,
|
|
54
|
+
/** `GET` the exceptions of the team's recent shifts: no-shows, late, not checked in (a lead of the team, or staff). */
|
|
55
|
+
exceptions: (teamId) => `${BASE}/teams/${enc(teamId)}/exceptions`,
|
|
56
|
+
/** `GET` the team's check-in stations on published schedules (a lead of the team, or staff). */
|
|
57
|
+
stations: (teamId) => `${BASE}/teams/${enc(teamId)}/stations`
|
|
58
|
+
},
|
|
59
|
+
/** `GET` the current rotating QR code of a check-in station (a lead of its team, or staff). */
|
|
60
|
+
stationToken: (stationId) => `${BASE}/stations/${enc(stationId)}/token`,
|
|
61
|
+
/** `POST` to mark an assignment attended (a lead of the team, or staff). */
|
|
62
|
+
attended: (assignmentId) => `${BASE}/assignments/${enc(assignmentId)}/attended`,
|
|
63
|
+
/** `POST` to mark an assignment a no-show (a lead of the team, or staff). */
|
|
64
|
+
noShow: (assignmentId) => `${BASE}/assignments/${enc(assignmentId)}/no-show`,
|
|
65
|
+
/** `GET` who is on shift now in an operation, and the leads on duty per team. */
|
|
66
|
+
now: (operationId) => `${BASE}/operations/${enc(operationId)}/now`,
|
|
67
|
+
/** `GET` the `shifts.on-duty` live layer: GeoJSON points on the operation's venue layout, a team per shift location. */
|
|
68
|
+
onDuty: (operationId) => `${BASE}/operations/${enc(operationId)}/on-duty`,
|
|
69
|
+
admin: {
|
|
70
|
+
/** `GET` (`?operationId`) / `POST` schedules. */
|
|
71
|
+
schedules: `${ADMIN_BASE}/schedules`,
|
|
72
|
+
/** `GET` / `PATCH` / `DELETE` one schedule. */
|
|
73
|
+
schedule: (scheduleId) => `${ADMIN_BASE}/schedules/${enc(scheduleId)}`,
|
|
74
|
+
/** `POST` to publish a draft schedule. */
|
|
75
|
+
publish: (scheduleId) => `${ADMIN_BASE}/schedules/${enc(scheduleId)}/publish`,
|
|
76
|
+
/** `POST` `{ scheduleId, offsetDays }` to copy another schedule's roles and shifts into this one. */
|
|
77
|
+
copyFrom: (scheduleId) => `${ADMIN_BASE}/schedules/${enc(scheduleId)}/copy-from`,
|
|
78
|
+
/** `GET` / `POST` a schedule's shift roles. */
|
|
79
|
+
roles: (scheduleId) => `${ADMIN_BASE}/schedules/${enc(scheduleId)}/roles`,
|
|
80
|
+
/** `GET` / `POST` a schedule's check-in stations. */
|
|
81
|
+
stations: (scheduleId) => `${ADMIN_BASE}/schedules/${enc(scheduleId)}/stations`,
|
|
82
|
+
/** `PATCH` / `DELETE` one check-in station. */
|
|
83
|
+
station: (stationId) => `${ADMIN_BASE}/stations/${enc(stationId)}`,
|
|
84
|
+
/** `PATCH` / `DELETE` one shift role. */
|
|
85
|
+
role: (roleId) => `${ADMIN_BASE}/roles/${enc(roleId)}`,
|
|
86
|
+
/** `GET` (`?teamId&from&to`) a schedule's shifts with their assignments. */
|
|
87
|
+
shifts: (scheduleId) => `${ADMIN_BASE}/schedules/${enc(scheduleId)}/shifts`,
|
|
88
|
+
/** `POST` `{ teamId, days, slots, capacity?, shiftRoleId? }` to create shifts in bulk. */
|
|
89
|
+
bulk: (scheduleId) => `${ADMIN_BASE}/schedules/${enc(scheduleId)}/shifts/bulk`,
|
|
90
|
+
/** `PATCH` / `DELETE` one shift. */
|
|
91
|
+
shift: (shiftId) => `${ADMIN_BASE}/${enc(shiftId)}`,
|
|
92
|
+
/** `POST` `{ userId, shiftRoleId?, force? }` to assign a person to a shift. */
|
|
93
|
+
assignments: (shiftId) => `${ADMIN_BASE}/${enc(shiftId)}/assignments`,
|
|
94
|
+
/** `GET` (`?q`) the people of the shift's team staff could assign, with the guards they would break. */
|
|
95
|
+
candidates: (shiftId) => `${ADMIN_BASE}/${enc(shiftId)}/candidates`,
|
|
96
|
+
/** `DELETE` to cancel an assignment. */
|
|
97
|
+
assignment: (assignmentId) => `${ADMIN_BASE}/assignments/${enc(assignmentId)}`,
|
|
98
|
+
/** `GET` (`?operationId&status`) swaps, for staff. */
|
|
99
|
+
swaps: `${ADMIN_BASE}/swaps`,
|
|
100
|
+
/** `POST` to cancel a live swap, settling one stuck while being carried out. */
|
|
101
|
+
cancelSwap: (swapId) => `${ADMIN_BASE}/swaps/${enc(swapId)}/cancel`,
|
|
102
|
+
/** `GET` an operation's teams with their kind's ladder. */
|
|
103
|
+
teams: (operationId) => `${ADMIN_BASE}/operations/${enc(operationId)}/teams`,
|
|
104
|
+
/** `GET` (`?operationId`) the broadcasts of an operation, `POST` `{ operationId, audience, channels, subject, message }` to send one (`shifts:broadcast`). */
|
|
105
|
+
broadcasts: `${ADMIN_BASE}/broadcasts`,
|
|
106
|
+
/** `GET` / `POST` an operation's perks (what an attended shift earns). */
|
|
107
|
+
perks: (operationId) => `${ADMIN_BASE}/operations/${enc(operationId)}/perks`,
|
|
108
|
+
/** `PATCH` / `DELETE` one perk. */
|
|
109
|
+
perk: (perkId) => `${ADMIN_BASE}/perks/${enc(perkId)}`
|
|
110
|
+
}
|
|
111
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { GeoPoint, MapLocation } from '@frigear-nu/maps/utils';
|
|
2
|
+
import type { ShiftCheckInRule, ShiftCheckInSettings, ShiftExceptionKind } from '../../types.js';
|
|
3
|
+
export declare const SHIFT_CHECK_IN_MODES: readonly ["station", "location", "daily", "lead"];
|
|
4
|
+
/** The check-in settings of a schedule that never set any: the lead's scanner only (as before modes existed). */
|
|
5
|
+
export declare const DEFAULT_CHECK_IN: ShiftCheckInSettings;
|
|
6
|
+
/** The radius of a check-in place set as a bare point, and the most a device's accuracy may be, in metres. */
|
|
7
|
+
export declare const DEFAULT_CHECK_IN_RADIUS = 150;
|
|
8
|
+
/** How long a station's QR code lives, in seconds. The current and the previous window are accepted. */
|
|
9
|
+
export declare const STATION_ROTATE_SECONDS = 30;
|
|
10
|
+
/** A stored `checkIn` value, typed and with the defaults filled in. */
|
|
11
|
+
export declare function checkInSettingsOf(value: unknown): ShiftCheckInSettings;
|
|
12
|
+
/**
|
|
13
|
+
* What applies to one team's shifts: the team's override of `modes` and `location` where it sets them, the schedule's
|
|
14
|
+
* otherwise. `lead` is always in the result: a lead's scan works whatever the settings say.
|
|
15
|
+
*/
|
|
16
|
+
export declare function checkInRuleFor(settings: unknown, teamId: string): ShiftCheckInRule;
|
|
17
|
+
/** The radius a location check uses: the place's own radius, else the default (an area checks its outline instead). */
|
|
18
|
+
export declare const checkInRadius: (location: MapLocation) => number;
|
|
19
|
+
/**
|
|
20
|
+
* Whether a reported position passes the location check: inside the place (its area, or within its radius, 150 m for a
|
|
21
|
+
* bare point) and reported at least as accurately as that radius. `outside` and `inaccurate` name the 409 code.
|
|
22
|
+
*/
|
|
23
|
+
export declare function checkLocation(location: MapLocation, position: GeoPoint, accuracy: number): {
|
|
24
|
+
ok: true;
|
|
25
|
+
} | {
|
|
26
|
+
ok: false;
|
|
27
|
+
reason: 'outside' | 'inaccurate';
|
|
28
|
+
distance: number;
|
|
29
|
+
radius: number;
|
|
30
|
+
};
|
|
31
|
+
/** The rotation window an instant falls in. */
|
|
32
|
+
export declare const stationWindow: (now: number, rotateSeconds?: number) => number;
|
|
33
|
+
/** Whether a token of `window` is still accepted at `now`: the current window and the one before. */
|
|
34
|
+
export declare const stationWindowAccepted: (window: number, now: number, rotateSeconds?: number) => boolean;
|
|
35
|
+
/** What a station token signs: the station and the window. */
|
|
36
|
+
export declare const stationTokenPayload: (stationId: string, window: number) => string;
|
|
37
|
+
/** Splits a station token (`<stationId>.<window>.<signature>`); `null` when it is not one. */
|
|
38
|
+
export declare function parseStationToken(token: string): {
|
|
39
|
+
stationId: string;
|
|
40
|
+
window: number;
|
|
41
|
+
signature: string;
|
|
42
|
+
} | null;
|
|
43
|
+
/** The exception of an assignment at `now`, or `null`. `graceMinutes` is how long after the start nobody is "missing" yet. */
|
|
44
|
+
export declare function exceptionOf(assignment: {
|
|
45
|
+
status: string;
|
|
46
|
+
checkedInAt: Date | null;
|
|
47
|
+
}, shift: {
|
|
48
|
+
startsAt: Date;
|
|
49
|
+
}, now: Date, options?: {
|
|
50
|
+
graceMinutes?: number;
|
|
51
|
+
claimedPerk?: boolean;
|
|
52
|
+
}): {
|
|
53
|
+
kind: ShiftExceptionKind;
|
|
54
|
+
lateMinutes?: number;
|
|
55
|
+
} | null;
|
|
56
|
+
/** The most rows of each kind one run of `shifts:close-shifts` takes. */
|
|
57
|
+
export declare const DEFAULT_AUTOMATION_BATCH = 200;
|
|
58
|
+
export declare const MAX_AUTOMATION_BATCH = 1000;
|
|
59
|
+
export declare function normalizeAutomationBatch(value: unknown): number;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { haversineMeters, isInLocation } from "@frigear-nu/maps/utils";
|
|
2
|
+
export const SHIFT_CHECK_IN_MODES = ["station", "location", "daily", "lead"];
|
|
3
|
+
export const DEFAULT_CHECK_IN = { modes: ["lead"] };
|
|
4
|
+
export const DEFAULT_CHECK_IN_RADIUS = 150;
|
|
5
|
+
export const STATION_ROTATE_SECONDS = 30;
|
|
6
|
+
export function checkInSettingsOf(value) {
|
|
7
|
+
const raw = value && typeof value === "object" ? value : {};
|
|
8
|
+
const modes = cleanModes(raw.modes) ?? DEFAULT_CHECK_IN.modes;
|
|
9
|
+
return {
|
|
10
|
+
modes,
|
|
11
|
+
location: raw.location ?? null,
|
|
12
|
+
...raw.teams && Object.keys(raw.teams).length ? { teams: raw.teams } : {}
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
const cleanModes = (value) => Array.isArray(value) ? SHIFT_CHECK_IN_MODES.filter((mode) => value.includes(mode)) : void 0;
|
|
16
|
+
export function checkInRuleFor(settings, teamId) {
|
|
17
|
+
const schedule = checkInSettingsOf(settings);
|
|
18
|
+
const team = schedule.teams?.[teamId];
|
|
19
|
+
const modes = cleanModes(team?.modes) ?? schedule.modes;
|
|
20
|
+
const location = team && team.location !== void 0 ? team.location ?? null : schedule.location ?? null;
|
|
21
|
+
return { modes: modes.includes("lead") ? modes : [...modes, "lead"], location };
|
|
22
|
+
}
|
|
23
|
+
export const checkInRadius = (location) => location.radiusMeters ?? DEFAULT_CHECK_IN_RADIUS;
|
|
24
|
+
export function checkLocation(location, position, accuracy) {
|
|
25
|
+
const radius = checkInRadius(location);
|
|
26
|
+
const distance = Math.round(haversineMeters(position, location.point));
|
|
27
|
+
if (!Number.isFinite(accuracy) || accuracy < 0 || accuracy > radius) return { ok: false, reason: "inaccurate", distance, radius };
|
|
28
|
+
const inside = location.area?.length ? isInLocation(position, location) : distance <= radius;
|
|
29
|
+
return inside ? { ok: true } : { ok: false, reason: "outside", distance, radius };
|
|
30
|
+
}
|
|
31
|
+
export const stationWindow = (now, rotateSeconds = STATION_ROTATE_SECONDS) => Math.floor(now / (rotateSeconds * 1e3));
|
|
32
|
+
export const stationWindowAccepted = (window, now, rotateSeconds = STATION_ROTATE_SECONDS) => {
|
|
33
|
+
const current = stationWindow(now, rotateSeconds);
|
|
34
|
+
return window === current || window === current - 1;
|
|
35
|
+
};
|
|
36
|
+
export const stationTokenPayload = (stationId, window) => `${stationId}:${window}`;
|
|
37
|
+
export function parseStationToken(token) {
|
|
38
|
+
const parts = token.trim().split(".");
|
|
39
|
+
if (parts.length !== 3) return null;
|
|
40
|
+
const [stationId, window, signature] = parts;
|
|
41
|
+
if (!/^sst_[\da-f]{1,64}$/i.test(stationId) || !/^\d{1,15}$/.test(window) || !/^[\w-]{20,100}$/.test(signature)) return null;
|
|
42
|
+
return { stationId, window: Number(window), signature };
|
|
43
|
+
}
|
|
44
|
+
export function exceptionOf(assignment, shift, now, options = {}) {
|
|
45
|
+
if (assignment.status === "no_show") return { kind: options.claimedPerk ? "claimed_no_show" : "no_show" };
|
|
46
|
+
if (assignment.status === "attended" && assignment.checkedInAt && assignment.checkedInAt.getTime() > shift.startsAt.getTime() + 6e4) {
|
|
47
|
+
return { kind: "late", lateMinutes: Math.round((assignment.checkedInAt.getTime() - shift.startsAt.getTime()) / 6e4) };
|
|
48
|
+
}
|
|
49
|
+
if (assignment.status === "assigned" && now.getTime() >= shift.startsAt.getTime() + (options.graceMinutes ?? 0) * 6e4) return { kind: "not_checked_in" };
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
export const DEFAULT_AUTOMATION_BATCH = 200;
|
|
53
|
+
export const MAX_AUTOMATION_BATCH = 1e3;
|
|
54
|
+
export function normalizeAutomationBatch(value) {
|
|
55
|
+
const number = Math.floor(Number(value));
|
|
56
|
+
return Number.isFinite(number) && number > 0 ? Math.min(number, MAX_AUTOMATION_BATCH) : DEFAULT_AUTOMATION_BATCH;
|
|
57
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ShiftGuards, ShiftWarning } from '../../types.js';
|
|
2
|
+
/** A shift as the guards see it: an id and a time. */
|
|
3
|
+
export type GuardShift = {
|
|
4
|
+
id: string;
|
|
5
|
+
startsAt: Date | string;
|
|
6
|
+
endsAt: Date | string;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* The guards a person breaks by working `target` on top of `others` (their other `assigned`/`attended` shifts, the one
|
|
10
|
+
* they give up in a swap left out): working more shifts on one day than `maxShiftsPerDay` (days in `timeZone`), less
|
|
11
|
+
* rest than `minRestHours` between two shifts, and two shifts at once (always, without a guard).
|
|
12
|
+
*/
|
|
13
|
+
export declare function shiftGuardWarnings(target: GuardShift, others: readonly GuardShift[], guards: ShiftGuards | null | undefined, timeZone: string): ShiftWarning[];
|
|
14
|
+
/** The capacity that applies to a shift: its own, else the schedule's `maxPerShift`; `null` is unlimited. */
|
|
15
|
+
export declare const effectiveCapacity: (shift: {
|
|
16
|
+
capacity: number | null;
|
|
17
|
+
}, schedule: {
|
|
18
|
+
maxPerShift: number | null;
|
|
19
|
+
}) => number | null;
|
|
20
|
+
/** The capacity warnings of a shift holding `filled` people (after an assignment): over the capacity, or short of the minimum. */
|
|
21
|
+
export declare function shiftCapacityWarnings(filled: number, capacity: number | null, minPerShift: number | null): ShiftWarning[];
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { dayKey } from "@frigear-nu/module-kit/time";
|
|
2
|
+
const time = (value) => new Date(value).getTime();
|
|
3
|
+
const HOUR = 36e5;
|
|
4
|
+
export function shiftGuardWarnings(target, others, guards, timeZone) {
|
|
5
|
+
const warnings = [];
|
|
6
|
+
const start = time(target.startsAt);
|
|
7
|
+
const end = time(target.endsAt);
|
|
8
|
+
const rest = guards?.minRestHours ? guards.minRestHours * HOUR : 0;
|
|
9
|
+
for (const other of others) {
|
|
10
|
+
if (other.id === target.id) continue;
|
|
11
|
+
const otherStart = time(other.startsAt);
|
|
12
|
+
const otherEnd = time(other.endsAt);
|
|
13
|
+
if (otherStart < end && start < otherEnd) {
|
|
14
|
+
warnings.push({ code: "overlap", message: "The person works another shift at the same time.", shiftId: other.id });
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
const gap = otherEnd <= start ? start - otherEnd : otherStart - end;
|
|
18
|
+
if (rest && gap < rest) {
|
|
19
|
+
warnings.push({ code: "min_rest", message: `Less than ${guards.minRestHours} hours of rest between two shifts.`, shiftId: other.id });
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const max = guards?.maxShiftsPerDay;
|
|
23
|
+
if (max) {
|
|
24
|
+
const day = dayKey(target.startsAt, timeZone);
|
|
25
|
+
const sameDay = others.filter((other) => other.id !== target.id && dayKey(other.startsAt, timeZone) === day).length;
|
|
26
|
+
if (sameDay + 1 > max) warnings.push({ code: "max_shifts_per_day", message: `More than ${max} shift${max === 1 ? "" : "s"} on one day.` });
|
|
27
|
+
}
|
|
28
|
+
return warnings;
|
|
29
|
+
}
|
|
30
|
+
export const effectiveCapacity = (shift, schedule) => shift.capacity ?? schedule.maxPerShift ?? null;
|
|
31
|
+
export function shiftCapacityWarnings(filled, capacity, minPerShift) {
|
|
32
|
+
const warnings = [];
|
|
33
|
+
if (capacity !== null && filled > capacity) warnings.push({ code: "shift_full", message: `The shift takes ${capacity} people.` });
|
|
34
|
+
if (minPerShift && filled < minPerShift) warnings.push({ code: "below_min", message: `The shift needs at least ${minPerShift} people.` });
|
|
35
|
+
return warnings;
|
|
36
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Escapes a TEXT value: backslash, semicolon, comma and line breaks. Control characters (U+0000-0008, U+000B-001F,
|
|
3
|
+
* U+007F) are not allowed in a TEXT value and would break the file or the line: they are dropped (a tab stays).
|
|
4
|
+
*/
|
|
5
|
+
export declare function icsEscape(text: string): string;
|
|
6
|
+
/** An instant as `YYYYMMDDTHHMMSSZ` (UTC). */
|
|
7
|
+
export declare function icsDate(date: Date): string;
|
|
8
|
+
/**
|
|
9
|
+
* Folds a content line: no line is longer than 75 octets, the continuations start with one space. A multi-byte
|
|
10
|
+
* character is never split.
|
|
11
|
+
*/
|
|
12
|
+
export declare function icsFold(line: string): string;
|
|
13
|
+
/** One event of a feed. `end` is exclusive. */
|
|
14
|
+
export type IcsEvent = {
|
|
15
|
+
uid: string;
|
|
16
|
+
start: Date;
|
|
17
|
+
end: Date;
|
|
18
|
+
summary: string;
|
|
19
|
+
description?: string;
|
|
20
|
+
location?: string;
|
|
21
|
+
url?: string;
|
|
22
|
+
/** When the event was last changed (`DTSTAMP`); defaults to the calendar's `generatedAt`. */
|
|
23
|
+
stamp?: Date;
|
|
24
|
+
status?: 'CONFIRMED' | 'CANCELLED' | 'TENTATIVE';
|
|
25
|
+
};
|
|
26
|
+
/** A whole calendar as one string (CRLF line ends, ending with a final CRLF). */
|
|
27
|
+
export declare function buildIcs(input: {
|
|
28
|
+
name: string;
|
|
29
|
+
events: readonly IcsEvent[];
|
|
30
|
+
generatedAt?: Date;
|
|
31
|
+
prodId?: string;
|
|
32
|
+
}): string;
|