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:
@@ -8,6 +8,7 @@ export interface HkSettings {
|
||||
checkout_priority: string
|
||||
inspection_after_clean: boolean
|
||||
require_completion_photo: boolean
|
||||
emergency_close_days: number
|
||||
}
|
||||
|
||||
const DEFAULT_SETTINGS: HkSettings = {
|
||||
@@ -15,11 +16,12 @@ const DEFAULT_SETTINGS: HkSettings = {
|
||||
checkout_priority: 'high',
|
||||
inspection_after_clean: true,
|
||||
require_completion_photo: false,
|
||||
emergency_close_days: 1,
|
||||
}
|
||||
|
||||
export async function getHkSettings(hotelId: string): Promise<HkSettings> {
|
||||
const { rows } = await db.query(
|
||||
'SELECT checkout_auto, checkout_priority, inspection_after_clean, require_completion_photo FROM housekeeping_settings WHERE hotel_id = $1',
|
||||
'SELECT checkout_auto, checkout_priority, inspection_after_clean, require_completion_photo, emergency_close_days FROM housekeeping_settings WHERE hotel_id = $1',
|
||||
[hotelId],
|
||||
)
|
||||
return rows[0] ?? DEFAULT_SETTINGS
|
||||
@@ -59,15 +61,16 @@ const housekeepingSettings: FastifyPluginAsync = async (fastify) => {
|
||||
const hotelId = await getHotelId(slug)
|
||||
if (!hotelId) return reply.code(404).send({ error: 'Hotel not found' })
|
||||
|
||||
const { checkout_auto, checkout_priority, inspection_after_clean, require_completion_photo } = request.body
|
||||
const { checkout_auto, checkout_priority, inspection_after_clean, require_completion_photo, emergency_close_days } = request.body
|
||||
await db.query(
|
||||
`INSERT INTO housekeeping_settings (hotel_id, checkout_auto, checkout_priority, inspection_after_clean, require_completion_photo)
|
||||
VALUES ($1, $2, $3, $4, $5)
|
||||
`INSERT INTO housekeeping_settings (hotel_id, checkout_auto, checkout_priority, inspection_after_clean, require_completion_photo, emergency_close_days)
|
||||
VALUES ($1, $2, $3, $4, $5, $6)
|
||||
ON CONFLICT (hotel_id) DO UPDATE SET
|
||||
checkout_auto = COALESCE(EXCLUDED.checkout_auto, housekeeping_settings.checkout_auto),
|
||||
checkout_priority = COALESCE(EXCLUDED.checkout_priority, housekeeping_settings.checkout_priority),
|
||||
inspection_after_clean = COALESCE(EXCLUDED.inspection_after_clean, housekeeping_settings.inspection_after_clean),
|
||||
require_completion_photo = COALESCE(EXCLUDED.require_completion_photo, housekeeping_settings.require_completion_photo),
|
||||
emergency_close_days = COALESCE(EXCLUDED.emergency_close_days, housekeeping_settings.emergency_close_days),
|
||||
updated_at = NOW()`,
|
||||
[
|
||||
hotelId,
|
||||
@@ -75,6 +78,7 @@ const housekeepingSettings: FastifyPluginAsync = async (fastify) => {
|
||||
checkout_priority ?? DEFAULT_SETTINGS.checkout_priority,
|
||||
inspection_after_clean ?? DEFAULT_SETTINGS.inspection_after_clean,
|
||||
require_completion_photo ?? DEFAULT_SETTINGS.require_completion_photo,
|
||||
emergency_close_days ?? DEFAULT_SETTINGS.emergency_close_days,
|
||||
],
|
||||
)
|
||||
return getHkSettings(hotelId)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user