Volunteering

Shifts

Schedules, shift roles, assignment, swaps, check-in by pass, station or location, reminders, a calendar feed, broadcasts and earned perks, per operation, built on crew and teams.

Shifts is when people work an operation. Staff build a schedule of shifts for the operation's teams, publish it and put people on the shifts. Volunteers see their shifts, trade or give them away as far as the schedule allows, and check in: a lead of their team scans their QR pass, or they scan the rotating code of a station or check in by their location, as the schedule allows. They get reminders before a shift, can follow their shifts in a calendar app, and earn perks (two beers, a meal) for every shift they attend, which an app such as the vouchers app hands out. When a shift ends, a task gives out the perks, can mark the people who never turned up as no-shows, and sends the leads one digest of what needs a look. Coordinators and leads message a team. Everyone who takes part sees who is on shift now and which lead is on duty. The people come from Crew and Teams: a person can hold a shift when they hold a team role on its team. The operations themselves are in Operations.

The package is @frigear-nu/shifts.

What you get

  • Volunteer pages (on by default, each can be turned off): my shifts (a list by day and a month calendar, with Subscribe in calendar) and the open swaps, as the My shifts and Swaps tabs of the crew home of Crew (/dashboard/crew?tab=shifts, ?tab=swaps); one shift at /dashboard/crew/shifts/:assignmentId (the lead on duty, the QR pass with a countdown and a full-screen view, checking in at a station or by location, what the shift earns, and the swap); the page of a team's leads at /shifts/lead/:teamId (it opens on the exceptions, with Message team and the team's stations), their scanner at /shifts/check-in/:teamId, and a station's full-screen rotating QR code at /shifts/station/:stationId. With Mobile, a Shifts tab on my shifts.
  • Admin area (with Admin and Widget): a Shifts tab on the operation page of Operations. It lists the schedules and who is working now; a schedule opens with a timeline per day and team, a list, its shift roles, the swaps that wait for approval and its check-in (modes, the check-in place, automatic no-shows and the stations); a shift's form picks its place on the venue layout. Below the schedules, the operation's perks and its messages (the broadcasts sent, and the button to send one).
  • Server routes: my shifts, the pass, checking in myself and my swaps; my earned perks (for the vouchers app); the marketplace and offers; the lead's check-in, attendance, exceptions, stations, broadcasts and team view; who is on shift now; my calendar feed; and a staff API for schedules, roles, shifts, stations, assignments, swaps, perks and broadcasts.
  • Tasks: shifts:send-reminders emails people a day and two hours before a shift starts; shifts:close-shifts gives out the perks of ended shifts, marks automatic no-shows and sends the leads' digest.
  • Emails: the swap emails (on a new offer, an accepted or rejected offer, a completed swap, a swap that waits for approval and a trade aimed at somebody's shift; a trade's emails name both shifts), the reminder, the broadcast and the leads' digest.
  • Hooks: shifts:schedule:published, shifts:shift:created, shifts:shift:updated, shifts:assignment:changed, shifts:swap:offered, shifts:swap:accepted, shifts:swap:rejected, shifts:swap:completed, shifts:attendance:marked, shifts:reminder:sent, shifts:broadcast:sent, shifts:perk:earned, shifts:perk:revoked and shifts:digest:sent.
ServerClientMobile
Installed for you:Crew, Teams, Operations, Notify, Auth, Users, Maps, UI and Module Kit. You add:@nuxthub/core, and @nuxt/ui for the pages. Optional:Admin and Widget for the Shifts tab, Mobile for the tab, and Email Templates to render the emails from templates.

Quick setup

Install Shifts

pnpm add @frigear-nu/shifts @nuxthub/core

Add it to nuxt.config.ts

List Admin and Widget before Shifts, so the tab registers. Operations needs its admin pages for the tab to have a page to live on.

nuxt.config.ts
export default defineNuxtConfig({
  modules: ['@nuxthub/core', '@frigear-nu/admin', '@frigear-nu/widget', '@frigear-nu/shifts'],
  operations: { settings: { pages: { admin: true, adminOperation: true } } },
})

Shift times are entered and shown in the app's time zone. Set it once in app.config.ts, as frigearUi: { timeZone: 'Europe/Berlin' }; without it they are in UTC.

Generate the migration

Without a migration the shifts tables do not exist, and every request to them fails.
pnpm db:generate

Decide who manages shifts

Staff routes check permissions through Authorization. Without a role that holds shifts:manage, nobody can build a schedule. The admin role holds it when your app defines it; grant it to your own roles by name (authorization.roles.<role>.grant: ['shifts:manage', 'shifts:broadcast', 'shifts:pii']).

Build a schedule

Open the operation, then its Shifts tab. Create a schedule, then Create shifts: pick a team, the first and last day and the time slots. Open a shift to put people on it, then Publish schedule.

What you should see: an approved volunteer opens Crew → My shifts (/dashboard/crew?tab=shifts) and sees their shift. From an hour before it starts, the shift's page shows a QR code. A lead of the team opens /shifts/check-in/<teamId>, scans it and the volunteer is checked in. The operation's Shifts tab shows them under Working now, with that lead on duty.

Options

Options go under the shifts key.

OptionTypeDefaultPurpose
settings.pages.shiftsstring | booleanonMy shifts: the My shifts tab of the crew home. When the crew home is in the hub, true adds no page (/shifts redirects to /dashboard/crew?tab=shifts) and a path adds one there; without the hub, or with Mobile, true is also a page at /shifts. false turns both off.
settings.pages.shiftstring | booleanonOne of my shifts. With the crew home in the hub (and no Mobile), true is /dashboard/crew/shifts/:assignmentId, in the hub's layout, and the old /shifts/:assignmentId redirects there (301); otherwise /shifts/:assignmentId. A path must contain :assignmentId.
settings.pages.swapsstring | booleanonThe open swaps: the Swaps tab of the crew home, and a page at /shifts/swaps on the same terms as shifts (?tab=swaps).
settings.pages.checkInstring | booleanonThe scanner of a team's leads. true is /shifts/check-in/:teamId; a path must contain :teamId.
settings.pages.leadstring | booleanonThe page of a team's leads: exceptions, shifts, attendance and swaps to approve. true is /shifts/lead/:teamId; a path must contain :teamId.
settings.pages.stationstring | booleanonA check-in station's screen. true is /shifts/station/:stationId; a path must contain :stationId.
settings.operationsTabbooleantrueAdd the Shifts tab to the admin.operations tab area.
timeZonestringthe app'sThe time zone shift times are entered and shown in, when it is not the app's own (appConfig.frigearUi.timeZone, else UTC).
checkInOpensMinutesnumber60How many minutes before a shift starts its QR pass shows and check-in opens.
reminders.cronstring | falseevery ten minutesThe cron expression the reminder task runs on. false registers the task without a schedule.
reminders.offsetsnumber[][1440, 120]Minutes before a shift starts that a reminder goes out (a day and two hours). Whole minutes up to a week.
reminders.smsbooleanfalseAlso text people who have a phone number. SMS costs money, so it is off.
reminders.batchSizenumber100The most due assignments one run handles, soonest shift first (1 to 1000). The next run takes the rest.
automation.cronstring | falseevery five minutesThe cron expression of shifts:close-shifts. false registers the task without a schedule.
automation.batchSizenumber200The most rows of each kind (ended shifts, auto no-shows, digest items) one run handles (1 to 1000).

Station check-in needs a station key. Station codes are signed with NUXT_SHIFTS_STATION_KEY (runtimeConfig.shifts.stationKey), else with a key derived from NUXT_APP_SECRET (Secrets), so it works in any app that sets NUXT_APP_SECRET (32+ characters). An own key is optional; when you set one, make it at least 32 characters (for example openssl rand -base64 32): a shorter key stops the build when it is in nuxt.config.ts and the server at startup when it comes from the environment, with an error that says so. Where the environment only reaches a request (Cloudflare), a short key is logged and counts as no key. Without any key station check-in is off: the station screen and a station check-in answer 501 not_configured, the pass leaves station out of checkIn.modes, and the schedule's Check-in view shows that the key is missing and does not let staff turn the mode on. The lead's scan, location and daily work without it. Changing the key, or NUXT_APP_SECRET while the key is derived, invalidates the codes on screen for at most a minute.

