@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,12 @@
1
+ import type { H3Event } from 'h3';
2
+ import type { MapLiveFeatureCollection } from '@frigear-nu/maps/utils';
3
+ /**
4
+ * The `shifts.on-duty` live layer of an operation: one point per team and shift location, at the anchor of the venue
5
+ * layout's feature the location names (a point as it is, a line at its middle, an area at its centroid). `count` is
6
+ * how many people of the team are on shift there now; `leads` (the names of the leads on duty) only with `pii`.
7
+ * Shifts without a location, or naming a feature the layout does not have, are left out.
8
+ */
9
+ export declare function shiftsOnDutyLayer(event: H3Event, operation: {
10
+ id: string;
11
+ venueLayout?: unknown;
12
+ }, pii: boolean, at?: Date): Promise<MapLiveFeatureCollection>;
@@ -0,0 +1,37 @@
1
+ import { geometryAnchor } from "@frigear-nu/maps/utils";
2
+ export async function shiftsOnDutyLayer(event, operation, pii, at = /* @__PURE__ */ new Date()) {
3
+ const layout = operation.venueLayout;
4
+ const anchors = new Map((layout?.features ?? []).map((feature) => [feature.id, geometryAnchor(feature.geometry)]));
5
+ if (!anchors.size) return { type: "FeatureCollection", features: [] };
6
+ const now = await shiftsNow(event, operation.id, false, at);
7
+ const spots = /* @__PURE__ */ new Map();
8
+ for (const team of now.teams) {
9
+ const leadNames = new Map(team.leads.map((lead) => [lead.userId, lead.name]));
10
+ for (const shift of team.shifts) {
11
+ const featureId = shift.location?.featureId;
12
+ if (!featureId || !anchors.get(featureId)) continue;
13
+ const key = `${team.teamId}:${featureId}`;
14
+ let spot = spots.get(key);
15
+ if (!spot) spots.set(key, spot = { teamId: team.teamId, team: team.teamName, featureId, people: /* @__PURE__ */ new Set(), leads: /* @__PURE__ */ new Map() });
16
+ for (const assignee of shift.assignees) {
17
+ spot.people.add(assignee.userId);
18
+ if (leadNames.has(assignee.userId)) spot.leads.set(assignee.userId, leadNames.get(assignee.userId) ?? null);
19
+ }
20
+ }
21
+ }
22
+ const features = [...spots.entries()].map(([key, spot]) => ({
23
+ type: "Feature",
24
+ id: key,
25
+ geometry: { type: "Point", coordinates: anchors.get(spot.featureId) },
26
+ properties: {
27
+ label: spot.team,
28
+ teamId: spot.teamId,
29
+ featureId: spot.featureId,
30
+ count: spot.people.size,
31
+ leadsOnDuty: spot.leads.size,
32
+ // The names of the leads on duty only for staff who may see people's details.
33
+ ...pii ? { leads: [...spot.leads.values()].filter((name) => !!name) } : {}
34
+ }
35
+ }));
36
+ return { type: "FeatureCollection", features };
37
+ }
@@ -0,0 +1,46 @@
1
+ import type { H3Event } from 'h3';
2
+ import type { z } from 'zod';
3
+ import type { ShiftPassPerkDto, ShiftPerkDto, ShiftEarnedPerkDto } from '../../../types.js';
4
+ import type { ShiftAssignmentRow, ShiftEarnedPerkRow, ShiftPerkRow, ShiftRow, ShiftScheduleRow } from './shifts-dto.js';
5
+ import type { ShiftAssignmentEntry } from './shifts-core.js';
6
+ import type { shiftsPerkInput, shiftsPerkPatch } from './shifts-schemas.js';
7
+ type PerkInput = z.output<typeof shiftsPerkInput>;
8
+ type PerkPatch = z.output<typeof shiftsPerkPatch>;
9
+ export declare function getShiftPerkOr404(id: string): Promise<ShiftPerkRow>;
10
+ /** An operation's perks, oldest first, with how many times it was earned (revoked ones left out). */
11
+ export declare function shiftsListPerks(operationId: string): Promise<ShiftPerkDto[]>;
12
+ /** Creates a perk of an operation, for one of its teams or all of them. */
13
+ export declare function shiftsCreatePerk(operationId: string, input: PerkInput): Promise<ShiftPerkRow>;
14
+ /** Changes a perk. Perks earned before keep the voucher type and quantity they were made with. */
15
+ export declare function shiftsPatchPerk(existing: ShiftPerkRow, patch: PerkPatch): Promise<ShiftPerkRow>;
16
+ /** Deletes a perk nobody earned yet; 409 `perk_already_earned` once someone earned it (even if it was revoked). */
17
+ export declare function shiftsDeletePerk(existing: ShiftPerkRow): Promise<void>;
18
+ /**
19
+ * Gives out the perks of attended assignments of ended shifts. Idempotent: the unique `(perkId, assignmentId)` key makes a
20
+ * second run (or a lead's mark racing the task) insert nothing; an earned perk revoked by an earlier `no_show` comes back to
21
+ * the person holding the assignment now. Assignments not `attended` or of shifts that have not ended are skipped.
22
+ * Fires `shifts:perk:earned` for every earned perk that was new or came back. Returns how many.
23
+ */
24
+ export declare function shiftsEarnPerks(event: H3Event | undefined, entries: Array<{
25
+ assignment: ShiftAssignmentRow;
26
+ shift: ShiftRow;
27
+ schedule: Pick<ShiftScheduleRow, 'operationId'>;
28
+ }>, now?: Date): Promise<number>;
29
+ /** Revokes the unclaimed earned perks of an assignment (a flip to `no_show`); claimed ones stay. Fires `shifts:perk:revoked`. */
30
+ export declare function shiftsRevokeEarnedPerks(event: H3Event | undefined, assignmentId: string): Promise<number>;
31
+ /** The assignments (of `ids`) with a claimed earned perk: a no-show among them is flagged to the lead. */
32
+ export declare function shiftsClaimedAssignmentIds(ids: string[]): Promise<Set<string>>;
33
+ /** What a shift earns, on the pass: each perk that applies, `upcoming` until earned, then the earned perk's state. */
34
+ export declare function shiftsPassPerks(entry: ShiftAssignmentEntry): Promise<ShiftPassPerkDto[]>;
35
+ /** The language of the perk, team and operation names: the first tag of `Accept-Language`, else `en`. */
36
+ export declare function shiftsRequestLocale(event: H3Event): string;
37
+ /** A person's earned perks, oldest first: `unclaimed` (the default), `claimed` or `all`. Revoked ones are never listed. */
38
+ export declare function shiftsMyEarnedPerks(userId: number, status: 'unclaimed' | 'claimed' | 'all', locale: string): Promise<ShiftEarnedPerkDto[]>;
39
+ /** One of the person's earned perks: someone else's is a 404, like an unknown one. */
40
+ export declare function shiftsMyEarnedPerkOr404(userId: number, id: string): Promise<ShiftEarnedPerkRow>;
41
+ /**
42
+ * Claims an earned perk for a client (a conditional write: two claims at once set `claimedAt` once). Idempotent: a
43
+ * claimed one answers again with the same `claimedAt`. A revoked one is a 409 `perk_revoked`.
44
+ */
45
+ export declare function shiftsClaimEarnedPerk(earned: ShiftEarnedPerkRow, client: string | undefined, locale: string): Promise<ShiftEarnedPerkDto>;
46
+ export {};
@@ -0,0 +1,183 @@
1
+ import { db, schema } from "@nuxthub/db";
2
+ import { and, asc, count, eq, inArray, isNotNull, isNull, or } from "drizzle-orm";
3
+ import { apiError, chunkParams, isoDate, notFound } from "@frigear-nu/module-kit/server";
4
+ import { newId, translate } from "../../utils/index.js";
5
+ import { toShiftPerkDto } from "./shifts-dto.js";
6
+ import { shiftsFire, shiftsOperationTeamOr400 } from "./shifts-core.js";
7
+ export async function getShiftPerkOr404(id) {
8
+ const [row] = await db.select().from(schema.shiftPerks).where(eq(schema.shiftPerks.id, id)).limit(1);
9
+ if (!row) throw notFound("Perk not found.");
10
+ return row;
11
+ }
12
+ export async function shiftsListPerks(operationId) {
13
+ const rows = await db.select().from(schema.shiftPerks).where(eq(schema.shiftPerks.operationId, operationId)).orderBy(asc(schema.shiftPerks.createdAt), asc(schema.shiftPerks.id)).limit(90);
14
+ if (!rows.length) return [];
15
+ const counts = await db.select({ perkId: schema.shiftEarnedPerks.perkId, total: count() }).from(schema.shiftEarnedPerks).where(and(inArray(schema.shiftEarnedPerks.perkId, rows.map((row) => row.id)), isNull(schema.shiftEarnedPerks.revokedAt))).groupBy(schema.shiftEarnedPerks.perkId);
16
+ const byId = new Map(counts.map((row) => [row.perkId, Number(row.total)]));
17
+ return rows.map((row) => toShiftPerkDto(row, byId.get(row.id) ?? 0));
18
+ }
19
+ export async function shiftsCreatePerk(operationId, input) {
20
+ if (input.teamId) await shiftsOperationTeamOr400(operationId, input.teamId);
21
+ const [row] = await db.insert(schema.shiftPerks).values({
22
+ id: newId("spk"),
23
+ operationId,
24
+ teamId: input.teamId ?? null,
25
+ name: input.name,
26
+ voucherType: input.voucherType,
27
+ quantity: input.quantity
28
+ }).returning();
29
+ return row;
30
+ }
31
+ export async function shiftsPatchPerk(existing, patch) {
32
+ const values = {};
33
+ if (patch.teamId !== void 0) {
34
+ if (patch.teamId) await shiftsOperationTeamOr400(existing.operationId, patch.teamId);
35
+ values.teamId = patch.teamId;
36
+ }
37
+ if (patch.name !== void 0) values.name = patch.name;
38
+ if (patch.voucherType !== void 0) values.voucherType = patch.voucherType;
39
+ if (patch.quantity !== void 0) values.quantity = patch.quantity;
40
+ if (!Object.keys(values).length) return existing;
41
+ const [row] = await db.update(schema.shiftPerks).set(values).where(eq(schema.shiftPerks.id, existing.id)).returning();
42
+ return row;
43
+ }
44
+ export async function shiftsDeletePerk(existing) {
45
+ const [earned] = await db.select({ id: schema.shiftEarnedPerks.id }).from(schema.shiftEarnedPerks).where(eq(schema.shiftEarnedPerks.perkId, existing.id)).limit(1);
46
+ if (earned) throw apiError(409, "perk_already_earned", "People earned this perk already. Change it instead of deleting it.");
47
+ await db.delete(schema.shiftPerks).where(eq(schema.shiftPerks.id, existing.id));
48
+ }
49
+ async function shiftsTeamPerksRows(operationId, teamId) {
50
+ return db.select().from(schema.shiftPerks).where(and(
51
+ eq(schema.shiftPerks.operationId, operationId),
52
+ or(isNull(schema.shiftPerks.teamId), eq(schema.shiftPerks.teamId, teamId))
53
+ )).orderBy(asc(schema.shiftPerks.createdAt), asc(schema.shiftPerks.id));
54
+ }
55
+ export async function shiftsEarnPerks(event, entries, now = /* @__PURE__ */ new Date()) {
56
+ const due = entries.filter((entry) => entry.assignment.status === "attended" && entry.shift.endsAt.getTime() <= now.getTime());
57
+ if (!due.length) return 0;
58
+ const perksByTeam = /* @__PURE__ */ new Map();
59
+ let earnedCount = 0;
60
+ for (const { assignment, shift, schedule } of due) {
61
+ const key = `${schedule.operationId}:${shift.teamId}`;
62
+ let perks = perksByTeam.get(key);
63
+ if (!perks) perksByTeam.set(key, perks = await shiftsTeamPerksRows(schedule.operationId, shift.teamId));
64
+ if (!perks.length) continue;
65
+ const restored = await db.update(schema.shiftEarnedPerks).set({ revokedAt: null, userId: assignment.userId }).where(and(
66
+ eq(schema.shiftEarnedPerks.assignmentId, assignment.id),
67
+ isNotNull(schema.shiftEarnedPerks.revokedAt)
68
+ )).returning();
69
+ const inserted = [];
70
+ for (const part of chunkParams(perks, 10)) {
71
+ inserted.push(...await db.insert(schema.shiftEarnedPerks).values(part.map((perk) => ({
72
+ id: newId("spg"),
73
+ perkId: perk.id,
74
+ assignmentId: assignment.id,
75
+ userId: assignment.userId,
76
+ voucherType: perk.voucherType,
77
+ quantity: perk.quantity,
78
+ earnedAt: now
79
+ }))).onConflictDoNothing().returning());
80
+ }
81
+ for (const earned of [...restored, ...inserted]) {
82
+ earnedCount++;
83
+ await shiftsFire("shifts:perk:earned", { event, earnedPerkId: earned.id, perkId: earned.perkId, assignmentId: earned.assignmentId, userId: earned.userId });
84
+ }
85
+ }
86
+ return earnedCount;
87
+ }
88
+ export async function shiftsRevokeEarnedPerks(event, assignmentId) {
89
+ const revoked = await db.update(schema.shiftEarnedPerks).set({ revokedAt: /* @__PURE__ */ new Date() }).where(and(
90
+ eq(schema.shiftEarnedPerks.assignmentId, assignmentId),
91
+ isNull(schema.shiftEarnedPerks.claimedAt),
92
+ isNull(schema.shiftEarnedPerks.revokedAt)
93
+ )).returning();
94
+ for (const earned of revoked) await shiftsFire("shifts:perk:revoked", { event, earnedPerkId: earned.id, perkId: earned.perkId, assignmentId: earned.assignmentId, userId: earned.userId });
95
+ return revoked.length;
96
+ }
97
+ export async function shiftsClaimedAssignmentIds(ids) {
98
+ const rows = (await Promise.all(chunkParams(ids).map((part) => db.select({ assignmentId: schema.shiftEarnedPerks.assignmentId }).from(schema.shiftEarnedPerks).where(and(inArray(schema.shiftEarnedPerks.assignmentId, part), isNotNull(schema.shiftEarnedPerks.claimedAt)))))).flat();
99
+ return new Set(rows.map((row) => row.assignmentId));
100
+ }
101
+ export async function shiftsPassPerks(entry) {
102
+ const perks = await shiftsTeamPerksRows(entry.schedule.operationId, entry.shift.teamId);
103
+ if (!perks.length) return [];
104
+ const earnedPerks = await db.select().from(schema.shiftEarnedPerks).where(eq(schema.shiftEarnedPerks.assignmentId, entry.assignment.id));
105
+ const byPerk = new Map(earnedPerks.map((earned) => [earned.perkId, earned]));
106
+ return perks.map((perk) => {
107
+ const earned = byPerk.get(perk.id);
108
+ const status = !earned ? "upcoming" : earned.revokedAt ? "revoked" : earned.claimedAt ? "claimed" : "earned";
109
+ return { perkId: perk.id, name: perk.name, voucherType: earned?.voucherType ?? perk.voucherType, quantity: earned?.quantity ?? perk.quantity, status };
110
+ });
111
+ }
112
+ export function shiftsRequestLocale(event) {
113
+ const header = getRequestHeader(event, "accept-language") ?? "";
114
+ const tag = header.split(",")[0]?.split(";")[0]?.trim().toLowerCase();
115
+ return tag ? tag.split("-")[0] : "en";
116
+ }
117
+ const MAX_EARNED_PERKS = 1e3;
118
+ async function shiftsEarnedPerkDtos(rows, locale) {
119
+ if (!rows.length) return [];
120
+ const joined = (await Promise.all(chunkParams(rows.map((row) => row.id)).map((part) => db.select({
121
+ id: schema.shiftEarnedPerks.id,
122
+ perkName: schema.shiftPerks.name,
123
+ shiftId: schema.shifts.id,
124
+ startsAt: schema.shifts.startsAt,
125
+ endsAt: schema.shifts.endsAt,
126
+ teamName: schema.teams.name,
127
+ operationName: schema.operations.name
128
+ }).from(schema.shiftEarnedPerks).innerJoin(schema.shiftPerks, eq(schema.shiftPerks.id, schema.shiftEarnedPerks.perkId)).innerJoin(schema.shiftAssignments, eq(schema.shiftAssignments.id, schema.shiftEarnedPerks.assignmentId)).innerJoin(schema.shifts, eq(schema.shifts.id, schema.shiftAssignments.shiftId)).innerJoin(schema.teams, eq(schema.teams.id, schema.shifts.teamId)).innerJoin(schema.operations, eq(schema.operations.id, schema.shiftPerks.operationId)).where(inArray(schema.shiftEarnedPerks.id, part))))).flat();
129
+ const byId = new Map(joined.map((row) => [row.id, row]));
130
+ return rows.flatMap((row) => {
131
+ const extra = byId.get(row.id);
132
+ if (!extra) return [];
133
+ return [{
134
+ id: row.id,
135
+ voucherType: row.voucherType,
136
+ quantity: row.quantity,
137
+ perkName: translate(extra.perkName, locale, "en"),
138
+ earnedAt: isoDate(row.earnedAt),
139
+ claimedAt: isoDate(row.claimedAt),
140
+ shift: {
141
+ id: extra.shiftId,
142
+ startsAt: isoDate(extra.startsAt),
143
+ endsAt: isoDate(extra.endsAt),
144
+ teamName: translate(extra.teamName, locale, "en"),
145
+ operationName: translate(extra.operationName, locale, "en")
146
+ }
147
+ }];
148
+ });
149
+ }
150
+ export async function shiftsMyEarnedPerks(userId, status, locale) {
151
+ const rows = await db.select().from(schema.shiftEarnedPerks).where(and(
152
+ eq(schema.shiftEarnedPerks.userId, userId),
153
+ isNull(schema.shiftEarnedPerks.revokedAt),
154
+ status === "unclaimed" ? isNull(schema.shiftEarnedPerks.claimedAt) : status === "claimed" ? isNotNull(schema.shiftEarnedPerks.claimedAt) : void 0
155
+ )).orderBy(asc(schema.shiftEarnedPerks.earnedAt), asc(schema.shiftEarnedPerks.id)).limit(MAX_EARNED_PERKS);
156
+ return shiftsEarnedPerkDtos(rows, locale);
157
+ }
158
+ export async function shiftsMyEarnedPerkOr404(userId, id) {
159
+ const [row] = await db.select().from(schema.shiftEarnedPerks).where(and(eq(schema.shiftEarnedPerks.id, id), eq(schema.shiftEarnedPerks.userId, userId))).limit(1);
160
+ if (!row) throw notFound("Earned perk not found.");
161
+ return row;
162
+ }
163
+ export async function shiftsClaimEarnedPerk(earned, client, locale) {
164
+ if (earned.revokedAt) throw apiError(409, "perk_revoked", "This perk was revoked: the shift was marked a no-show.");
165
+ let row = earned;
166
+ if (!earned.claimedAt) {
167
+ const [claimed] = await db.update(schema.shiftEarnedPerks).set({ claimedAt: /* @__PURE__ */ new Date(), claimClient: client ?? null }).where(and(
168
+ eq(schema.shiftEarnedPerks.id, earned.id),
169
+ isNull(schema.shiftEarnedPerks.claimedAt),
170
+ isNull(schema.shiftEarnedPerks.revokedAt)
171
+ )).returning();
172
+ if (claimed) row = claimed;
173
+ else {
174
+ const [current] = await db.select().from(schema.shiftEarnedPerks).where(eq(schema.shiftEarnedPerks.id, earned.id)).limit(1);
175
+ if (!current) throw notFound("Earned perk not found.");
176
+ if (current.revokedAt) throw apiError(409, "perk_revoked", "This perk was revoked: the shift was marked a no-show.");
177
+ row = current;
178
+ }
179
+ }
180
+ const [dto] = await shiftsEarnedPerkDtos([row], locale);
181
+ if (!dto) throw notFound("Earned perk not found.");
182
+ return dto;
183
+ }
@@ -0,0 +1,30 @@
1
+ import type { H3Event } from 'h3';
2
+ export type ShiftsReminderRunDto = {
3
+ /** The due assignments this run took (at most `batchSize`, soonest shift first). */
4
+ checked: number;
5
+ /** Reminders that went out (one per assignment and run). */
6
+ sent: number;
7
+ /** Reminder rows spent without a message: a larger offset that fell due together with a smaller one, or a person who no longer holds their role. */
8
+ spent: number;
9
+ };
10
+ /**
11
+ * Sends the reminders that are due at `now` (the `shifts:send-reminders` task, every ten minutes by default): for each
12
+ * `assigned` assignment of a published schedule whose shift lies ahead, every configured offset (`reminders.offsets`,
13
+ * minutes before the start) whose moment has passed is due. Each is claimed by inserting a `shift_reminders` row (the
14
+ * unique `(assignmentId, offsetMinutes)` key makes the loser of two runs at once send nothing) and then sent. When
15
+ * several offsets are due together (a late run, or a person assigned inside the window) one message goes out, for the
16
+ * smallest, and the others are spent without one. A failed send keeps its row: a broken address is not retried every
17
+ * run. A person who no longer holds their role on the team gets nothing, and their due offsets are spent so they do not
18
+ * crowd later runs. Through `shiftsNotify`: the email and push notification, and the SMS only with `reminders.sms` and a phone number. The person's own choice for the `shifts.reminder` topic decides which of them go out. The message names the real time left,
19
+ * in the person's language. Fires `shifts:reminder:sent` (`event` is always `undefined` when the task fires it).
20
+ *
21
+ * A run handles at most `reminders.batchSize` assignments (default 100), soonest shift first; rows with every due offset
22
+ * already claimed are left out in SQL, so the next run takes the rest. Every lookup by a list of ids is chunked below
23
+ * D1's 100 bound parameters. `override` replaces the module's `offsets`, `sms` and `batchSize` for one run (tests, a
24
+ * one-off run by hand).
25
+ */
26
+ export declare function shiftsSendReminders(now?: Date, event?: H3Event, override?: {
27
+ offsets?: number[];
28
+ sms?: boolean;
29
+ batchSize?: number;
30
+ }): Promise<ShiftsReminderRunDto>;
@@ -0,0 +1,102 @@
1
+ import { db, schema } from "@nuxthub/db";
2
+ import { and, asc, eq, gt, inArray, lte, notExists, or, sql } from "drizzle-orm";
3
+ import { newId, translate } from "../../utils/index.js";
4
+ import { dueReminderOffsets, normalizeReminderBatch, normalizeReminderOffsets, reminderOffsetToSend, timeLeftBucket } from "../../utils/reminders.js";
5
+ import { buildShiftReminderEmail, buildShiftReminderPush, buildShiftReminderSms, formatShiftWhen } from "../reminder-email.js";
6
+ import { toShiftAssignmentDto } from "./shifts-dto.js";
7
+ import { shiftsConfig, shiftsFire, shiftsLocalesOfMany, shiftsRolesByIds, shiftsTeamsById, shiftsUsersById } from "./shifts-core.js";
8
+ import { shiftsStillEligible } from "./shifts-assign.js";
9
+ import { shiftsNotify } from "./shifts-notify.js";
10
+ import { SHIFTS_TOPICS } from "../../notifications.js";
11
+ import { chunkParams } from "@frigear-nu/module-kit/server";
12
+ let shiftsWarnedNoOrigin = false;
13
+ export async function shiftsSendReminders(now = /* @__PURE__ */ new Date(), event, override = {}) {
14
+ const config = shiftsConfig(event);
15
+ const { timeZone } = config;
16
+ const reminders = {
17
+ offsets: override.offsets ? normalizeReminderOffsets(override.offsets) : config.reminders.offsets,
18
+ sms: override.sms ?? config.reminders.sms,
19
+ batchSize: override.batchSize ? normalizeReminderBatch(override.batchSize) : config.reminders.batchSize
20
+ };
21
+ const result = { checked: 0, sent: 0, spent: 0 };
22
+ if (!reminders.offsets.length) return result;
23
+ const dueSomething = or(...reminders.offsets.map((offset) => and(
24
+ lte(schema.shifts.startsAt, new Date(now.getTime() + offset * 6e4)),
25
+ notExists(db.select({ one: sql`1` }).from(schema.shiftReminders).where(and(
26
+ eq(schema.shiftReminders.assignmentId, schema.shiftAssignments.id),
27
+ eq(schema.shiftReminders.offsetMinutes, offset)
28
+ )))
29
+ )));
30
+ const rows = await db.select({ assignment: schema.shiftAssignments, shift: schema.shifts }).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(
31
+ eq(schema.shiftAssignments.status, "assigned"),
32
+ eq(schema.shiftSchedules.status, "published"),
33
+ gt(schema.shifts.startsAt, now),
34
+ dueSomething
35
+ )).orderBy(asc(schema.shifts.startsAt), asc(schema.shiftAssignments.id)).limit(reminders.batchSize);
36
+ result.checked = rows.length;
37
+ if (!rows.length) return result;
38
+ const claimed = (await Promise.all(chunkParams(rows.map((row) => row.assignment.id)).map((part) => db.select({ assignmentId: schema.shiftReminders.assignmentId, offsetMinutes: schema.shiftReminders.offsetMinutes }).from(schema.shiftReminders).where(inArray(schema.shiftReminders.assignmentId, part))))).flat();
39
+ const spentBefore = new Set(claimed.map((row) => `${row.assignmentId}:${row.offsetMinutes}`));
40
+ const [users, teams, roles, locales] = await Promise.all([
41
+ shiftsUsersById(rows.map((row) => row.assignment.userId)),
42
+ shiftsTeamsById(rows.map((row) => row.shift.teamId)),
43
+ shiftsRolesByIds(rows.map((row) => row.assignment.shiftRoleId)),
44
+ shiftsLocalesOfMany(rows.map((row) => ({ userId: row.assignment.userId, teamId: row.shift.teamId })))
45
+ ]);
46
+ const origin = configuredAuthSiteOrigin(event);
47
+ if (!origin && !shiftsWarnedNoOrigin) {
48
+ shiftsWarnedNoOrigin = true;
49
+ console.warn("[shifts] no site origin is configured: reminders go out without a link");
50
+ }
51
+ const shiftPath = useRuntimeConfig(event).public.shifts?.pages?.shift;
52
+ const claim = async (assignment, offset) => {
53
+ const [row] = await db.insert(schema.shiftReminders).values({ id: newId("srm"), assignmentId: assignment.id, offsetMinutes: offset, userId: assignment.userId }).onConflictDoNothing().returning({ id: schema.shiftReminders.id });
54
+ return !!row;
55
+ };
56
+ for (const { assignment, shift } of rows) {
57
+ const due = dueReminderOffsets(shift.startsAt, reminders.offsets, now).filter((offset) => !spentBefore.has(`${assignment.id}:${offset}`));
58
+ if (!due.length) continue;
59
+ try {
60
+ if (!await shiftsStillEligible(event, assignment, shift.teamId)) {
61
+ for (const offset of due) if (await claim(assignment, offset)) result.spent++;
62
+ continue;
63
+ }
64
+ const toSend = reminderOffsetToSend(dueReminderOffsets(shift.startsAt, reminders.offsets, now));
65
+ let winsSend = false;
66
+ for (const offset of due) {
67
+ if (!await claim(assignment, offset)) continue;
68
+ if (offset === toSend) winsSend = true;
69
+ else result.spent++;
70
+ }
71
+ if (!winsSend) continue;
72
+ const user = users.get(assignment.userId);
73
+ const locale = locales.get(`${assignment.userId}:${shift.teamId}`) ?? "en";
74
+ const role = assignment.shiftRoleId ? roles.get(assignment.shiftRoleId) : void 0;
75
+ const variables = {
76
+ name: user?.name ?? "",
77
+ team: translate(teams.get(shift.teamId)?.name ?? shift.teamId, locale, "en"),
78
+ role: role ? translate(role.name, locale, "en") : void 0,
79
+ when: formatShiftWhen(shift.startsAt, locale, timeZone),
80
+ where: shift.location?.name ? translate(shift.location.name, locale, "en") : void 0,
81
+ start: shift.startsAt.toISOString()
82
+ };
83
+ const left = timeLeftBucket(shift.startsAt, now);
84
+ const url = shiftPath && origin ? `${origin}${shiftPath.replace(":assignmentId", encodeURIComponent(assignment.id))}` : void 0;
85
+ const email = buildShiftReminderEmail({ email: user?.email ?? null, variables, offset: toSend, left, url, locale });
86
+ const sms = reminders.sms ? buildShiftReminderSms({ phone: user?.phone ?? null, variables, offset: toSend, left, url, locale }) : null;
87
+ const { channels } = await shiftsNotify(event, assignment.userId, {
88
+ topic: SHIFTS_TOPICS.reminder,
89
+ email,
90
+ sms,
91
+ push: buildShiftReminderPush({ variables, left, url, locale }),
92
+ label: `the reminder of assignment ${assignment.id}`
93
+ });
94
+ if (!channels.length) continue;
95
+ result.sent++;
96
+ await shiftsFire("shifts:reminder:sent", { event, assignment: toShiftAssignmentDto(assignment), offset: toSend, channels });
97
+ } catch (error) {
98
+ console.error(`[shifts] the reminder of assignment ${assignment.id} could not be handled`, error);
99
+ }
100
+ }
101
+ return result;
102
+ }