feat: staff and the schedule on v2; managers give staff passwords (platform-v2 step 6.11, KI-014)

- staff: PUT /api/waiters/{id}/password (set, change, or take away; 6+ chars)
  so the password sign-in mode works for everyone; PUT /{id}/pin with the PIN in
  the body (was in the address: reset-pin?pin= removed); PINs 4-6 digits when
  adding; a password can be given when adding; has_password on staff; editing
  clears emptied fields and keeps usernames unique; delete only without history
  (orders, items, shifts) and never yourself
- schedule: times checked (schedule.bad_time), one person's overlapping shifts
  refused (schedule.overlap, past midnight understood), everyone active can be
  scheduled (the kitchen too), changes need core.staff.manage
- manager: src/pages/staff (list with search and filters, person dialog with
  photo, PIN / password dialog, zones) and src/pages/schedule (by person, by
  hour with opening hours, shift dialog with clash check, view settings kept in
  the browser); the never-used "automatic start/close" switches dropped; v1
  StaffTab and SchedulePage removed; ApprovalsPage loads with useLiveQuery
- tests: test_staff_v2.py (done-when on a paired screen), staff.test.mjs, e2e
  manager.mjs (add, password, sign-in on a paired till, a shift and a clash)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-19 08:05:01 +02:00
co-authored by Claude Opus 5.5
parent f31bdf42aa
commit 6643614ff6
27 changed files with 1554 additions and 1794 deletions
+91
View File
@@ -0,0 +1,91 @@
// The staff page and the weekly schedule as plain data (plan step 6.11).
import { test } from 'node:test'
import assert from 'node:assert/strict'
import {
customKeys, filterStaff, groupCounts, groupOf, staffBody, staffForm, staffProblems, validPin, zonesBody, zonesOf, zonesSummary,
} from '../src/pages/staff/staffLogic.js'
import {
addDays, clashWith, gridOf, hourMarks, hoursOf, inOpening, loadView, overlaps, placeOnDay, saveView, shiftState, weekDays, weekStartOf, weekTotals,
} from '../src/pages/schedule/scheduleLogic.js'
const staff = [
{ id: 1, full_name: 'Μαρία Κωνσταντίνου', nickname: 'Μαρία', username: 'maria', role: 'waiter', is_active: true, mobile_phone: '6901' },
{ id: 2, full_name: 'Nikos P', username: 'nikos', role: 'chef', is_active: false },
{ id: 3, full_name: 'Anna', username: 'anna', role: 'owner', is_active: true },
]
test('groups, filters (role, status, search without accents), active first', () => {
assert.equal(groupOf('barman'), 'kitchen')
assert.equal(groupOf('custom'), 'other')
assert.deepEqual(groupCounts(staff), { management: 1, kitchen: 1, service: 1, other: 0 })
assert.deepEqual(filterStaff(staff).map(m => m.id).at(-1), 2) // blocked last
assert.deepEqual(filterStaff(staff, { q: 'μαρια' }).map(m => m.id), [1])
assert.deepEqual(filterStaff(staff, { q: '6901' }).map(m => m.id), [1])
assert.deepEqual(filterStaff(staff, { status: 'blocked' }).map(m => m.id), [2])
assert.deepEqual(filterStaff(staff, { role: 'owner' }).map(m => m.id), [3])
})
test('the form: what is wrong for a new person and an edit, and the bodies', () => {
const f = { ...staffForm(null), full_name: ' Eleni ', nickname: 'Eleni', username: 'el eni', pin: '12', password: 'abc' }
assert.deepEqual(staffProblems(f, true), ['username', 'pin', 'password'])
assert.deepEqual(staffProblems({ ...f, username: 'eleni', pin: '1234', password: '' }, true), [])
assert.deepEqual(staffProblems({ ...f, username: 'eleni', hourly_rate: 'x' }, false), ['hourly_rate'])
assert.equal(validPin('123456'), true)
assert.equal(validPin('12345a'), false)
const body = staffBody({ ...f, username: 'eleni', pin: '1234', password: 'secret1', hourly_rate: '8,5' }, true)
assert.equal(body.full_name, 'Eleni')
assert.equal(body.hourly_rate, 8.5)
assert.equal(body.password, 'secret1')
assert.equal(body.language, null)
const edit = staffBody(staffForm({ ...staff[0], hourly_rate: 9, language: 'el' }), false)
assert.equal('pin' in edit, false)
assert.equal(edit.language, 'el')
assert.equal(staffBody(staffForm(staff[0]), false).language, '') // '' = as the venue
})
test('zones and the "custom keys" mark', () => {
const groups = [{ id: 1, name: 'Terrace' }, { id: 2, name: 'Inside' }]
assert.deepEqual(zonesOf({ zone_assignments: [{ group_id: null }] }), { all: true, ids: [] })
assert.equal(zonesSummary({ zone_assignments: [] }, groups), 'none')
assert.equal(zonesSummary({ zone_assignments: [{ group_id: 2 }, { group_id: 1 }] }, groups), 'Inside, Terrace')
assert.deepEqual(zonesBody({ all: true, ids: [1] }), { all_zones: true, group_ids: [] })
assert.equal(customKeys({ role: 'waiter', permissions: ['a', 'b'] }, { waiter: ['b', 'a'] }), false)
assert.equal(customKeys({ role: 'waiter', permissions: ['a'] }, { waiter: ['a', 'b'] }), true)
})
test('weeks: Monday or Sunday first, crossing months', () => {
assert.equal(weekStartOf('2026-11-19', true), '2026-11-16') // a Thursday
assert.equal(weekStartOf('2026-11-22', true), '2026-11-16') // Sunday belongs to the week before
assert.equal(weekStartOf('2026-11-22', false), '2026-11-22')
assert.deepEqual(weekDays('2026-11-30').slice(0, 3), ['2026-11-30', '2026-12-01', '2026-12-02'])
assert.equal(addDays('2026-03-28', 2), '2026-03-30') // across the clock change
})
test('shifts: hours past midnight, clashes, the grid, states, totals, the timeline', () => {
assert.equal(hoursOf('18:00', '02:00'), 8)
assert.equal(overlaps('22:00', '02:00', '01:00', '03:00'), false) // same day: 01:00 is the morning
assert.equal(overlaps('10:00', '14:00', '13:00', '19:00'), true)
const scheduled = [
{ id: 1, user_id: 7, scheduled_date: '2026-11-19', start_time: '18:00', end_time: '23:00', duration_hours: 5, estimated_pay: 40 },
{ id: 2, user_id: 7, scheduled_date: '2026-11-19', start_time: '09:00', end_time: '13:00', duration_hours: 4, estimated_pay: 32, actual_shifts: [{ is_active: true }] },
]
assert.equal(clashWith(scheduled, { userId: 7, date: '2026-11-19', start: '12:00', end: '15:00' })?.id, 2)
assert.equal(clashWith(scheduled, { userId: 7, date: '2026-11-19', start: '12:00', end: '15:00', skipId: 2 }), null)
assert.deepEqual(gridOf(scheduled)[7]['2026-11-19'].map(s => s.id), [2, 1])
assert.equal(shiftState(scheduled[0]), 'planned')
assert.equal(shiftState(scheduled[1]), 'working')
assert.deepEqual(weekTotals(scheduled), { people: { 7: { hours: 9, pay: 72 } }, hours: 9, pay: 72 })
assert.deepEqual(placeOnDay({ start_time: '02:00', end_time: '04:30' }, 6), { top: 20, height: 2.5 })
assert.equal(hourMarks(22)[2], 0)
assert.equal(inOpening(23, '18:00', '02:00'), true)
assert.equal(inOpening(3, '18:00', '02:00'), false)
})
test('the view settings stay in this browser and survive a broken store', () => {
const store = new Map()
const fake = { getItem: k => store.get(k) ?? null, setItem: (k, v) => store.set(k, v) }
saveView({ view: 'hours', mondayFirst: false }, fake)
assert.equal(loadView(fake).view, 'hours')
assert.equal(loadView(fake).firstHour, 6)
assert.equal(loadView({ getItem: () => '{bad' }).view, 'people')
})