timeZone is the operation's local time. Bulk creation turns days and HH:mm slots into instants in it, so 18:00 stays 18:00 across daylight saving changes; the guards count days in it; every shifts page and form shows and takes times in it, whatever the viewer's own time zone; and reminder and swap emails show times in it. Leave it unset to follow the app's time zone (appConfig.frigearUi.timeZone, see useFormat), so shift times match every other date of the app. When the app sets none, it is UTC. An unknown zone stops the build.

Permissions

Shifts registers these permissions with Authorization.

NameFlagsHeld by defaultWhat it allows
shifts:readimplicitevery signed-in userRead your own shifts, the marketplace, and who is on shift now where you take part.
shifts:swapimplicitevery signed-in userOpen a swap of your own shifts, offer on others', accept and reject offers on yours.
shifts:attendimplicitevery signed-in userCheck in on your own shifts at a station or by your location.
shifts:leadimplicitevery signed-in userCheck people in, mark attendance, approve swaps, read the team view and exceptions and open the stations, on teams you lead.
shifts:feedimplicit, session onlyevery signed-in userCreate and revoke the secret calendar feed of your own shifts. A token cannot.
shifts:checkinadminCheck anyone in on any shift by scanning their QR pass, on every team and operation, without leading the team (POST /api/shifts/check-in).
shifts:broadcastadminMessage the teams of an operation, or the people on a shift, by email (and SMS on request).
shifts:manageadminSchedules, shift roles, shifts, assignments, perks and every swap.
shifts:piisensitiveadminSee the email address and phone number of people on a shift.
perks:readimplicitevery signed-in userSee the perks you earned.
perks:claimimplicitevery signed-in userMark your perks claimed, so an app can hand them out.
  • Scope: a token may use the named scope shifts or shifts:read itself. Either reads your own shifts and who is on shift now. Swapping and leading need their own scope (shifts:swap, shifts:lead); a scanner app for the gate asks for shifts:checkin (it only carries it when the user holds it). The named scope perks covers perks:read and perks:claim: give it to the app that hands out perks. shifts:feed is session only: the feed URL shows your shifts to whoever holds it, so a token (or an OAuth client) answers 403 session_required.
  • Policies: the implicit permissions pass for everyone without a record, so every route authorizes again with the record once it is loaded.
    • shifts:read: your own assignments ({ userId }); a team ({ teamId, published }) you lead, or whose published shifts you hold an explicit role on; an operation ({ operationId }) you take part in (approved crew or an explicit team role there, operationsTakesPart of Operations); and staff.
    • shifts:swap and shifts:attend: only your own assignments.
    • perks:read and perks:claim: only your own earned perks ({ userId }).
    • shifts:lead: the leads of the record's team (isTeamLead of Teams: the ladder's lead role and up) and staff. It also covers a lead's broadcasts and the screens of their team's stations.
  • Why shifts:pii: leads and volunteers see names. Emails and phone numbers are personal data, so they sit behind a separate grant. It ends in :pii, so shifts:* and * never cover it.

Server

Everything under /api is in the Routes section. This section covers how shifts work.

Schedules

A schedule belongs to an operation. It starts as a draft: staff build it and volunteers see none of it, not even their assignments. Publishing makes it published (once: there is no way back to draft) and fires shifts:schedule:published. A schedule also sets:

  • coverage, handover and approval: how its shifts change hands, see Coverage, handover and approval.
  • minPerShift: fewer people shows a shift as short. maxPerShift: the capacity of a shift that sets none.
  • guards: maxShiftsPerDay and minRestHours, see Guards.

Copying takes the shift roles and shifts of another schedule ({ scheduleId, offsetDays }) and its coverage, handover and approval, never the people on them. The shifts move by whole days at the same local time (364 keeps the weekday a year on). A schedule of another operation maps its teams to this operation's teams by name; a team without a match is skipped and named in skippedTeamIds. A role whose minimum team role is not on the target team kind's ladder is copied without one and named in changedRoleIds.

A schedule with people on its shifts (or people who were on them: attended, no-shows) cannot be deleted (409 schedule_in_use), nor can such a shift (409 shift_in_use). Cancel the assignments first.

Shift roles

