@frigear-nu/shifts 0.0.0-stage → 0.0.0

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.
Files changed (341) hide show
  1. package/README.md +53 -2
  2. package/dist/module.d.mts +709 -0
  3. package/dist/module.json +9 -0
  4. package/dist/module.mjs +253 -0
  5. package/dist/runtime/access.d.ts +2 -0
  6. package/dist/runtime/access.js +84 -0
  7. package/dist/runtime/app/components/ShiftBroadcastSlideover.d.vue.ts +19 -0
  8. package/dist/runtime/app/components/ShiftBroadcastSlideover.vue +142 -0
  9. package/dist/runtime/app/components/ShiftBroadcastSlideover.vue.d.ts +19 -0
  10. package/dist/runtime/app/components/ShiftBroadcastsCard.d.vue.ts +9 -0
  11. package/dist/runtime/app/components/ShiftBroadcastsCard.vue +74 -0
  12. package/dist/runtime/app/components/ShiftBroadcastsCard.vue.d.ts +9 -0
  13. package/dist/runtime/app/components/ShiftBulkSlideover.d.vue.ts +15 -0
  14. package/dist/runtime/app/components/ShiftBulkSlideover.vue +185 -0
  15. package/dist/runtime/app/components/ShiftBulkSlideover.vue.d.ts +15 -0
  16. package/dist/runtime/app/components/ShiftCheckInCard.d.vue.ts +13 -0
  17. package/dist/runtime/app/components/ShiftCheckInCard.vue +238 -0
  18. package/dist/runtime/app/components/ShiftCheckInCard.vue.d.ts +13 -0
  19. package/dist/runtime/app/components/ShiftCopySlideover.d.vue.ts +11 -0
  20. package/dist/runtime/app/components/ShiftCopySlideover.vue +71 -0
  21. package/dist/runtime/app/components/ShiftCopySlideover.vue.d.ts +11 -0
  22. package/dist/runtime/app/components/ShiftDayView.d.vue.ts +16 -0
  23. package/dist/runtime/app/components/ShiftDayView.vue +124 -0
  24. package/dist/runtime/app/components/ShiftDayView.vue.d.ts +16 -0
  25. package/dist/runtime/app/components/ShiftFeedSlideover.d.vue.ts +7 -0
  26. package/dist/runtime/app/components/ShiftFeedSlideover.vue +172 -0
  27. package/dist/runtime/app/components/ShiftFeedSlideover.vue.d.ts +7 -0
  28. package/dist/runtime/app/components/ShiftNowCard.d.vue.ts +6 -0
  29. package/dist/runtime/app/components/ShiftNowCard.vue +83 -0
  30. package/dist/runtime/app/components/ShiftNowCard.vue.d.ts +6 -0
  31. package/dist/runtime/app/components/ShiftPassFullscreen.d.vue.ts +13 -0
  32. package/dist/runtime/app/components/ShiftPassFullscreen.vue +79 -0
  33. package/dist/runtime/app/components/ShiftPassFullscreen.vue.d.ts +13 -0
  34. package/dist/runtime/app/components/ShiftPerkSlideover.d.vue.ts +14 -0
  35. package/dist/runtime/app/components/ShiftPerkSlideover.vue +103 -0
  36. package/dist/runtime/app/components/ShiftPerkSlideover.vue.d.ts +14 -0
  37. package/dist/runtime/app/components/ShiftPerksCard.d.vue.ts +8 -0
  38. package/dist/runtime/app/components/ShiftPerksCard.vue +66 -0
  39. package/dist/runtime/app/components/ShiftPerksCard.vue.d.ts +8 -0
  40. package/dist/runtime/app/components/ShiftQrScanner.d.vue.ts +10 -0
  41. package/dist/runtime/app/components/ShiftQrScanner.vue +44 -0
  42. package/dist/runtime/app/components/ShiftQrScanner.vue.d.ts +10 -0
  43. package/dist/runtime/app/components/ShiftRoleSlideover.d.vue.ts +15 -0
  44. package/dist/runtime/app/components/ShiftRoleSlideover.vue +88 -0
  45. package/dist/runtime/app/components/ShiftRoleSlideover.vue.d.ts +15 -0
  46. package/dist/runtime/app/components/ShiftScheduleSettingsFields.d.vue.ts +11 -0
  47. package/dist/runtime/app/components/ShiftScheduleSettingsFields.vue +61 -0
  48. package/dist/runtime/app/components/ShiftScheduleSettingsFields.vue.d.ts +11 -0
  49. package/dist/runtime/app/components/ShiftScheduleSlideover.d.vue.ts +12 -0
  50. package/dist/runtime/app/components/ShiftScheduleSlideover.vue +129 -0
  51. package/dist/runtime/app/components/ShiftScheduleSlideover.vue.d.ts +12 -0
  52. package/dist/runtime/app/components/ShiftSlideover.d.vue.ts +13 -0
  53. package/dist/runtime/app/components/ShiftSlideover.vue +353 -0
  54. package/dist/runtime/app/components/ShiftSlideover.vue.d.ts +13 -0
  55. package/dist/runtime/app/components/ShiftStationSlideover.d.vue.ts +15 -0
  56. package/dist/runtime/app/components/ShiftStationSlideover.vue +92 -0
  57. package/dist/runtime/app/components/ShiftStationSlideover.vue.d.ts +15 -0
  58. package/dist/runtime/app/composables/index.d.ts +6 -0
  59. package/dist/runtime/app/composables/index.js +5 -0
  60. package/dist/runtime/app/composables/useShiftsActions.d.ts +61 -0
  61. package/dist/runtime/app/composables/useShiftsActions.js +224 -0
  62. package/dist/runtime/app/composables/useShiftsFormat.d.ts +12 -0
  63. package/dist/runtime/app/composables/useShiftsFormat.js +14 -0
  64. package/dist/runtime/app/composables/useShiftsLinks.d.ts +12 -0
  65. package/dist/runtime/app/composables/useShiftsLinks.js +6 -0
  66. package/dist/runtime/app/composables/useShiftsTranslate.d.ts +5 -0
  67. package/dist/runtime/app/composables/useShiftsTranslate.js +12 -0
  68. package/dist/runtime/app/composables/useShiftsVenueFeatures.d.ts +17 -0
  69. package/dist/runtime/app/composables/useShiftsVenueFeatures.js +18 -0
  70. package/dist/runtime/app/dashboard/NextShift.d.vue.ts +3 -0
  71. package/dist/runtime/app/dashboard/NextShift.vue +69 -0
  72. package/dist/runtime/app/dashboard/NextShift.vue.d.ts +3 -0
  73. package/dist/runtime/app/dashboard/OpenSwaps.d.vue.ts +3 -0
  74. package/dist/runtime/app/dashboard/OpenSwaps.vue +69 -0
  75. package/dist/runtime/app/dashboard/OpenSwaps.vue.d.ts +3 -0
  76. package/dist/runtime/app/dashboard/TeamOnNow.d.vue.ts +3 -0
  77. package/dist/runtime/app/dashboard/TeamOnNow.vue +72 -0
  78. package/dist/runtime/app/dashboard/TeamOnNow.vue.d.ts +3 -0
  79. package/dist/runtime/app/pages/check-in.d.vue.ts +3 -0
  80. package/dist/runtime/app/pages/check-in.vue +93 -0
  81. package/dist/runtime/app/pages/check-in.vue.d.ts +3 -0
  82. package/dist/runtime/app/pages/lead.d.vue.ts +3 -0
  83. package/dist/runtime/app/pages/lead.vue +300 -0
  84. package/dist/runtime/app/pages/lead.vue.d.ts +3 -0
  85. package/dist/runtime/app/pages/shift.d.vue.ts +3 -0
  86. package/dist/runtime/app/pages/shift.vue +482 -0
  87. package/dist/runtime/app/pages/shift.vue.d.ts +3 -0
  88. package/dist/runtime/app/pages/shifts.d.vue.ts +3 -0
  89. package/dist/runtime/app/pages/shifts.vue +169 -0
  90. package/dist/runtime/app/pages/shifts.vue.d.ts +3 -0
  91. package/dist/runtime/app/pages/station.d.vue.ts +3 -0
  92. package/dist/runtime/app/pages/station.vue +104 -0
  93. package/dist/runtime/app/pages/station.vue.d.ts +3 -0
  94. package/dist/runtime/app/pages/swaps.d.vue.ts +3 -0
  95. package/dist/runtime/app/pages/swaps.vue +192 -0
  96. package/dist/runtime/app/pages/swaps.vue.d.ts +3 -0
  97. package/dist/runtime/app/tabs/Shifts.d.vue.ts +9 -0
  98. package/dist/runtime/app/tabs/Shifts.vue +487 -0
  99. package/dist/runtime/app/tabs/Shifts.vue.d.ts +9 -0
  100. package/dist/runtime/app/utils/admin-shifts.d.ts +42 -0
  101. package/dist/runtime/app/utils/admin-shifts.js +36 -0
  102. package/dist/runtime/dashboard.d.ts +8 -0
  103. package/dist/runtime/dashboard.js +30 -0
  104. package/dist/runtime/emails/shifts-broadcast.d.vue.ts +8 -0
  105. package/dist/runtime/emails/shifts-broadcast.vue +24 -0
  106. package/dist/runtime/emails/shifts-broadcast.vue.d.ts +8 -0
  107. package/dist/runtime/emails/shifts-reminder.d.vue.ts +12 -0
  108. package/dist/runtime/emails/shifts-reminder.vue +34 -0
  109. package/dist/runtime/emails/shifts-reminder.vue.d.ts +12 -0
  110. package/dist/runtime/emails/shifts-swap-accepted.d.vue.ts +11 -0
  111. package/dist/runtime/emails/shifts-swap-accepted.vue +32 -0
  112. package/dist/runtime/emails/shifts-swap-accepted.vue.d.ts +11 -0
  113. package/dist/runtime/emails/shifts-swap-completed.d.vue.ts +11 -0
  114. package/dist/runtime/emails/shifts-swap-completed.vue +32 -0
  115. package/dist/runtime/emails/shifts-swap-completed.vue.d.ts +11 -0
  116. package/dist/runtime/emails/shifts-swap-offered.d.vue.ts +11 -0
  117. package/dist/runtime/emails/shifts-swap-offered.vue +32 -0
  118. package/dist/runtime/emails/shifts-swap-offered.vue.d.ts +11 -0
  119. package/dist/runtime/emails/shifts-swap-pending.d.vue.ts +11 -0
  120. package/dist/runtime/emails/shifts-swap-pending.vue +32 -0
  121. package/dist/runtime/emails/shifts-swap-pending.vue.d.ts +11 -0
  122. package/dist/runtime/emails/shifts-swap-proposed.d.vue.ts +11 -0
  123. package/dist/runtime/emails/shifts-swap-proposed.vue +32 -0
  124. package/dist/runtime/emails/shifts-swap-proposed.vue.d.ts +11 -0
  125. package/dist/runtime/emails/shifts-swap-rejected.d.vue.ts +11 -0
  126. package/dist/runtime/emails/shifts-swap-rejected.vue +32 -0
  127. package/dist/runtime/emails/shifts-swap-rejected.vue.d.ts +11 -0
  128. package/dist/runtime/i18n/lang/da.json +626 -0
  129. package/dist/runtime/i18n/lang/en.json +626 -0
  130. package/dist/runtime/menus.d.ts +2 -0
  131. package/dist/runtime/menus.js +17 -0
  132. package/dist/runtime/notifications.d.ts +9 -0
  133. package/dist/runtime/notifications.js +36 -0
  134. package/dist/runtime/server/db/schema.postgresql.d.ts +2151 -0
  135. package/dist/runtime/server/db/schema.postgresql.js +228 -0
  136. package/dist/runtime/server/db/schema.sqlite.d.ts +2263 -0
  137. package/dist/runtime/server/db/schema.sqlite.js +228 -0
  138. package/dist/runtime/server/digest-email.d.ts +17 -0
  139. package/dist/runtime/server/digest-email.js +42 -0
  140. package/dist/runtime/server/plugins/station-key.d.ts +2 -0
  141. package/dist/runtime/server/plugins/station-key.js +5 -0
  142. package/dist/runtime/server/plugins/teams.d.ts +2 -0
  143. package/dist/runtime/server/plugins/teams.js +19 -0
  144. package/dist/runtime/server/policies.d.ts +2 -0
  145. package/dist/runtime/server/policies.js +41 -0
  146. package/dist/runtime/server/reminder-email.d.ts +67 -0
  147. package/dist/runtime/server/reminder-email.js +109 -0
  148. package/dist/runtime/server/routes/admin/assignment.delete.d.ts +2 -0
  149. package/dist/runtime/server/routes/admin/assignment.delete.js +10 -0
  150. package/dist/runtime/server/routes/admin/assignments.post.d.ts +2 -0
  151. package/dist/runtime/server/routes/admin/assignments.post.js +11 -0
  152. package/dist/runtime/server/routes/admin/broadcasts.get.d.ts +2 -0
  153. package/dist/runtime/server/routes/admin/broadcasts.get.js +8 -0
  154. package/dist/runtime/server/routes/admin/broadcasts.post.d.ts +2 -0
  155. package/dist/runtime/server/routes/admin/broadcasts.post.js +9 -0
  156. package/dist/runtime/server/routes/admin/candidates.get.d.ts +2 -0
  157. package/dist/runtime/server/routes/admin/candidates.get.js +10 -0
  158. package/dist/runtime/server/routes/admin/operation-teams.get.d.ts +2 -0
  159. package/dist/runtime/server/routes/admin/operation-teams.get.js +9 -0
  160. package/dist/runtime/server/routes/admin/perk.delete.d.ts +2 -0
  161. package/dist/runtime/server/routes/admin/perk.delete.js +10 -0
  162. package/dist/runtime/server/routes/admin/perk.patch.d.ts +2 -0
  163. package/dist/runtime/server/routes/admin/perk.patch.js +10 -0
  164. package/dist/runtime/server/routes/admin/perks.get.d.ts +2 -0
  165. package/dist/runtime/server/routes/admin/perks.get.js +9 -0
  166. package/dist/runtime/server/routes/admin/perks.post.d.ts +2 -0
  167. package/dist/runtime/server/routes/admin/perks.post.js +10 -0
  168. package/dist/runtime/server/routes/admin/role.delete.d.ts +2 -0
  169. package/dist/runtime/server/routes/admin/role.delete.js +11 -0
  170. package/dist/runtime/server/routes/admin/role.patch.d.ts +2 -0
  171. package/dist/runtime/server/routes/admin/role.patch.js +11 -0
  172. package/dist/runtime/server/routes/admin/roles.get.d.ts +2 -0
  173. package/dist/runtime/server/routes/admin/roles.get.js +9 -0
  174. package/dist/runtime/server/routes/admin/roles.post.d.ts +2 -0
  175. package/dist/runtime/server/routes/admin/roles.post.js +10 -0
  176. package/dist/runtime/server/routes/admin/schedule-copy.post.d.ts +2 -0
  177. package/dist/runtime/server/routes/admin/schedule-copy.post.js +12 -0
  178. package/dist/runtime/server/routes/admin/schedule-publish.post.d.ts +2 -0
  179. package/dist/runtime/server/routes/admin/schedule-publish.post.js +9 -0
  180. package/dist/runtime/server/routes/admin/schedule.delete.d.ts +2 -0
  181. package/dist/runtime/server/routes/admin/schedule.delete.js +10 -0
  182. package/dist/runtime/server/routes/admin/schedule.get.d.ts +2 -0
  183. package/dist/runtime/server/routes/admin/schedule.get.js +9 -0
  184. package/dist/runtime/server/routes/admin/schedule.patch.d.ts +2 -0
  185. package/dist/runtime/server/routes/admin/schedule.patch.js +10 -0
  186. package/dist/runtime/server/routes/admin/schedules.get.d.ts +2 -0
  187. package/dist/runtime/server/routes/admin/schedules.get.js +10 -0
  188. package/dist/runtime/server/routes/admin/schedules.post.d.ts +2 -0
  189. package/dist/runtime/server/routes/admin/schedules.post.js +9 -0
  190. package/dist/runtime/server/routes/admin/shift.delete.d.ts +2 -0
  191. package/dist/runtime/server/routes/admin/shift.delete.js +10 -0
  192. package/dist/runtime/server/routes/admin/shift.patch.d.ts +2 -0
  193. package/dist/runtime/server/routes/admin/shift.patch.js +10 -0
  194. package/dist/runtime/server/routes/admin/shifts-bulk.post.d.ts +2 -0
  195. package/dist/runtime/server/routes/admin/shifts-bulk.post.js +10 -0
  196. package/dist/runtime/server/routes/admin/shifts.get.d.ts +2 -0
  197. package/dist/runtime/server/routes/admin/shifts.get.js +10 -0
  198. package/dist/runtime/server/routes/admin/station.delete.d.ts +2 -0
  199. package/dist/runtime/server/routes/admin/station.delete.js +11 -0
  200. package/dist/runtime/server/routes/admin/station.patch.d.ts +2 -0
  201. package/dist/runtime/server/routes/admin/station.patch.js +11 -0
  202. package/dist/runtime/server/routes/admin/stations.get.d.ts +2 -0
  203. package/dist/runtime/server/routes/admin/stations.get.js +9 -0
  204. package/dist/runtime/server/routes/admin/stations.post.d.ts +2 -0
  205. package/dist/runtime/server/routes/admin/stations.post.js +10 -0
  206. package/dist/runtime/server/routes/admin/swap-cancel.post.d.ts +2 -0
  207. package/dist/runtime/server/routes/admin/swap-cancel.post.js +10 -0
  208. package/dist/runtime/server/routes/admin/swaps.get.d.ts +2 -0
  209. package/dist/runtime/server/routes/admin/swaps.get.js +10 -0
  210. package/dist/runtime/server/routes/feed/feed.get.d.ts +2 -0
  211. package/dist/runtime/server/routes/feed/feed.get.js +9 -0
  212. package/dist/runtime/server/routes/lead/attended.post.d.ts +2 -0
  213. package/dist/runtime/server/routes/lead/attended.post.js +11 -0
  214. package/dist/runtime/server/routes/lead/broadcast.post.d.ts +2 -0
  215. package/dist/runtime/server/routes/lead/broadcast.post.js +12 -0
  216. package/dist/runtime/server/routes/lead/check-in.post.d.ts +2 -0
  217. package/dist/runtime/server/routes/lead/check-in.post.js +9 -0
  218. package/dist/runtime/server/routes/lead/exceptions.get.d.ts +2 -0
  219. package/dist/runtime/server/routes/lead/exceptions.get.js +8 -0
  220. package/dist/runtime/server/routes/lead/no-show.post.d.ts +2 -0
  221. package/dist/runtime/server/routes/lead/no-show.post.js +11 -0
  222. package/dist/runtime/server/routes/lead/now.get.d.ts +2 -0
  223. package/dist/runtime/server/routes/lead/now.get.js +9 -0
  224. package/dist/runtime/server/routes/lead/on-duty.get.d.ts +2 -0
  225. package/dist/runtime/server/routes/lead/on-duty.get.js +10 -0
  226. package/dist/runtime/server/routes/lead/stations.get.d.ts +2 -0
  227. package/dist/runtime/server/routes/lead/stations.get.js +8 -0
  228. package/dist/runtime/server/routes/lead/team-shifts.get.d.ts +2 -0
  229. package/dist/runtime/server/routes/lead/team-shifts.get.js +9 -0
  230. package/dist/runtime/server/routes/lead/team-swaps.get.d.ts +2 -0
  231. package/dist/runtime/server/routes/lead/team-swaps.get.js +9 -0
  232. package/dist/runtime/server/routes/me/check-in.post.d.ts +2 -0
  233. package/dist/runtime/server/routes/me/check-in.post.js +11 -0
  234. package/dist/runtime/server/routes/me/earned-perk-claim.post.d.ts +2 -0
  235. package/dist/runtime/server/routes/me/earned-perk-claim.post.js +10 -0
  236. package/dist/runtime/server/routes/me/earned-perks.get.d.ts +2 -0
  237. package/dist/runtime/server/routes/me/earned-perks.get.js +9 -0
  238. package/dist/runtime/server/routes/me/feed-token.delete.d.ts +2 -0
  239. package/dist/runtime/server/routes/me/feed-token.delete.js +7 -0
  240. package/dist/runtime/server/routes/me/feed-token.get.d.ts +2 -0
  241. package/dist/runtime/server/routes/me/feed-token.get.js +6 -0
  242. package/dist/runtime/server/routes/me/feed-token.post.d.ts +2 -0
  243. package/dist/runtime/server/routes/me/feed-token.post.js +7 -0
  244. package/dist/runtime/server/routes/me/leads.get.d.ts +2 -0
  245. package/dist/runtime/server/routes/me/leads.get.js +5 -0
  246. package/dist/runtime/server/routes/me/now.get.d.ts +2 -0
  247. package/dist/runtime/server/routes/me/now.get.js +5 -0
  248. package/dist/runtime/server/routes/me/pass.get.d.ts +2 -0
  249. package/dist/runtime/server/routes/me/pass.get.js +11 -0
  250. package/dist/runtime/server/routes/me/settle.post.d.ts +2 -0
  251. package/dist/runtime/server/routes/me/settle.post.js +14 -0
  252. package/dist/runtime/server/routes/me/shift.get.d.ts +2 -0
  253. package/dist/runtime/server/routes/me/shift.get.js +10 -0
  254. package/dist/runtime/server/routes/me/shifts.get.d.ts +2 -0
  255. package/dist/runtime/server/routes/me/shifts.get.js +6 -0
  256. package/dist/runtime/server/routes/me/swap.delete.d.ts +2 -0
  257. package/dist/runtime/server/routes/me/swap.delete.js +11 -0
  258. package/dist/runtime/server/routes/me/swap.post.d.ts +2 -0
  259. package/dist/runtime/server/routes/me/swap.post.js +11 -0
  260. package/dist/runtime/server/routes/stations/token.get.d.ts +2 -0
  261. package/dist/runtime/server/routes/stations/token.get.js +12 -0
  262. package/dist/runtime/server/routes/swaps/approve.post.d.ts +2 -0
  263. package/dist/runtime/server/routes/swaps/approve.post.js +9 -0
  264. package/dist/runtime/server/routes/swaps/list.get.d.ts +2 -0
  265. package/dist/runtime/server/routes/swaps/list.get.js +5 -0
  266. package/dist/runtime/server/routes/swaps/offer-accept.post.d.ts +2 -0
  267. package/dist/runtime/server/routes/swaps/offer-accept.post.js +9 -0
  268. package/dist/runtime/server/routes/swaps/offer-reject.post.d.ts +2 -0
  269. package/dist/runtime/server/routes/swaps/offer-reject.post.js +9 -0
  270. package/dist/runtime/server/routes/swaps/offer.delete.d.ts +2 -0
  271. package/dist/runtime/server/routes/swaps/offer.delete.js +11 -0
  272. package/dist/runtime/server/routes/swaps/offer.post.d.ts +2 -0
  273. package/dist/runtime/server/routes/swaps/offer.post.js +11 -0
  274. package/dist/runtime/server/routes/swaps/reject.post.d.ts +2 -0
  275. package/dist/runtime/server/routes/swaps/reject.post.js +9 -0
  276. package/dist/runtime/server/swap-email.d.ts +28 -0
  277. package/dist/runtime/server/swap-email.js +49 -0
  278. package/dist/runtime/server/tasks/close-shifts.d.ts +2 -0
  279. package/dist/runtime/server/tasks/close-shifts.js +9 -0
  280. package/dist/runtime/server/tasks/send-reminders.d.ts +2 -0
  281. package/dist/runtime/server/tasks/send-reminders.js +9 -0
  282. package/dist/runtime/server/utils/shifts-admin.d.ts +67 -0
  283. package/dist/runtime/server/utils/shifts-admin.js +312 -0
  284. package/dist/runtime/server/utils/shifts-assign.d.ts +89 -0
  285. package/dist/runtime/server/utils/shifts-assign.js +264 -0
  286. package/dist/runtime/server/utils/shifts-automation.d.ts +37 -0
  287. package/dist/runtime/server/utils/shifts-automation.js +171 -0
  288. package/dist/runtime/server/utils/shifts-broadcasts.d.ts +38 -0
  289. package/dist/runtime/server/utils/shifts-broadcasts.js +113 -0
  290. package/dist/runtime/server/utils/shifts-core.d.ts +78 -0
  291. package/dist/runtime/server/utils/shifts-core.js +142 -0
  292. package/dist/runtime/server/utils/shifts-dto.d.ts +32 -0
  293. package/dist/runtime/server/utils/shifts-dto.js +127 -0
  294. package/dist/runtime/server/utils/shifts-emails.d.ts +16 -0
  295. package/dist/runtime/server/utils/shifts-emails.js +44 -0
  296. package/dist/runtime/server/utils/shifts-exceptions.d.ts +7 -0
  297. package/dist/runtime/server/utils/shifts-exceptions.js +32 -0
  298. package/dist/runtime/server/utils/shifts-feed.d.ts +16 -0
  299. package/dist/runtime/server/utils/shifts-feed.js +73 -0
  300. package/dist/runtime/server/utils/shifts-notify.d.ts +40 -0
  301. package/dist/runtime/server/utils/shifts-notify.js +22 -0
  302. package/dist/runtime/server/utils/shifts-on-duty.d.ts +12 -0
  303. package/dist/runtime/server/utils/shifts-on-duty.js +37 -0
  304. package/dist/runtime/server/utils/shifts-perks.d.ts +46 -0
  305. package/dist/runtime/server/utils/shifts-perks.js +183 -0
  306. package/dist/runtime/server/utils/shifts-reminders.d.ts +30 -0
  307. package/dist/runtime/server/utils/shifts-reminders.js +102 -0
  308. package/dist/runtime/server/utils/shifts-schemas.d.ts +318 -0
  309. package/dist/runtime/server/utils/shifts-schemas.js +177 -0
  310. package/dist/runtime/server/utils/shifts-station-key.d.ts +7 -0
  311. package/dist/runtime/server/utils/shifts-station-key.js +22 -0
  312. package/dist/runtime/server/utils/shifts-stations.d.ts +28 -0
  313. package/dist/runtime/server/utils/shifts-stations.js +109 -0
  314. package/dist/runtime/server/utils/shifts-swaps.d.ts +114 -0
  315. package/dist/runtime/server/utils/shifts-swaps.js +559 -0
  316. package/dist/runtime/server/utils/shifts-views.d.ts +62 -0
  317. package/dist/runtime/server/utils/shifts-views.js +212 -0
  318. package/dist/runtime/utils/api.d.ts +108 -0
  319. package/dist/runtime/utils/api.js +111 -0
  320. package/dist/runtime/utils/checkin.d.ts +59 -0
  321. package/dist/runtime/utils/checkin.js +57 -0
  322. package/dist/runtime/utils/guards.d.ts +21 -0
  323. package/dist/runtime/utils/guards.js +36 -0
  324. package/dist/runtime/utils/ics.d.ts +32 -0
  325. package/dist/runtime/utils/ics.js +56 -0
  326. package/dist/runtime/utils/index.d.ts +16 -0
  327. package/dist/runtime/utils/index.js +15 -0
  328. package/dist/runtime/utils/links.d.ts +30 -0
  329. package/dist/runtime/utils/links.js +18 -0
  330. package/dist/runtime/utils/reminders.d.ts +27 -0
  331. package/dist/runtime/utils/reminders.js +28 -0
  332. package/dist/runtime/utils/settings.d.ts +28 -0
  333. package/dist/runtime/utils/settings.js +18 -0
  334. package/dist/runtime/utils/station-key.d.ts +9 -0
  335. package/dist/runtime/utils/station-key.js +12 -0
  336. package/dist/runtime/utils/status.d.ts +23 -0
  337. package/dist/runtime/utils/status.js +46 -0
  338. package/dist/runtime/utils/time.d.ts +22 -0
  339. package/dist/runtime/utils/time.js +14 -0
  340. package/dist/types.d.mts +5 -0
  341. package/package.json +131 -3
