feat: emergency room closure for urgent maintenance tasks

- Backend housekeeping POST: when priority=urgent + category=maintenance + room_id
  → auto sets room status=maintenance with maintenance_from/to dates
  → closes room for emergency_close_days (default 1 day)
  → broadcasts room_updated WS event
- housekeeping-settings: add emergency_close_days column (migration 030, default 1)
- TechnicalPage: rename "Срочно" → "Экстренно!", show "🔒 Номер закрыт" badge for urgent active tasks
- HousekeepingPage plans tab: new "Экстренное закрытие номера" setting with day picker (1/2/3/5/7/14 days)
- api.ts HkSettings: add emergency_close_days field

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-24 11:51:42 +03:00
parent c83a9ca714
commit 0feec5c88f
6 changed files with 67 additions and 7 deletions

View File

@@ -81,6 +81,24 @@ const housekeeping: FastifyPluginAsync = async (fastify) => {
[hotelId, room_id ?? null, type, priority,
assignee_id ?? null, notes ?? null, due_date ?? null, category, photos],
)
// If priority=urgent and room_id → close the room for emergency_close_days
if (priority === 'urgent' && room_id && category === 'maintenance') {
const settings = await getHkSettings(hotelId).catch(() => null)
const closeDays = settings?.emergency_close_days ?? 1
const from = new Date().toISOString().slice(0, 10)
const toDate = new Date()
toDate.setDate(toDate.getDate() + closeDays)
const to = toDate.toISOString().slice(0, 10)
await db.query(
`UPDATE rooms SET status = 'maintenance', maintenance_from = $2, maintenance_to = $3 WHERE id = $1`,
[room_id, from, to],
)
broadcast(slug, {
type: 'room_updated',
room: { id: room_id, status: 'maintenance', maintenanceFrom: from, maintenanceTo: to },
})
}
const { rows } = await db.query(
`SELECT t.*, r.number AS room_number, r.type AS room_type, u.name AS assignee_name
FROM housekeeping_tasks t