A shift role is a role on one team of the schedule, such as "Lead" or "Bartender", with the lowest team role that may hold it (teamRole, a key of the team kind's ladder; empty is anybody on the team). A shift may name a role: new assignments on it hold that role unless staff pick another. Moving a shift to another team or role is refused while people are on it.

Who can hold a shift

A person can hold an assignment on a shift when they hold an explicit active role on the shift's team, and that role is at least the shift role's teamRole on the ladder (roleAtLeast of @frigear-nu/teams/utils). Explicit means a team_members row that grants: approved crew, or a member staff added in Teams (teamGrantOf with source: 'explicit'). People who hold the team role only through a mapping rule (such as a global supervisor mapped to lead) are not assignable, so a mapping rule never puts somebody on a shift. Anything else is a 409 not_eligible with reason: 'grant' or 'role'.

One person holds a shift once (409 already_assigned). The rule is checked again after the insert, so two requests at once cannot put a person on a shift twice.

Guards and capacity

The capacity of a shift is its own capacity, else the schedule's maxPerShift; null is unlimited. Assigning somebody to a full shift is a 409 shift_full unless staff send force: true. The capacity is counted again after the insert, so two requests at once cannot overfill a shift: the last places go to the earliest rows (by creation, then id, the order of the duplicate check) and only a row past the capacity is taken back.

The guards are computed per assignment, from the person's other assigned and attended shifts:

WarningWhen
overlapThe person works another shift at the same time. Always, without a guard.
min_restFewer than minRestHours between the end of one shift and the start of the other.
max_shifts_per_dayMore than maxShiftsPerDay shifts start on one day (in the time zone).
shift_fullOver the capacity (only with force).
below_minThe shift still has fewer than minPerShift people.

Staff get the guards as warnings next to the assignment; they never block. A volunteer swap is refused when either person could not hold the shift they get, as they would stand after the exchange. The 409 code names the guard, and data.userId the person:

CodeWhen
guard_overlapThe person works another shift at the same time.
guard_restLess than minRestHours between two of their shifts.
guard_max_per_dayMore than maxShiftsPerDay shifts on one day.
guard_ineligibleNo explicit role on the shift's team, or below the shift role's teamRole.
guard_capacityThe shift holds more people than its capacity (staff forced people on, or lowered it).

A swap moves people between assignments, so the number of people on a shift never changes and minPerShift cannot break. The guards run when an offer is made (a doomed offer is refused), when a targeted trade is opened, and again when the owner accepts and when a lead approves.

Coverage, handover and approval

Three settings of a schedule decide how its shifts change hands between volunteers:

  • coverage: all means volunteers must work every shift they are given: nothing a volunteer does may lower how many shifts they hold. flexible (the default) lets them give shifts away.
  • handover: trade (shift for shift: both change hands together, so each person keeps their count), release (give a shift away, or take one over) or both (the default).
  • approval: peer (the default: the two volunteers' agreement is enough) or lead (a lead of the team, or staff, approves each swap the owner accepted).
coveragehandoverVolunteers canValid
alltradeTrade shift for shift.Yes
allrelease or bothNo: 400 invalid_schedule_settings
flexibletradeTrade shift for shift.Yes
flexiblereleaseGive a shift away; take one over.Yes
flexiblebothEither: the owner picks when opening the swap.Yes

approval combines with every valid row. coverage governs swaps and handovers, not leaving the crew: a person who withdraws from the crew (or leaves the team) still has their future shifts cancelled.

Across schedules. A trade may give back a shift of another schedule. Both schedules must allow a trade (409 handover_not_allowed), and when either has coverage: 'all' both shifts must be in the same schedule (409 handover_cross_schedule), so a shift that must be worked cannot be traded into a schedule that lets it be given away. The swap needs a lead's approval when either schedule says approval: 'lead'; a lead of a team whose schedule says so, or staff, approves it (a lead of the peer side cannot). Creating a schedule and changing one (PATCH, checked merged with the stored values) answer 400 invalid_schedule_settings for the invalid rows.

Example: a festival bar asks every volunteer to work all their shifts, and lets them swap one shift for another between themselves:

{ "coverage": "all", "handover": "trade", "approval": "peer" }

The server refuses every path that would lower a volunteer's count unless the schedule allows a release, with 409 handover_not_allowed: opening a release, an offer without a shift in return, and accepting or approving such an offer. Opening a trade under handover: 'release' is refused the same way. Accepting and approving check the settings of that moment, so a release opened before staff switched a schedule to coverage: 'all' can no longer be carried out (staff or its owner cancel it), and the marketplace stops showing it. The lead page and the admin tab hide Approve swap on such a swap and say to reject it. Opening a swap again keeps the live one while it is of the kind asked for and still allowed; a stale open one (another kind, or no longer allowed) is cancelled and replaced, and one with offers answers 409 swap_changed. The pages hide every action the schedule does not allow and say "trade only: you must work all your shifts" when coverage is all.

Swap model changed. Schedules used to have a single swap mode (peer or approval) and any swap could be taken over without a shift in return. approval replaces it (approval became lead, migrated with the data), and coverage and handover are new. Swaps have a kind; swaps opened before the change are releases. Hook payloads carry kind, the swap and schedule DTOs carry the settings, and the guard refusals answer guard_* codes instead of swap_guard and not_eligible. Apps that open swaps through the API pass { kind } where the schedule allows both.

Swaps

The owner of an assigned shift in a published schedule that has not started opens a swap of it, of a kind the schedule allows ({ kind }; left out, a release where the schedule allows one, else a trade):

  • A trade asks for a shift in return. Every offer gives one of the offerer's own future shifts ({ assignmentId }, required), and both shifts change hands together, so each person's count stays the same. The owner may aim the trade at one assignment (wantedAssignmentId): only its holder sees the swap and may offer, and only that shift (409 not_wanted); the holder is emailed. The owner chooses among the offers; each names its shift.
  • A release gives the shift away. An offer takes it over and gives nothing back (400 with a shift).

Both people must be able to hold the shift they get (eligibility and guards): a swap across teams works only when each person holds a role on the other's team. One live offer per person and swap (409 offer_exists; two offers at once keep the earliest). A shift whose own swap is being carried out or waits for approval cannot be given back (409 not_swappable).

open ──offer──► offered ──owner accepts──► accepted ──► completed          (approval: peer)
                   │                └────► pending_approval ──approve──► accepted ──► completed
                   │                                 └──reject──► open      (approval: lead)
                   └──last offer withdrawn or rejected──► open
open, offered, pending_approval ──owner withdraws──► cancelled
  • Accepting checks the schedule's settings and both directions again, then claims the swap with a conditional write, so two accepts at once carry out one; the other gets 409 swap_changed. The other waiting offers become superseded.
  • Completing hands the owner's assignment to the offerer and, in a trade, the shift given back to the owner. Each assignment keeps its id and gets a new check-in code. Every write is conditional: the accepted offer must still stand (a withdraw that won the race leaves none), the owner's assignment must still be assigned to the person who opened the swap and the one given back to the offerer, and the swap must still be accepted. On postgres the writes run in one transaction. On sqlite and D1, which have no interactive transactions, a failed write puts the earlier ones back, each undo conditional on the row still holding what the exchange wrote. When the exchange does not happen the offer is rejected and the swap is open again (409 swap_changed). Other live swaps of the shift given back are cancelled, and offers elsewhere that gave either shift are withdrawn.
  • Recovery: on sqlite and D1 a process that dies between the writes leaves the swap accepted with one shift moved. Staff settle it with POST /api/admin/shifts/swaps/:swapId/cancel (completed when both shifts moved, put back to the people who held them when only one moved, else cancelled), and the owner's withdraw does the same once the swap has sat in accepted for five minutes. Between the crash and the recovery the two people may both, or neither, hold a shift: that window is what remains without transactions.
  • approval: 'peer' fires shifts:swap:accepted only once the exchange is done, just before shifts:swap:completed, and sends only the completed email. approval: 'lead' fires accepted and sends the accepted email when the owner accepts.
  • approval: 'lead': the leads of the team (or teams) whose schedule says approval: 'lead' are emailed; any of them, or staff, approves (the settings and the exchange are checked again and the swap completes) or rejects (the offer is rejected and the swap is open for offers again). A lead of a peer schedule's team cannot decide for the other side.
  • No deciding your own swap. The owner and the offerer whose offer was accepted never approve or reject it, even when they lead the team: 403 swap_party, unless they hold shifts:manage. They are not emailed to approve it either.
  • Withdrawing: the owner cancels an open swap; an offerer withdraws a waiting offer, or an accepted one that still waits for approval (the swap is open again). A withdraw and an approval at once settle one way: when the approval claimed the swap first the offer is put back and the withdraw answers 409 swap_changed.
  • Cancelled shifts: when an assignment stops being assigned (cancelled, checked in, marked a no-show), its swap is cancelled and offers that gave it back are withdrawn.
  • The rejected swap status is reserved: an approver's rejection puts the swap back to open instead.

Check-in and attendance

Every assignment has a check-in code: 64 hex characters, like an Events ticket. The pass route shows it, and its QR code as SVG, only from checkInOpensMinutes before the shift starts until it ends, and only to the person. A lead of the team (or staff) checks the person in with POST /api/shifts/teams/:teamId/check-in { code }:

  • an unknown code, or the code of another team's shift, is a 404 (a lead learns nothing of other teams);
  • a cancelled assignment is 409 assignment_cancelled; outside the window 409 outside_window;
  • a person who no longer holds an explicit role on the team (removed, or a membership status that stopped granting) is 409 not_eligible, and their future shifts on the team are cancelled there and then. The pass route is read-only: it answers available: false, eligible: false with no code, and the shift page then calls POST /api/shifts/me/:assignmentId/settle, which cancels those future shifts (Teams' hooks normally do it first, see People leaving a team);
  • scanning twice is fine: the second scan answers alreadyCheckedIn: true with the first scan's time.

POST /api/shifts/check-in { code } (shiftsApi.checkIn) is the same scan without picking a team first, for a scanner that serves a whole event (a gate, a bar). The code says which shift it is: a holder of shifts:checkin checks anyone in on any team and operation, and a lead (or staff) the people of the teams they lead. An unknown code, or one of a team the caller may not check in on, is a 404, so the route says nothing about codes the caller may not use. A token needs the shifts:checkin or shifts:lead scope (403 insufficient_scope otherwise). The answer, the 409 errors, the attendance hook and the contact details (only with shifts:pii) are those of the team scanner. Grant it to the role of the people who scan: authorization.roles.<role>.grant: ['shifts:checkin'].

A check-in marks the assignment attended and records how (checkInMethod: lead, station, location or daily). Leads and staff also mark attendance by hand (attended, no_show), for example after the window closed, but not before check-in opens (409 outside_window). An attended assignment cannot be cancelled.

Check-in modes

A schedule's checkIn setting says how volunteers check in: { modes, location?, teams? }. Any mode that is on is enough, and the lead's scan always works, whatever the modes say. A schedule that never set it is { modes: ['lead'] }.

ModeHow
leadA lead scans the volunteer's QR pass (above).
stationThe volunteer scans the rotating QR code on a station's screen with the camera on their shift page.
locationThe volunteer taps I'm here and the app sends the device's position and its accuracy.
dailyThe first successful check-in of the day (any mode, in timeZone) also checks in the person's other shifts that day whose check-in window is already open (checkInMethod: 'daily'). A shift whose window opens later needs a check-in of its own.

Per team. teams maps a team id to { modes?, location? }, overriding the schedule's for that team's shifts (a key it leaves out keeps the schedule's). It lives on the schedule, so a schedule's settings stay in one row; every key must be a team of the operation (400). The pass answers the rule that applies (checkIn: { modes, location }).

The volunteer checks in with POST /api/shifts/me/:assignmentId/check-in, { mode: 'station', token } or { mode: 'location', latitude, longitude, accuracy }:

  • a mode that is off for the shift is 409 mode_disabled;
  • station: a token that is not one, or whose signature does not verify (forged or altered), is 400 invalid_token; one older than the previous window is 409 token_expired; a station of another team or schedule 409 wrong_station;
  • location: without a place, 409 no_location; an accuracy worse than the radius 409 inaccurate_position; outside the place 409 outside_location (with distance and radius);
  • then as for a lead's scan: 409 assignment_cancelled, not_eligible, outside_window;
  • checking in twice (a replayed token, a second tap) answers alreadyCheckedIn: true and changes nothing.

The place is a Maps location (MapLocation, from the location picker): a point with a radius, default 150 m, or an area. The check uses the maps geometry helpers (haversine distance, point in area), and the device's accuracy must be at most the radius.

Self check-in is attendance-grade, not proof. In location mode the position and its accuracy are what the volunteer's device reports, and a determined person can send any position (an accuracy of 0 always passes). In station mode a photo of the station's code works anywhere for as long as the code does, 30 to 60 seconds, for anyone on the team. It suits "did the volunteers turn up", not access control: use a lead's scan where it matters.

Stations

A station is a screen of a team on a schedule (at the bar, at the gate): staff add them in the schedule's Check-in view, optionally on an operations.station feature of the operation's venue layout (featureId, 400 for anything else). Its page, /shifts/station/:stationId, is for the team's leads and staff: a full-screen QR code that keeps the screen awake and fetches the next code from GET /api/shifts/stations/:stationId/token as the window turns.

  • The code is <stationId>.<window>.<signature>: an HMAC-SHA-256 of <stationId>:<window> (Web Crypto), keyed by HKDF from the station key, NUXT_SHIFTS_STATION_KEY or one derived from NUXT_APP_SECRET (see Options). Nothing is stored per code. Without a key, stations can still be added, but their screens and station check-in answer 501 not_configured. Every schedule response says whether a key is available (stationKeyConfigured).
  • Windows are 30 seconds. The current and the previous window are accepted, so a code scanned as it turns still works; anything older is 409 token_expired.
  • Single use per person and shift. One code checks in every volunteer of the team who scans it, each once: a replay answers alreadyCheckedIn.

Automation

The shifts:close-shifts task runs every five minutes (automation.cron), on its own cron, mirrored into the Cloudflare cron triggers like the reminders. Every step is idempotent on both dialects and handles at most automation.batchSize rows, chunked below D1's 100 bound parameters; the next run takes the rest.

  1. Shift end. For ended shifts of published schedules not closed yet (shifts.closedAt), everyone attended gets the shift's earned perks, then the shift is closed. Nobody else changes: there is no completed status, and a person who never checked in stays assigned (or becomes a no-show, below).
  2. Automatic no-shows. On schedules with autoNoShow: true (off by default), assignments still assigned without a check-in autoNoShowMinutes (default 30) after the start become no_show, for shifts that started in the last day. The system marks them: by: null, and the hooks get auto: true and event: undefined. A person who turns up after all is checked in by a lead's scan or mark as usual.
  3. Digest. The new exceptions go out as one message per lead per run: no-shows, people still not checked in autoNoShowMinutes after the start (on schedules without automatic no-shows), and no-shows whose perk was claimed before the flip. Each is claimed in shift_digest_items (unique on kind and assignment), so it is sent once. A team's exceptions go to its leads on shift now; with none on duty, to its leads; with none, to the operation's coordinators (the explicit holders of the top role of a ladder on one of its teams). It goes through shiftsNotify on the shifts.digest topic (the lead's own channels, email and push by default). Fires shifts:digest:sent.

The lead page opens on the same Exceptions (GET /api/shifts/teams/:teamId/exceptions): no-shows, late check-ins, people not checked in after the start, and claimed no-shows, on the team's shifts of the last day. The full list of shifts is one tab away. Crew approval and swap approval are not automated.

On shift now

GET /api/shifts/operations/:operationId/now answers the shifts of the operation's published schedules running now, per team, with the people on them (assigned and attended) and the leads on duty among them. People who take part in the operation and staff read it. Names always; email and phone number only with shifts:pii.

Dashboard items

With Dashboard installed, Shifts adds three items to crew.home and the hub's dashboard, each with the permission shifts:read and each showing a skeleton, an empty state or an error:

ItemOrderShowsReads
shifts.next20Two columns wide. My next shift (or the one on now), with a link to its page and the QR pass. On the mobile Home tab (homeTab: true) it shows nothing without a shift.GET /api/shifts/me
shifts.on-now30Two columns wide. My teams on shift now, who is on and the lead on duty. Refreshes every minute.GET /api/shifts/me/now
shifts.swaps40One column (up to two). The open swaps I can take, with a link to the marketplace.GET /api/shifts/swaps

Texts are under shifts.dashboard.

On-duty layer

Shifts registers shifts.on-duty, a live layer of Maps, on the venue layout of Operations (the operations.venue-layout surface). A viewer of the venue layout fetches it from GET /api/shifts/operations/:operationId/on-duty every 120 seconds. The layer looks up the leads of every team on shift (each lookup resolves the person's team roles), so it refreshes less often than the dashboard item, which only asks about my own teams.

  • Shift locations. A shift's location is { name?, featureId? }. featureId is the stable id of a feature of the operation's venue layout, such as a station.
  • A point per team and location. The route runs the same query as "on shift now". A shift whose location.featureId names a feature of the layout is drawn at that feature: a point as it is, a line at its middle, an area at its centroid (geometryAnchor of Maps). The same team at the same feature is one point. A shift without a feature, or naming one the layout does not have, is skipped.
  • Properties: label (the team's name, shown in the popup), teamId, featureId, count (people on now, shown on the marker) and leadsOnDuty. The names of the leads on duty (leads) only come with shifts:pii.
  • Who sees it. Like "on shift now": shifts:read for people who take part in the operation and staff. Anybody else gets a 403, and the viewer hides the layer.

My teams on shift now

GET /api/shifts/me/now answers, for each operation where I hold a team role, the teams I am on that have a shift running, with who is on it and the leads among them (names only, never email or phone). It is "on shift now" narrowed to my teams, so an operation I may not read that view of is left out (shifts:read with the operation, as for /operations/:operationId/now). The dashboard item shifts.on-now reads it.

People leaving a team

Shifts listens to the Teams hooks of teams an operation owns:

  • teams:member:removed (removed in Teams, or a crew member rejected, waitlisted, withdrawn or moved to another team): the person's future assigned assignments on the team are cancelled.
  • teams:member:role-changed: the future ones whose shift role the new role no longer meets are cancelled.

Each cancellation fires shifts:assignment:changed and cancels the assignment's swap.

Reminders

The shifts:send-reminders Nitro task runs on reminders.cron (every ten minutes unless you set it). Registering it turns on Nitro's experimental tasks and adds the cron to scheduledTasks, next to other modules' tasks. For every assigned assignment in a published schedule whose shift lies ahead, each of reminders.offsets whose moment (startsAt minus the offset) has passed is due:

  • Once per offset. A reminder is claimed by inserting a shift_reminders row (unique on the assignment and the offset) and then sent, so two runs at once, or a run repeated, send nothing twice. A swap that hands the assignment over deletes its rows, so the new holder is reminded too (see Reminders, feed and perks after a handover). A failed send keeps its row and is logged: a broken address is not retried every ten minutes.
  • One message when several are due together. A person assigned inside the window, or a late run, gets one reminder, for the smallest offset (the one closest to the shift); the larger offsets are spent without a message of their own.
  • Still eligible. A person who no longer holds their role on the team gets nothing; their due offsets are spent (rows without a message), so they do not crowd later runs.
  • What it says. The message names the real time left (startsAt minus now, as minutes below an hour, rounded hours below a day, then days), not the configured offset: a person assigned three hours before a shift gets "in 3 hours". It is written in the person's language (their users.locale, else the language on their crew row of the team; Danish for da, English for everything else, including a locale Intl does not know), for the subject, text, heading and button of the email and for the SMS.
  • Channels. Email and push by default (template shifts-reminder, in the person's locale, with a link to the shift page when a site origin is configured). SMS only with reminders.sms and a phone number (users.phone of Users, set on the profile or by crew applications) and the person's own choice. See Push and notify topics.
  • A budget per run. A run takes at most reminders.batchSize assignments (100), soonest shift first. Assignments whose due offsets are all claimed are left out in SQL, so later runs pick up the rest: a backlog drains over a few ten-minute runs. Every lookup by a list of ids runs in chunks of 90.
  • Hook. shifts:reminder:sent with { event, assignment, offset, channels }, where event is always undefined when the task fires it (the type is H3Event | undefined). A scheduled task has no request, so this is the one shifts hook without one: do not read the session from it.
Cloudflare: nitropack 2 bundles scheduledTasks into the worker but never writes the cron expressions to wrangler.json, so Cloudflare would not trigger them. The module adds its cron to nitro.options.cloudflare.wrangler.triggers.crons (a deduplicated union, so it works next to a host that mirrors all of its own crons, as apps/website does). Other presets run the task from scheduledTasks as Nitro does. With cron: false, call shiftsSendReminders() from your own scheduler.

shiftsSendReminders(now?, event?, override?) is the function the task calls; override replaces offsets, sms and batchSize for one run, which is how the tests drive it with a fake now.

Calendar feed

A volunteer subscribes to their shifts from a calendar app. Subscribe in calendar on my shifts mints a secret link, shown once, as an https address and a webcal:// one that calendar apps open as a subscription.

  • POST /api/shifts/me/feed-token mints it (shift_feed_tokens: only the SHA-256 hash is stored) and revokes any earlier one, so there is one live link per person. The live rows are revoked before the insert and every other one again after it, so two mints at once (a double click) never leave two live links. GET says whether I have one and when it was last read; DELETE revokes it. All three need shifts:feed, so a session: a token answers 403 session_required.
  • GET /api/shifts/feed/<token>.ics is public: the secret is the credential. An unknown or revoked one is 404. The router does not match a suffix after a param, so the route is feed/:token and the handler strips an optional .ics. It answers text/calendar; charset=utf-8 with cache-control: private, max-age=300.
  • The feed lists my assigned, attended and no_show shifts of published schedules from 30 days ago onward, never other people's. Each event has the team and role as its summary, the location name, a description with the operation, the notes and a link to the shift page, UTC start and end, and a stable UID per assignment (so a swap changes who has the event, not the event). The .ics is written by hand (RFC 5545: CRLF, 75-octet folding, escaping).
  • Reading a feed touches lastUsedAt at most every five minutes.

Broadcasts

A broadcast messages the people of an operation: POST /api/admin/shifts/broadcasts for staff with shifts:broadcast (admin, and the roles your app grants it to), and POST /api/shifts/teams/:teamId/broadcasts for the leads of a team, who reach their own team only. The body is { operationId, audience, channels, subject, message } (a lead's has no operationId):

  • Audience. { teamId?, teamRole?, shiftId? }. Without a shift: the active explicit members of the operation's teams (teamId narrows to one team) whose role is at least teamRole on their team kind's ladder. With shiftId: the people holding a place on that shift (a role cannot be combined with a shift). One message per person. Nobody matching is 400 audience_empty; more than 500 people is 400 audience_too_large.
  • Channels. ['email'] by default. SMS is opt-in per broadcast: add 'sms' and everyone with a phone number who chose SMS is texted as well. Texts cost money, so the form warns and never defaults to them.
  • Locale. subject and message are translated texts: each person gets their own language (their users.locale, else the one on their crew row of the team), falling back to en only when neither is set.
  • The audience, the people and their locales are resolved first, then the broadcast is stored (shift_broadcasts, with the audience and the recipient count), so a failure while resolving leaves no history row. It is listed by GET /api/admin/shifts/broadcasts?operationId= (newest first). A delivery that fails is logged and skipped. Fires shifts:broadcast:sent once delivery is over.
  • Delivery. On Cloudflare Workers it runs in waitUntil, so the request returns once the row is stored with delivery: 'queued' (and zero counts); the totals and failures are logged when it ends. Elsewhere it is awaited and the answer has delivery: 'done' with sent: { email, sms }.

Workers and D1 limits

A Workers invocation has a budget of subrequests (50 on the free plan, 1000 on paid), and D1 allows 100 bound parameters per statement. Shifts keeps inside both: lookups by a list of ids are chunked (90), bulk create and schedule copy insert 8 shifts per statement (11 parameters a row), reminders take a batch per run (reminders.batchSize), and broadcasts are capped at 500 people and delivered in the background. Every email or SMS is a subrequest through your notify driver, so size batchSize and your broadcasts to your plan, and run the task often (the default is every ten minutes) rather than with a big batch.

Perks

A perk is what a volunteer earns for a shift they attend: { name, voucherType, quantity } for a team (or every team of the operation), such as two of beer. Staff add them per operation in the Shifts tab. Shifts does not hand them out: an app such as the vouchers app spends them.

  • Earned perks. Every attended assignment of a team a perk applies to earns it once (shift_earned_perks, unique on (perkId, assignmentId)): at the shift's end by the task, or at once when a lead marks an ended shift attended. The earned perk copies the perk's voucherType and quantity. Fires shifts:perk:earned.
  • Revocation. A flip from attended to no_show revokes the earned perks nobody claimed yet (shifts:perk:revoked). A claimed one stays, and the lead sees that no-show flagged in the exceptions. Marked attended again, the same earned perk comes back.
  • The pass lists what the shift earns: upcoming, then earned, claimed or revoked.
  • Deleting a perk is refused with 409 perk_already_earned once anybody earned it: change it instead. Changes apply to perks earned from then on.

The vouchers contract. The app calls, with an OAuth access token holding the perks scope (an access token of this app's OAuth server, or a foreign token through OAuth Resource):

  • GET /api/shifts/me/earned-perks?status=unclaimed|claimed|all (unclaimed by default): { items }, oldest first, never the revoked ones, not paginated (one person's earned perks). An item is { id, voucherType, quantity, perkName, earnedAt, claimedAt, shift: { id, startsAt, endsAt, teamName, operationName } }, names in the Accept-Language. id (spg_...) is the idempotency key on the app's side.
  • POST /api/shifts/me/earned-perks/:id/claim with an optional { client }: the earned perk with claimedAt set. A repeat answers 200 with the same claimedAt. 404 not_found for an unknown earned perk or somebody else's; 409 perk_revoked for a revoked one.
  • A token without the scope gets 403 insufficient_scope.

Example

A bar team checks in at a station by the bar, and anywhere on the site by location; a shift earns two beers:

// PATCH /api/admin/shifts/schedules/:scheduleId
{
  checkIn: {
    modes: ['location', 'daily'],
    location: { point: { lat: 10.0167, lng: 20.0784 }, radiusMeters: 800 },
    teams: { [barTeamId]: { modes: ['station', 'location', 'daily'] } },
  },
  autoNoShow: true,
  autoNoShowMinutes: 30,
}
// POST /api/admin/shifts/schedules/:scheduleId/stations
{ teamId: barTeamId, name: 'Bar north', featureId: 'bar-north' }
// POST /api/admin/shifts/operations/:operationId/perks
{ teamId: barTeamId, name: { en: 'Beer', da: 'Øl' }, voucherType: 'beer', quantity: 2 }

The bar's leads open the station's screen on a tablet and the Exceptions of their lead page; the shift's end gives out the beers, and the vouchers app lists and claims them with a token holding perks.

Reminders, feed and perks after a handover

A trade or a release keeps the assignment's id and changes its owner (and issues a new check-in code). The extras follow the assignment, with these rules:

  • Reminders: a claim is keyed by assignment and offset, so the handover deletes the assignment's claims. The new owner gets the reminder that is due at the next run (worded with the real time left, so "in 22 hours" for a handover two hours after the day-before reminder) and every later offset; the old owner gets nothing more.
  • Perks: whoever attends the shift earns the perk: it is made for the assignment's holder when it is earned. The old pass code no longer works.
  • Feed: events are keyed by assignment (UID), so a released shift leaves the giver's feed and enters the taker's, and a trade swaps the two events between the two feeds, at the next refresh of the calendar app.

QR pass

The pass page counts down to the moment the pass opens, lists what the shift earns, offers checking in at a station or by location where the schedule allows it, names the lead on duty and has Show larger: a full-screen, high-contrast QR code that keeps the screen awake with the Screen Wake Lock API where the browser has it (client only; without it the pass still shows).

Push and notify topics

Shifts registers the topics shifts.reminder, shifts.swap, shifts.broadcast and shifts.digest with Notify (email and push on by default, SMS off; swaps and the digest do not offer SMS) and sends reminders, swap messages, broadcasts and the leads' digest through notifyUser. People choose their channels per topic on the account page of Preferences; without Preferences the defaults apply to everyone. Push notifications reach phones with Push installed; without it Notify's log driver logs them.

  • A reminder's SMS needs both reminders.sms and the person's own choice for shifts.reminder.
  • A broadcast's SMS stays opt-in per broadcast. When the sender ticks SMS, the person's choice for shifts.broadcast still decides: an SMS-only broadcast reaches only the people who opted into SMS for the topic, which is off by default. The push notification goes out with the email channel: a broadcast by SMS alone sends none.
  • The push notification says the email's subject and message, with the link. shifts:reminder:sent lists push among its channels when one went out, and a broadcast's sent has a push count next to email and sms.

All of it goes through one helper, shiftsNotify (a server util), which calls notifyUser.

Emails

TemplateToWhen
shifts-swap-proposedThe holder of the wanted shiftA trade is aimed at their shift.
shifts-swap-offeredThe ownerSomebody offered on their swap.
shifts-swap-acceptedThe offererThe owner accepted their offer.
shifts-swap-rejectedThe offerer (and the owner on an approver's rejection)The offer was turned down.
shifts-swap-completedBoth peopleThe shift (both shifts, in a trade) changed hands.
shifts-swap-pendingThe explicit leads of the team(s)A swap waits for approval.
shifts-reminderThe person on the shiftA reminder offset fell due.
shifts-broadcastEach person reachedA coordinator or lead sent a message; also the leads' digest of the close task.

A trade's emails name both shifts (the template gets trade: true). The emails go through Notify in the person's language: their users.locale, else the locale on their crew row of the team, else en. Their link goes to the shift's page for the owner, the lead page for a pending approval, my shifts once completed and the open swaps otherwise. Links need a configured site origin (the one Auth uses for its emails); without one the emails go out without a link and a warning is logged once. A failing email is logged and never fails the swap.

App

Pages

PageWhat it shows
My shifts tab (/shifts without the hub)My shifts in published schedules, grouped by day, with a month calendar marking the days I work; past shifts on request. The lead pages of the teams I lead and Subscribe in calendar above.
/dashboard/crew/shifts/:assignmentId (/shifts/:assignmentId without the hub)One of my shifts: when and where, my role, the lead on duty, the QR pass while check-in is open, Scan the station code and I'm here: check in where the schedule allows them, what the shift earns, and the swap with its offers: Offer shift for a trade and Give shift away, as far as the schedule allows.
Swaps tab (/shifts/swaps without the hub)The swaps I can take: a trade asks me to choose one of my own shifts, a released shift is taken over; my own shifts on offer.
/shifts/check-in/:teamIdThe scanner of a team's leads: the camera (vue-qrcode-reader, in the browser only) or the code typed in. A repeat of the same code within three seconds is ignored.
/shifts/lead/:teamIdThe page of a team's leads. It opens on Exceptions (no-shows, late, not checked in after the start, claimed no-shows) with attendance marks; All shifts is one tab away. Also the swaps waiting for approval, the team's stations, Message team and the scanner. My shifts links it for the teams the person leads.
/shifts/station/:stationIdA check-in station's screen for the team's leads and staff: its QR code full screen, a new one every 30 seconds, the screen kept awake.

Signed-out visitors go to the sign-in page and come back.

My shifts and the swaps are tabs of the crew home (crew.dashboard, see Crew): shifts (order 20, shifts:read) and swaps (30, shifts:swap). In the hub they replace the two pages, whose old paths answer with a 302 to their tab; links (useShiftsLinks().shifts(), .swaps(), the swap emails and the back links of the shift and lead pages) go to the page when there is one and to the tab otherwise. With Mobile the pages stay, for the tab bar's Shifts tab.

Tab on the operation page

The Shifts tab (admin.operations, order 30, after Crew and Teams, shifts:manage) lists the operation's schedules and who is working now. ?schedule=<id> opens one schedule:

  • Day: a timeline per day, a row per team, a block per shift coloured by how full it is (short of the minimum, full). Clicking a block opens the shift: who is on it, marking attendance, taking people off, assigning people from a search of the team with the guards each would break (for the shift role picked in the form), and editing its times, capacity, role and place on the venue layout (a select of the layout's features; Create shifts has it too).
  • List: every shift with its people.
  • Shift roles: add, edit and delete them.
  • Swaps to approve: the swaps of the schedule waiting for approval, with approve and reject.
  • Check-in: the modes, the check-in place (the maps location picker), automatic no-shows and per-team overrides, and the schedule's stations (add, edit, delete, open the screen).
  • Settings: coverage, handover and approval as form rows (also in the schedule's slideover). Picking coverage: 'all' sets handover: 'trade'.

The schedule's header holds Edit schedule, Copy shifts, Create shifts (a range of days and time slots for one team) and Publish schedule. The tab reads the operation's teams through a shifts route, so shifts:manage is enough.

Under the schedules the tab has two more cards: Perks (add, edit and delete the operation's perks, with how many times each was earned) and Messages (the broadcasts sent, and Message teams, which opens a slideover with the team, a role and up, a translated subject and message, and an SMS switch with a cost warning). Messages needs shifts:broadcast and hides itself without it.

Composables

ComposableWhat it does
useShiftsActions()The schedule, role and shift forms and confirmations (createSchedule, editSchedule, publishSchedule, deleteSchedule, bulkCreate, copyFrom, createRole, editRole, deleteRole, openShift, deleteShift, approveSwap, rejectSwap, saveScheduleSettings, subscribe, broadcast, broadcastToTeam, createPerk, editPerk, deletePerk, createStation, editStation, deleteStation), the row menus, settingsLabel (a schedule's settings in a few words) and swapSummary (who a pending swap moves where).
useShiftsLinks()Locale-aware links to the shifts pages.
useShiftsFormat()Formats shift times in the shifts time zone (timeZone, else the app's).
useShiftsTranslate()Reads a translated text in the current locale.
useShiftsVenueFeatures(operationId, { kind? })The features of an operation's venue layout as select options, for the place pickers.

Hooks

Your app answers these Nitro hooks from a server plugin (server/plugins/*.ts).

HookWhenPayload
shifts:schedule:publishedAfter a draft schedule was published.{ event, schedule }
shifts:shift:createdAfter a shift was created (bulk creation and copying fire it per shift).{ event, shift }
shifts:shift:updatedAfter a shift's times, place, capacity, notes, team or role changed.{ event, shift, previous }
shifts:assignment:changedAfter an assignment was created, cancelled, marked or changed hands in a swap.{ event, assignment, previous, auto? }
shifts:swap:offeredAfter somebody offered on a swap.{ event, kind, swap, offer }
shifts:swap:acceptedAfter the owner accepted an offer.{ event, kind, swap, offer }
shifts:swap:rejectedAfter the owner turned an offer down, or an approver rejected the swap.{ event, kind, swap, offer }
shifts:swap:completedAfter the shift (both shifts, in a trade) changed hands.{ event, kind, swap, offer }
shifts:attendance:markedAfter a check-in (by a lead, a station, a location or the daily mode), a lead's mark, or an automatic no-show.{ event, assignment, by, method?, auto? }
shifts:reminder:sentAfter a reminder went out (by the task).{ event, assignment, offset, channels }, event always undefined
shifts:broadcast:sentAfter a broadcast was sent.{ event, broadcast }
shifts:perk:earnedAfter a perk was earned, or came back on attended (also from the task).{ event, earnedPerkId, perkId, assignmentId, userId }
shifts:perk:revokedAfter an unclaimed earned perk was revoked by a flip to no-show.{ event, earnedPerkId, perkId, assignmentId, userId }
shifts:digest:sentAfter the close task sent a lead their digest.{ event, userId, items, channels }, event always undefined
  • previous of shifts:assignment:changed is null for a new assignment. A swap moves an assignment to another person: previous.userId is the person who gave it away. It fires for assignments in draft schedules too; a listener that only cares about what volunteers see checks that the schedule is published.
  • assignment never carries the check-in code.
  • by is the user id of the lead or staff member, the person themselves for a station or location check-in, or null for an automatic no-show. method is how a check-in happened (lead, station, location, daily).
  • auto: true marks what the shifts:close-shifts task did (an automatic no-show): event is undefined then, in shifts:attendance:marked and shifts:assignment:changed (both typed H3Event | undefined). shifts:perk:earned has no event when the task fires it, and shifts:digest:sent never has one.
  • event is always undefined in shifts:reminder:sent (type H3Event | undefined). It fires from the shifts:send-reminders task, which has no request, unlike every other shifts hook (the same exception as teams:roles:resolve). Hooks identify the user from the payload (assignment.userId), never from the session of event.
  • channels of the reminder are the ones that went out (email, sms). broadcast has the audience and recipient count, never the people. items of a digest are { kind, assignmentId, teamId }.
  • kind is the swap's: trade or release.
  • With approval: 'peer' an accept fires shifts:swap:accepted only after the exchange succeeded, then shifts:swap:completed, in the same request.
  • Shifts listens to teams:member:removed and teams:member:role-changed.

Routes

Typed path builders are exported as shiftsApi from @frigear-nu/shifts/api.

RouteWhoWhat it does
GET /api/shifts/meshifts:readMy shifts in published schedules (?from&to, ISO instants).
GET /api/shifts/me/leadsshifts:readThe teams I lead, with their operations.
GET /api/shifts/me/nowshifts:readMy teams that have a shift running now, with who is on it and the leads. Names only.
GET /api/shifts/me/feed-tokenshifts:feedWhether I have a calendar feed, its prefix and when it was made and last read. Session only.
POST /api/shifts/me/feed-tokenshifts:feedMint my calendar feed (201): { token, url, webcalUrl }, shown once; revokes the old one. Session only.
DELETE /api/shifts/me/feed-tokenshifts:feedRevoke it (204). Session only.
GET /api/shifts/feed/:tokenpublic (the token)My shifts as text/calendar (.ics suffix optional). 404 for an unknown or revoked token.
GET /api/shifts/me/:assignmentIdshifts:read + policyOne of my shifts, with the leads on duty and my swap. 404 for somebody else's or a draft's.
GET /api/shifts/me/:assignmentId/passshifts:read + policyThe QR pass: code and svg only inside the window, and only while I hold my role on the team (else eligible: false). With what the shift earns (perks) and how I can check in (checkIn). Read-only.
POST /api/shifts/me/:assignmentId/settleshifts:attend + policyAfter a pass said eligible: false: cancels my future shifts on the team my role no longer meets, and answers the pass.
POST /api/shifts/me/:assignmentId/check-inshifts:attend + policyCheck in myself { mode: 'station', token } or { mode: 'location', latitude, longitude, accuracy }: { ok, alreadyCheckedIn, checkedInAt, method, assignment, alsoCheckedIn }. 400 invalid_token; 409 mode_disabled, token_expired, wrong_station, no_location, inaccurate_position, outside_location, outside_window, assignment_cancelled, not_eligible; 501 not_configured for station without a station key (NUXT_SHIFTS_STATION_KEY or NUXT_APP_SECRET).
GET /api/shifts/me/earned-perksperks:read + policyMy earned perks (?status=unclaimed|claimed|all): { items }. See Perks.
POST /api/shifts/me/earned-perks/:id/claimperks:claim + policyClaim an earned perk { client? }, idempotently. 404 not_found, 409 perk_revoked.
POST /api/shifts/me/:assignmentId/swapshifts:swap + policyOpen a swap { kind?, wantedAssignmentId? } (201). Again answers the live swap of that kind; a stale open one is replaced. 409 not_swappable, handover_not_allowed, swap_changed, and for a targeted trade handover_cross_schedule and guard_*.
DELETE /api/shifts/me/:assignmentId/swapshifts:swap + policyWithdraw the swap (204); a swap stuck in accepted for five minutes is settled.
GET /api/shifts/swapsshifts:readThe swaps I can take (of a kind the schedule allows now), each with myOffer.
POST /api/shifts/swaps/:swapId/offersshifts:swapOffer { assignmentId } on a trade, {} on a release (201). 400 a shift on a release; 409 handover_not_allowed, handover_cross_schedule, not_wanted, guard_*, already_assigned, offer_exists, own_swap, swap_closed.
DELETE /api/shifts/swaps/:swapId/offers/:offerIdshifts:swap + policyWithdraw my offer (204).
POST /api/shifts/swaps/:swapId/offers/:offerId/acceptshifts:swap + policy (owner)Accept: completed (approval: 'peer') or pending_approval. 409 handover_not_allowed, guard_*, swap_changed.
POST /api/shifts/swaps/:swapId/offers/:offerId/rejectshifts:swap + policy (owner)Turn the offer down.
POST /api/shifts/swaps/:swapId/approveshifts:lead + policyApprove a swap waiting for approval: a lead of a team whose schedule asks for it, or staff. 403 swap_party for the owner or the offerer (unless shifts:manage); 409 handover_not_allowed, guard_*, swap_changed.
POST /api/shifts/swaps/:swapId/rejectshifts:lead + policyReject it: the swap is open again. Same approvers, same 403 swap_party.
POST /api/shifts/teams/:teamId/check-inshifts:lead + policyCheck in { code }: { ok, alreadyCheckedIn, checkedInAt, assignment, shift, alsoCheckedIn }. 404, 409 outside_window, assignment_cancelled.
GET /api/shifts/teams/:teamId/exceptionsshifts:lead + policyThe exceptions of the team's shifts of the last day: [{ kind, assignment, shift, lateMinutes? }].
GET /api/shifts/teams/:teamId/stationsshifts:lead + policyThe team's stations on published schedules.
GET /api/shifts/stations/:stationId/tokenshifts:lead + policyThe station's current code: { station, token, svg, refreshAt, rotateSeconds }. 501 not_configured without a station key.
GET /api/shifts/teams/:teamId/shiftsshifts:lead + policyThe team's published shifts with their people (?from&to).
GET /api/shifts/teams/:teamId/swapsshifts:lead + policyThe team's swaps (?status, e.g. pending_approval), also those giving one of its shifts back.
POST /api/shifts/teams/:teamId/broadcastsshifts:lead + policyMessage the team { audience?, channels?, subject, message } (201). 400 audience_empty, audience_too_large; 403 for another team.
POST /api/shifts/assignments/:assignmentId/attendedshifts:lead + policyMark attended. 409 outside_window before check-in opens.
POST /api/shifts/assignments/:assignmentId/no-showshifts:lead + policyMark a no-show. 409 outside_window before check-in opens.
GET /api/shifts/operations/:operationId/nowshifts:read + policyWho is on shift now, per team, with the leads on duty.
GET /api/shifts/operations/:operationId/on-dutyshifts:read + policyThe shifts.on-duty live layer: GeoJSON points on the venue layout.
GET /api/admin/shifts/schedulesshifts:manageSchedules (?operationId) with their shift counts. Every schedule response carries stationKeyConfigured: whether a station key is available (NUXT_SHIFTS_STATION_KEY, or one derived from NUXT_APP_SECRET).
POST /api/admin/shifts/schedulesshifts:manageCreate { operationId, name, coverage?, handover?, approval?, minPerShift?, maxPerShift?, guards?, checkIn?, autoNoShow?, autoNoShowMinutes? } (201, a draft). 400 invalid_schedule_settings.
GET /api/admin/shifts/schedules/:scheduleIdshifts:manageOne schedule.
PATCH /api/admin/shifts/schedules/:scheduleIdshifts:manageChange the name, coverage, handover, approval, sizes, guards, checkIn, autoNoShow or autoNoShowMinutes. 400 invalid_schedule_settings (checked merged with the stored settings); 400 for a checkIn.teams key that is not a team of the operation.
GET /api/admin/shifts/schedules/:scheduleId/stationsshifts:manageThe schedule's stations.
POST /api/admin/shifts/schedules/:scheduleId/stationsshifts:manageAdd { teamId, name, featureId? } (201). 400 for a team of another operation or a feature that is not a station of the venue layout.
PATCH /api/admin/shifts/stations/:stationIdshifts:manageChange { name?, featureId? }.
DELETE /api/admin/shifts/stations/:stationIdshifts:manageDelete (204): its codes stop working.
DELETE /api/admin/shifts/schedules/:scheduleIdshifts:manageDelete (204). 409 schedule_in_use.
POST /api/admin/shifts/schedules/:scheduleId/publishshifts:managePublish. Again is a no-op.
POST /api/admin/shifts/schedules/:scheduleId/copy-fromshifts:manageCopy { scheduleId, offsetDays }: { schedule, roles, shifts, skippedTeamIds, changedRoleIds }.
GET /api/admin/shifts/schedules/:scheduleId/rolesshifts:manageThe shift roles.
POST /api/admin/shifts/schedules/:scheduleId/rolesshifts:manageAdd { teamId, teamRole?, name } (201).
PATCH /api/admin/shifts/roles/:roleIdshifts:manageChange { teamRole?, name? }.
DELETE /api/admin/shifts/roles/:roleIdshifts:manageDelete (204). 409 role_in_use.
GET /api/admin/shifts/schedules/:scheduleId/shiftsshifts:manageThe shifts with their people (?teamId&from&to).
POST /api/admin/shifts/schedules/:scheduleId/shifts/bulkshifts:manageCreate { teamId, days, slots, capacity?, shiftRoleId?, location?, notes? } (201, at most 500).
PATCH /api/admin/shifts/:shiftIdshifts:manageChange { startsAt?, endsAt?, capacity?, shiftRoleId?, teamId?, location?, notes? }.
DELETE /api/admin/shifts/:shiftIdshifts:manageDelete (204). 409 shift_in_use.
POST /api/admin/shifts/:shiftId/assignmentsshifts:manageAssign { userId, shiftRoleId?, force? }: { assignment, warnings } (201). 409 not_eligible, already_assigned, shift_full.
GET /api/admin/shifts/:shiftId/candidatesshifts:manageThe team's people staff could assign (?q, ?shiftRoleId, the shift's own role by default), with eligible, reason and warnings.
DELETE /api/admin/shifts/assignments/:assignmentIdshifts:manageCancel (204). 409 invalid_transition for an attended one.
GET /api/admin/shifts/swapsshifts:manageSwaps with their offers (?operationId&status).
POST /api/admin/shifts/swaps/:swapId/cancelshifts:manageCancel a live swap; settle an accepted one stuck halfway.
GET /api/admin/shifts/operations/:operationId/teamsshifts:manageThe operation's teams with their kind's ladder, for the schedule forms.
GET /api/admin/shifts/broadcastsshifts:broadcastThe operation's broadcasts (?operationId), newest first.
POST /api/admin/shifts/broadcastsshifts:broadcastSend { operationId, audience, channels, subject, message } (201) with sent: { email, sms }. SMS only when channels has sms.
GET /api/admin/shifts/operations/:operationId/perksshifts:manageThe operation's perks with how many times each was earned and not revoked (earned).
POST /api/admin/shifts/operations/:operationId/perksshifts:manageAdd { name, voucherType, quantity?, teamId? } (201, quantity 1 by default).
PATCH /api/admin/shifts/perks/:perkIdshifts:manageChange { name?, voucherType?, quantity?, teamId? }; perks earned before keep theirs.
DELETE /api/admin/shifts/perks/:perkIdshifts:manageDelete (204). 409 perk_already_earned once anybody earned it.

Emails and phone numbers need shifts:pii; without it a person has neither field. Reads that leads and volunteers make live under /api/shifts; /api/admin/shifts is for staff.

Database

Tables the module adds. Generate and commit a migration after installing.

TableHolds
shift_schedulesshs_ id, operationId, name (json), status (draft, published), coverage (all, flexible), handover (trade, release, both), approval (peer, lead), minPerShift, maxPerShift, guards (json), checkIn (json: modes, location, teams), autoNoShow (off), autoNoShowMinutes (30), publishedAt.
shift_rolesshr_ id, scheduleId, teamId, teamRole (the lowest team role, or null), name (json).
shiftsshf_ id, scheduleId, teamId, shiftRoleId, startsAt, endsAt, location (json: name, featureId), capacity, notes (json), closedAt (when the close task handled its end).
shift_assignmentssha_ id, shiftId, userId, shiftRoleId, status (assigned, attended, no_show, cancelled), checkInCode (unique), checkedInAt, checkedInBy, checkInMethod, assignedBy.
shift_swapsshw_ id, assignmentId, userId (who opened it), kind (trade, release), wantedAssignmentId (a targeted trade), status, openedAt, decidedAt.
shift_swap_offerssho_ id, swapId, userId, offeredAssignmentId (the shift given in a trade; null takes a released shift over), status (offered, accepted, rejected, withdrawn, superseded), decidedAt, approvedBy.
shift_reminderssrm_ id, assignmentId, offsetMinutes, userId, sentAt; unique on (assignmentId, offsetMinutes): the claim of a reminder.
shift_feed_tokenssft_ id, userId, tokenHash (unique), prefix, createdAt, lastUsedAt, revokedAt.
shift_broadcastsshb_ id, operationId, teamId, shiftId, teamRole, channels (json), subject and message (json, translated), recipientCount, sentBy.
shift_perksspk_ id, operationId, teamId (null is all teams), name (json), voucherType, quantity.
shift_earned_perksspg_ id, perkId, assignmentId, userId, voucherType, quantity, earnedAt, claimedAt, claimClient, revokedAt; unique on (perkId, assignmentId), indexed on (userId, claimedAt).
shift_stationssst_ id, scheduleId, teamId, name (json), featureId.
shift_digest_itemssdi_ id, kind, assignmentId, teamId, sentAt; unique on (kind, assignmentId): the claim of a digest line.

Operation, team and user ids carry no foreign key: those tables belong to other modules. Every table has a .postgresql.ts twin, and the schema parity test covers them. Runtime code uses no transactions, except the swap exchange on postgres: the conditional writes above keep the rows consistent on both dialects.

Translations

Override any string in your app's i18n/locales/<code>.json. The module registers da and en files under shifts.*. See overriding module strings.

Key groups: home.* (the tab labels), mobile.*, permissions.*, scopes.*, admin.* (with admin.tabs.*, admin.coverages.*, admin.handovers.* and admin.approvals.*), mine.*, shift.*, swaps.*, lead.*, scanner.*, now.*, statuses.*, swapStatuses.*, swapKinds.*, offerStatuses.*, warnings.*, feed.*, broadcast.*, perks.*, checkIn.*, stations.*, station.* and exceptions.*. The perks resource's permission and scope labels are under perks.permissions.* and perks.scopes.*. The email texts are the templates'; the digest's are in the module.

Next steps

  • Operations – the operation and venue layout shifts belong to.
  • Crew – where the people on shifts come from.
  • Teams – the team roles and leads shifts checks.
Copyright © 2026