@@ -0,0 +1,312 @@
1
+ import { db, schema } from "@nuxthub/db";
2
+ import { and, asc, count, desc, eq, gte, inArray, lt, ne } from "drizzle-orm";
3
+ import { apiError, chunkParams, validationError } from "@frigear-nu/module-kit/server";
4
+ import { newId } from "../../utils/index.js";
5
+ import { validScheduleSettings } from "../../utils/settings.js";
6
+ import { ACTIVE_ASSIGNMENT_STATUSES } from "../../utils/status.js";
7
+ import { shiftByDays } from "@frigear-nu/module-kit/time";
8
+ import { slotInstants } from "../../utils/time.js";
9
+ import { toShiftDto, toShiftRoleDto, toShiftScheduleDto } from "./shifts-dto.js";
10
+ import { getShiftScheduleOr404, shiftsAssigneeDtos, shiftsConfig, shiftsFire, shiftsOperationTeamOr400, shiftsRoleOfOr400, shiftsTeamsById } from "./shifts-core.js";
11
+ export const SHIFT_INSERT_ROWS = Math.floor(90 / 11);
12
+ const cleanGuards = (guards) => ({
13
+ ...guards?.maxShiftsPerDay ? { maxShiftsPerDay: guards.maxShiftsPerDay } : {},
14
+ ...guards?.minRestHours ? { minRestHours: guards.minRestHours } : {}
15
+ });
16
+ function shiftsAssertScheduleSettings(settings) {
17
+ if (!validScheduleSettings(settings)) {
18
+ throw apiError(400, "invalid_schedule_settings", 'With coverage "all" volunteers must work every shift they hold: the handover must be "trade".', { coverage: settings.coverage, handover: settings.handover });
19
+ }
20
+ }
21
+ export async function shiftsListSchedules(operationId, event) {
22
+ const rows = await db.select().from(schema.shiftSchedules).where(operationId ? eq(schema.shiftSchedules.operationId, operationId) : void 0).orderBy(desc(schema.shiftSchedules.createdAt), asc(schema.shiftSchedules.id)).limit(500);
23
+ if (!rows.length) return [];
24
+ const counts = (await Promise.all(chunkParams(rows.map((row) => row.id)).map((part) => db.select({ scheduleId: schema.shifts.scheduleId, total: count() }).from(schema.shifts).where(inArray(schema.shifts.scheduleId, part)).groupBy(schema.shifts.scheduleId)))).flat();
25
+ const byId = new Map(counts.map((row) => [row.scheduleId, Number(row.total)]));
26
+ return rows.map((row) => toShiftScheduleDto(row, byId.get(row.id) ?? 0, event));
27
+ }
28
+ export async function shiftsCreateSchedule(input) {
29
+ shiftsAssertScheduleSettings(input);
30
+ const [row] = await db.insert(schema.shiftSchedules).values({
31
+ id: newId("shs"),
32
+ operationId: input.operationId,
33
+ name: input.name,
34
+ status: "draft",
35
+ coverage: input.coverage,
36
+ handover: input.handover,
37
+ approval: input.approval,
38
+ minPerShift: input.minPerShift ?? null,
39
+ maxPerShift: input.maxPerShift ?? null,
40
+ guards: cleanGuards(input.guards),
41
+ checkIn: input.checkIn ? await shiftsCleanCheckIn(input.operationId, input.checkIn) : null,
42
+ autoNoShow: input.autoNoShow,
43
+ autoNoShowMinutes: input.autoNoShowMinutes
44
+ }).returning();
45
+ return row;
46
+ }
47
+ async function shiftsCleanCheckIn(operationId, checkIn) {
48
+ const teamIds = Object.keys(checkIn.teams ?? {});
49
+ if (teamIds.length) {
50
+ const known = new Set((await Promise.all(chunkParams(teamIds).map((part) => db.select({ id: schema.teams.id }).from(schema.teams).where(and(
51
+ inArray(schema.teams.id, part),
52
+ eq(schema.teams.ownerType, "operation"),
53
+ eq(schema.teams.ownerId, operationId)
54
+ ))))).flat().map((row) => row.id));
55
+ const unknown = teamIds.find((id) => !known.has(id));
56
+ if (unknown) throw validationError([{ path: ["checkIn", "teams", unknown], message: "The team must belong to the schedule's operation." }], "Unknown team");
57
+ }
58
+ return {
59
+ modes: checkIn.modes,
60
+ ...checkIn.location ? { location: checkIn.location } : {},
61
+ ...teamIds.length ? { teams: checkIn.teams } : {}
62
+ };
63
+ }
64
+ export async function shiftsPatchSchedule(existing, patch) {
65
+ const values = {};
66
+ if (patch.name !== void 0) values.name = patch.name;
67
+ if (patch.coverage !== void 0) values.coverage = patch.coverage;
68
+ if (patch.handover !== void 0) values.handover = patch.handover;
69
+ if (patch.approval !== void 0) values.approval = patch.approval;
70
+ shiftsAssertScheduleSettings({ coverage: values.coverage ?? existing.coverage, handover: values.handover ?? existing.handover });
71
+ if (patch.minPerShift !== void 0) values.minPerShift = patch.minPerShift;
72
+ if (patch.maxPerShift !== void 0) values.maxPerShift = patch.maxPerShift;
73
+ if (patch.guards !== void 0) values.guards = cleanGuards(patch.guards);
74
+ if (patch.checkIn !== void 0) values.checkIn = patch.checkIn ? await shiftsCleanCheckIn(existing.operationId, patch.checkIn) : null;
75
+ if (patch.autoNoShow !== void 0) values.autoNoShow = patch.autoNoShow;
76
+ if (patch.autoNoShowMinutes !== void 0) values.autoNoShowMinutes = patch.autoNoShowMinutes;
77
+ const min = values.minPerShift !== void 0 ? values.minPerShift : existing.minPerShift;
78
+ const max = values.maxPerShift !== void 0 ? values.maxPerShift : existing.maxPerShift;
79
+ if (min != null && max != null && max < min) throw validationError([{ path: ["maxPerShift"], message: "The maximum must be at least the minimum." }]);
80
+ if (!Object.keys(values).length) return existing;
81
+ const [row] = await db.update(schema.shiftSchedules).set(values).where(eq(schema.shiftSchedules.id, existing.id)).returning();
82
+ return row;
83
+ }
84
+ export async function shiftsPublishSchedule(event, existing) {
85
+ if (existing.status === "published") return existing;
86
+ const [row] = await db.update(schema.shiftSchedules).set({ status: "published", publishedAt: /* @__PURE__ */ new Date() }).where(and(eq(schema.shiftSchedules.id, existing.id), eq(schema.shiftSchedules.status, "draft"))).returning();
87
+ if (!row) return getShiftScheduleOr404(existing.id);
88
+ await shiftsFire("shifts:schedule:published", { event, schedule: toShiftScheduleDto(row, void 0, event) });
89
+ return row;
90
+ }
91
+ async function shiftsHaveAttendance(shiftIds) {
92
+ if (!shiftIds.length) return false;
93
+ for (const part of chunkParams(shiftIds)) {
94
+ const [row] = await db.select({ id: schema.shiftAssignments.id }).from(schema.shiftAssignments).where(and(inArray(schema.shiftAssignments.shiftId, part), ne(schema.shiftAssignments.status, "cancelled"))).limit(1);
95
+ if (row) return true;
96
+ }
97
+ return false;
98
+ }
99
+ async function shiftsDeleteShiftRows(shiftIds) {
100
+ if (!shiftIds.length) return;
101
+ const each = async (ids, run) => await Promise.all(chunkParams(ids).map(run));
102
+ const assignmentIds = (await each(shiftIds, (part) => db.select({ id: schema.shiftAssignments.id }).from(schema.shiftAssignments).where(inArray(schema.shiftAssignments.shiftId, part)))).flat().map((row) => row.id);
103
+ if (assignmentIds.length) {
104
+ const swapIds = (await each(assignmentIds, (part) => db.select({ id: schema.shiftSwaps.id }).from(schema.shiftSwaps).where(inArray(schema.shiftSwaps.assignmentId, part)))).flat().map((row) => row.id);
105
+ if (swapIds.length) {
106
+ await each(swapIds, (part) => db.delete(schema.shiftSwapOffers).where(inArray(schema.shiftSwapOffers.swapId, part)));
107
+ await each(swapIds, (part) => db.delete(schema.shiftSwaps).where(inArray(schema.shiftSwaps.id, part)));
108
+ }
109
+ await each(assignmentIds, (part) => db.delete(schema.shiftReminders).where(inArray(schema.shiftReminders.assignmentId, part)));
110
+ await each(assignmentIds, (part) => db.delete(schema.shiftEarnedPerks).where(inArray(schema.shiftEarnedPerks.assignmentId, part)));
111
+ await each(assignmentIds, (part) => db.delete(schema.shiftDigestItems).where(inArray(schema.shiftDigestItems.assignmentId, part)));
112
+ await each(assignmentIds, (part) => db.delete(schema.shiftAssignments).where(inArray(schema.shiftAssignments.id, part)));
113
+ }
114
+ await each(shiftIds, (part) => db.delete(schema.shifts).where(inArray(schema.shifts.id, part)));
115
+ }
116
+ export async function shiftsDeleteSchedule(existing) {
117
+ const shiftIds = (await db.select({ id: schema.shifts.id }).from(schema.shifts).where(eq(schema.shifts.scheduleId, existing.id))).map((row) => row.id);
118
+ if (await shiftsHaveAttendance(shiftIds)) throw apiError(409, "schedule_in_use", "People are assigned to shifts of this schedule. Cancel their assignments first.");
119
+ await shiftsDeleteShiftRows(shiftIds);
120
+ await db.delete(schema.shiftRoles).where(eq(schema.shiftRoles.scheduleId, existing.id));
121
+ await db.delete(schema.shiftStations).where(eq(schema.shiftStations.scheduleId, existing.id));
122
+ await db.delete(schema.shiftSchedules).where(eq(schema.shiftSchedules.id, existing.id));
123
+ }
124
+ export async function shiftsListRoles(scheduleId) {
125
+ const rows = await db.select().from(schema.shiftRoles).where(eq(schema.shiftRoles.scheduleId, scheduleId)).orderBy(asc(schema.shiftRoles.createdAt), asc(schema.shiftRoles.id));
126
+ return rows.map(toShiftRoleDto);
127
+ }
128
+ export async function shiftsCreateRole(event, schedule, input) {
129
+ const team = await shiftsOperationTeamOr400(schedule.operationId, input.teamId);
130
+ if (input.teamRole) await assertTeamRoleOnLadder(event, team.kind, input.teamRole, "teamRole");
131
+ const [row] = await db.insert(schema.shiftRoles).values({ id: newId("shr"), scheduleId: schedule.id, teamId: team.id, teamRole: input.teamRole ?? null, name: input.name }).returning();
132
+ return row;
133
+ }
134
+ export async function shiftsPatchRole(event, role, patch) {
135
+ const values = {};
136
+ if (patch.name !== void 0) values.name = patch.name;
137
+ if (patch.teamRole !== void 0) {
138
+ if (patch.teamRole) {
139
+ const [team] = await db.select().from(schema.teams).where(eq(schema.teams.id, role.teamId)).limit(1);
140
+ if (team) await assertTeamRoleOnLadder(event, team.kind, patch.teamRole, "teamRole");
141
+ }
142
+ values.teamRole = patch.teamRole ?? null;
143
+ }
144
+ if (!Object.keys(values).length) return role;
145
+ const [row] = await db.update(schema.shiftRoles).set(values).where(eq(schema.shiftRoles.id, role.id)).returning();
146
+ return row;
147
+ }
148
+ export async function shiftsDeleteRole(role) {
149
+ const [shift] = await db.select({ id: schema.shifts.id }).from(schema.shifts).where(eq(schema.shifts.shiftRoleId, role.id)).limit(1);
150
+ const [assignment] = await db.select({ id: schema.shiftAssignments.id }).from(schema.shiftAssignments).where(and(eq(schema.shiftAssignments.shiftRoleId, role.id), ne(schema.shiftAssignments.status, "cancelled"))).limit(1);
151
+ if (shift || assignment) throw apiError(409, "role_in_use", "Shifts or assignments use this role. Change them first.");
152
+ await db.delete(schema.shiftRoles).where(eq(schema.shiftRoles.id, role.id));
153
+ }
154
+ export async function shiftsBulkCreate(event, schedule, input) {
155
+ const team = await shiftsOperationTeamOr400(schedule.operationId, input.teamId);
156
+ if (input.shiftRoleId) await shiftsRoleOfOr400(schedule.id, team.id, input.shiftRoleId);
157
+ const { timeZone } = shiftsConfig(event);
158
+ const values = input.days.flatMap((day) => input.slots.map((slot) => {
159
+ const { startsAt, endsAt } = slotInstants(day, slot, timeZone);
160
+ return {
161
+ id: newId("shf"),
162
+ scheduleId: schedule.id,
163
+ teamId: team.id,
164
+ shiftRoleId: input.shiftRoleId ?? null,
165
+ startsAt,
166
+ endsAt,
167
+ capacity: input.capacity ?? null,
168
+ location: input.location ?? null,
169
+ notes: input.notes && (typeof input.notes !== "string" || input.notes) ? input.notes : null
170
+ };
171
+ }));
172
+ const rows = [];
173
+ for (const part of chunkParams(values, SHIFT_INSERT_ROWS)) rows.push(...await db.insert(schema.shifts).values(part).returning());
174
+ rows.sort((a, b) => a.startsAt.getTime() - b.startsAt.getTime());
175
+ const dtos = rows.map((row) => toShiftDto(row, schedule));
176
+ for (const shift of dtos) await shiftsFire("shifts:shift:created", { event, shift });
177
+ return dtos;
178
+ }
179
+ export async function shiftsPatchShift(event, entry, patch) {
180
+ const { shift, schedule } = entry;
181
+ const values = {};
182
+ const teamId = patch.teamId ?? shift.teamId;
183
+ if (patch.teamId !== void 0 && patch.teamId !== shift.teamId) {
184
+ await shiftsOperationTeamOr400(schedule.operationId, patch.teamId);
185
+ values.teamId = patch.teamId;
186
+ }
187
+ if (patch.shiftRoleId !== void 0 && patch.shiftRoleId !== shift.shiftRoleId) {
188
+ if (patch.shiftRoleId) await shiftsRoleOfOr400(schedule.id, teamId, patch.shiftRoleId);
189
+ values.shiftRoleId = patch.shiftRoleId ?? null;
190
+ } else if (values.teamId && shift.shiftRoleId) {
191
+ values.shiftRoleId = null;
192
+ }
193
+ if ((values.teamId || values.shiftRoleId !== void 0) && await shiftsHaveActive(shift.id)) {
194
+ throw apiError(409, "shift_in_use", "People are assigned to this shift. Cancel their assignments before moving it to another team or role.");
195
+ }
196
+ const startsAt = patch.startsAt ?? shift.startsAt;
197
+ const endsAt = patch.endsAt ?? shift.endsAt;
198
+ if (endsAt.getTime() <= startsAt.getTime()) throw validationError([{ path: ["endsAt"], message: "A shift must end after it starts." }]);
199
+ if (patch.startsAt) values.startsAt = patch.startsAt;
200
+ if (patch.endsAt) values.endsAt = patch.endsAt;
201
+ if (patch.capacity !== void 0) values.capacity = patch.capacity;
202
+ if (patch.location !== void 0) values.location = patch.location;
203
+ if (patch.notes !== void 0) values.notes = patch.notes && (typeof patch.notes !== "string" || patch.notes) ? patch.notes : null;
204
+ const previous = toShiftDto(shift, schedule);
205
+ if (!Object.keys(values).length) return previous;
206
+ const [row] = await db.update(schema.shifts).set(values).where(eq(schema.shifts.id, shift.id)).returning();
207
+ const dto = toShiftDto(row, schedule);
208
+ await shiftsFire("shifts:shift:updated", { event, shift: dto, previous });
209
+ return dto;
210
+ }
211
+ async function shiftsHaveActive(shiftId) {
212
+ const [row] = await db.select({ id: schema.shiftAssignments.id }).from(schema.shiftAssignments).where(and(eq(schema.shiftAssignments.shiftId, shiftId), inArray(schema.shiftAssignments.status, [...ACTIVE_ASSIGNMENT_STATUSES]))).limit(1);
213
+ return !!row;
214
+ }
215
+ export async function shiftsDeleteShift(entry) {
216
+ if (await shiftsHaveAttendance([entry.shift.id])) throw apiError(409, "shift_in_use", "People are assigned to this shift. Cancel their assignments first.");
217
+ await shiftsDeleteShiftRows([entry.shift.id]);
218
+ }
219
+ export async function shiftsScheduleShifts(schedule, query, pii) {
220
+ const rows = await db.select().from(schema.shifts).where(and(
221
+ eq(schema.shifts.scheduleId, schedule.id),
222
+ query.teamId ? eq(schema.shifts.teamId, query.teamId) : void 0,
223
+ query.from ? gte(schema.shifts.endsAt, query.from) : void 0,
224
+ query.to ? lt(schema.shifts.startsAt, query.to) : void 0
225
+ )).orderBy(asc(schema.shifts.startsAt), asc(schema.shifts.id)).limit(2e3);
226
+ return shiftsWithAssignees(rows, /* @__PURE__ */ new Map([[schedule.id, schedule]]), pii);
227
+ }
228
+ export async function shiftsWithAssignees(rows, schedules, pii) {
229
+ if (!rows.length) return [];
230
+ const [chunks, teams] = await Promise.all([
231
+ Promise.all(chunkParams(rows.map((row) => row.id)).map((part) => db.select().from(schema.shiftAssignments).where(and(
232
+ inArray(schema.shiftAssignments.shiftId, part),
233
+ ne(schema.shiftAssignments.status, "cancelled")
234
+ )))),
235
+ shiftsTeamsById(rows.map((row) => row.teamId))
236
+ ]);
237
+ const assignments = chunks.flat().sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime() || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
238
+ const assignees = await shiftsAssigneeDtos(assignments, pii);
239
+ return rows.map((row) => {
240
+ const own = assignees.filter((item) => item.shiftId === row.id);
241
+ return {
242
+ ...toShiftDto(row, schedules.get(row.scheduleId)),
243
+ teamName: teams.get(row.teamId)?.name ?? row.teamId,
244
+ assignees: own,
245
+ filled: own.filter((item) => item.status === "assigned" || item.status === "attended").length
246
+ };
247
+ });
248
+ }
249
+ export async function shiftsCopyFrom(event, target, sourceId, offsetDays) {
250
+ if (sourceId === target.id) throw validationError([{ path: ["scheduleId"], message: "Pick another schedule to copy from." }]);
251
+ const source = await getShiftScheduleOr404(sourceId).catch(() => {
252
+ throw validationError([{ path: ["scheduleId"], message: "This schedule does not exist." }], "Unknown schedule");
253
+ });
254
+ const [roles, shifts] = await Promise.all([
255
+ db.select().from(schema.shiftRoles).where(eq(schema.shiftRoles.scheduleId, source.id)).orderBy(asc(schema.shiftRoles.createdAt)),
256
+ db.select().from(schema.shifts).where(eq(schema.shifts.scheduleId, source.id)).orderBy(asc(schema.shifts.startsAt))
257
+ ]);
258
+ const teamMap = /* @__PURE__ */ new Map();
259
+ const sourceTeamIds = [.../* @__PURE__ */ new Set([...roles.map((role) => role.teamId), ...shifts.map((shift) => shift.teamId)])];
260
+ if (source.operationId === target.operationId) {
261
+ for (const id of sourceTeamIds) teamMap.set(id, id);
262
+ } else {
263
+ const [sourceTeams, targetTeams2] = await Promise.all([
264
+ shiftsTeamsById(sourceTeamIds),
265
+ db.select().from(schema.teams).where(and(eq(schema.teams.ownerType, "operation"), eq(schema.teams.ownerId, target.operationId)))
266
+ ]);
267
+ const key = (name) => JSON.stringify(name);
268
+ for (const [id, team] of sourceTeams) {
269
+ const match = targetTeams2.find((candidate) => key(candidate.name) === key(team.name) && candidate.kind === team.kind) ?? targetTeams2.find((candidate) => key(candidate.name) === key(team.name));
270
+ if (match) teamMap.set(id, match.id);
271
+ }
272
+ }
273
+ const skippedTeamIds = sourceTeamIds.filter((id) => !teamMap.has(id));
274
+ const roleMap = /* @__PURE__ */ new Map();
275
+ const changedRoleIds = [];
276
+ const targetTeams = await shiftsTeamsById([...teamMap.values()]);
277
+ const ladders = await loadTeamLadders(event);
278
+ for (const role of roles) {
279
+ const teamId = teamMap.get(role.teamId);
280
+ if (!teamId) continue;
281
+ let teamRole = role.teamRole;
282
+ const keys = ladders[targetTeams.get(teamId)?.kind ?? ""]?.roles.map((item) => item.key) ?? [];
283
+ if (teamRole && !keys.includes(teamRole)) {
284
+ teamRole = null;
285
+ changedRoleIds.push(role.id);
286
+ }
287
+ const id = newId("shr");
288
+ roleMap.set(role.id, id);
289
+ await db.insert(schema.shiftRoles).values({ id, scheduleId: target.id, teamId, teamRole, name: role.name });
290
+ }
291
+ const { timeZone } = shiftsConfig(event);
292
+ const values = shifts.flatMap((shift) => {
293
+ const teamId = teamMap.get(shift.teamId);
294
+ if (!teamId) return [];
295
+ return [{
296
+ id: newId("shf"),
297
+ scheduleId: target.id,
298
+ teamId,
299
+ shiftRoleId: shift.shiftRoleId ? roleMap.get(shift.shiftRoleId) ?? null : null,
300
+ startsAt: shiftByDays(shift.startsAt, offsetDays, timeZone),
301
+ endsAt: shiftByDays(shift.endsAt, offsetDays, timeZone),
302
+ capacity: shift.capacity,
303
+ location: shift.location,
304
+ notes: shift.notes
305
+ }];
306
+ });
307
+ const created = [];
308
+ for (const part of chunkParams(values, SHIFT_INSERT_ROWS)) created.push(...await db.insert(schema.shifts).values(part).returning());
309
+ const [updated] = await db.update(schema.shiftSchedules).set({ coverage: source.coverage, handover: source.handover, approval: source.approval }).where(eq(schema.shiftSchedules.id, target.id)).returning();
310
+ for (const row of created) await shiftsFire("shifts:shift:created", { event, shift: toShiftDto(row, target) });
311
+ return { schedule: toShiftScheduleDto(updated ?? target, void 0, event), roles: roleMap.size, shifts: created.length, skippedTeamIds, changedRoleIds };
312
+ }
@@ -0,0 +1,89 @@
1
+ import type { H3Event } from 'h3';
2
+ import { schema } from '@nuxthub/db';
3
+ import type { ShiftAssignResultDto, ShiftCheckInDto, ShiftSelfCheckInDto, ShiftSelfCheckInInput } from '../../../types.js';
4
+ import type { ShiftAssignmentRow } from './shifts-dto.js';
5
+ import type { ShiftAssignmentEntry, ShiftEntry } from './shifts-core.js';
6
+ /** When the QR pass of a shift shows and check-in is open: `checkInOpensMinutes` before it starts until it ends. */
7
+ export declare function shiftsPassWindow(event: H3Event | undefined, shift: {
8
+ startsAt: Date;
9
+ endsAt: Date;
10
+ }): {
11
+ opensAt: Date;
12
+ closesAt: Date;
13
+ };
14
+ /** Whether check-in is open now for a shift. */
15
+ export declare function shiftsCheckInOpen(event: H3Event | undefined, shift: {
16
+ startsAt: Date;
17
+ endsAt: Date;
18
+ }, now?: Date): boolean;
19
+ /**
20
+ * Writes an assignment only while it still has the status the caller read (a conditional update). `undefined` when
21
+ * somebody else changed it first. Fires nothing.
22
+ */
23
+ export declare function shiftsWriteAssignment(before: ShiftAssignmentRow, patch: Partial<typeof schema.shiftAssignments.$inferInsert>): Promise<ShiftAssignmentRow | undefined>;
24
+ /**
25
+ * Assigns a person to a shift (staff). The person must be eligible (an explicit role on the shift's team, and the shift
26
+ * role's minimum team role): 409 `not_eligible` otherwise, and 409 `already_assigned` when they hold the shift already.
27
+ * A full shift is a 409 `shift_full` unless `force`. The guards never block: they come back as `warnings`. The capacity
28
+ * and the one-place-per-person rule are checked again after the insert, so two requests at once cannot overfill the
29
+ * shift or assign a person twice: the insert that lost is taken back. Fires `shifts:assignment:changed` with
30
+ * `previous: null`.
31
+ */
32
+ export declare function shiftsAssign(event: H3Event, entry: ShiftEntry, input: {
33
+ userId: number;
34
+ shiftRoleId?: string | null;
35
+ force?: boolean;
36
+ }, by: number | null, pii: boolean): Promise<ShiftAssignResultDto>;
37
+ /**
38
+ * Cancels an assignment (staff, or a person leaving the team). `assigned` and `no_show` can be cancelled; an attended
39
+ * shift cannot (409 `invalid_transition`); a cancelled one is a no-op. Its live swap is cancelled, and offers that gave
40
+ * it back are withdrawn. Fires `shifts:assignment:changed`.
41
+ */
42
+ export declare function shiftsCancelAssignment(event: H3Event, entry: ShiftAssignmentEntry): Promise<ShiftAssignmentRow>;
43
+ /**
44
+ * Marks attendance (a lead of the team, or staff; `by: null` with `auto: true` is the system, the auto no-show of the
45
+ * `shifts:close-shifts` task, with no request): `attended` (the check-in time is kept, or set now) or `no_show`.
46
+ * Asking for the status it has is a no-op; a move the status table does not allow is a 409 `invalid_transition`.
47
+ * Marking an ended shift attended gives out its perks at once; a flip from `attended` to `no_show` revokes the earned
48
+ * perks nobody claimed yet. Fires `shifts:attendance:marked` and `shifts:assignment:changed` when it changed (with `auto`).
49
+ */
50
+ export declare function shiftsMarkAttendance(event: H3Event | undefined, entry: ShiftAssignmentEntry, to: 'attended' | 'no_show', by: number | null, options?: {
51
+ auto?: boolean;
52
+ now?: Date;
53
+ }): Promise<ShiftAssignmentRow>;
54
+ /**
55
+ * The `daily` mode: when this is the person's first check-in of the day (in the module's time zone), their other shifts
56
+ * starting that day whose check-in window is open now, whose team's rule has `daily` and that they still hold
57
+ * (`assigned`, no check-in) are checked in too, with `method: 'daily'`. Shifts whose window opens later need a check-in
58
+ * of their own. Returns the assignment ids it checked in.
59
+ */
60
+ export declare function shiftsDailyCascade(event: H3Event | undefined, first: ShiftAssignmentRow, by: number, now: Date): Promise<string[]>;
61
+ /** The assignment (with its shift and schedule) a QR pass code belongs to, if any. */
62
+ export declare function shiftsAssignmentByCode(code: string): Promise<ShiftAssignmentEntry | undefined>;
63
+ /**
64
+ * Checks a person in with the code of their QR pass, for a team (a lead of it, or staff). An unknown code, or a code of
65
+ * another team's shift, is a 404 (a lead learns nothing about other teams). A cancelled assignment is a 409
66
+ * `assignment_cancelled`; outside the check-in window a 409 `outside_window`. Scanning twice is fine: the second scan
67
+ * reports `alreadyCheckedIn` with the first scan's time. Fires `shifts:attendance:marked` once.
68
+ */
69
+ export declare function shiftsCheckIn(event: H3Event, teamId: string, code: string, by: number, pii: boolean): Promise<ShiftCheckInDto>;
70
+ /**
71
+ * A volunteer checks in on one of their own shifts (`POST /api/shifts/me/:assignmentId/check-in`), by a mode the
72
+ * team's rule has on (409 `mode_disabled` otherwise):
73
+ * - `station`: the token of a station's QR code. A token that is not one, or whose signature does not verify, is a 400
74
+ * `invalid_token`; one older than the previous 30 second window a 409 `token_expired`; a station of another team or
75
+ * schedule a 409 `wrong_station`.
76
+ * - `location`: the device's position and accuracy. Without a place set, 409 `no_location`; an accuracy worse than the
77
+ * radius 409 `inaccurate_position`; outside the place 409 `outside_location` (with the distance and radius).
78
+ * Then, like a lead's scan: a cancelled assignment is a 409 `assignment_cancelled`, somebody who lost their role 409
79
+ * `not_eligible`, outside the check-in window 409 `outside_window`. A second check-in (a replayed token, a second tap)
80
+ * answers `alreadyCheckedIn` and changes nothing. The first check-in of the day runs the `daily` mode.
81
+ */
82
+ export declare function shiftsSelfCheckIn(event: H3Event, entry: ShiftAssignmentEntry, input: ShiftSelfCheckInInput, now?: Date): Promise<ShiftSelfCheckInDto>;
83
+ /**
84
+ * Cancels a person's future `assigned` assignments on a team (they left it, or their role no longer meets the shift
85
+ * role: `keep` decides per assignment). Each one fires `shifts:assignment:changed` and cancels its swap.
86
+ */
87
+ export declare function shiftsCancelFutureAssignments(event: H3Event, userId: number, teamId: string, keep?: (row: ShiftAssignmentRow) => Promise<boolean> | boolean): Promise<number>;
88
+ /** Whether a person still meets the shift role of an assignment with the team role they hold now. */
89
+ export declare function shiftsStillEligible(event: H3Event | undefined, assignment: ShiftAssignmentRow, teamId: string): Promise<boolean>;