fix: room number + photos in task cards; time tracking for tasks
- Backend POST housekeeping: include photos in INSERT, return task with room JOIN - Backend PATCH housekeeping: set started_at on in_progress, return task with room JOIN - WS broadcasts now include room_number/assignee_name from JOIN - Frontend: normalizeTask() helper maps snake_case WS fields to camelCase - TechnicalPage: fix room number display (roomNumber || room_number) - TechnicalPage: show time spent (started_at → completed_at) on task cards - HousekeepingPage: history tab now includes maintenance reports (no category filter) - HousekeepingPage: HistoryCard shows photos, notes, time spent, maintenance styling - Migration 028: started_at TIMESTAMPTZ column on housekeeping_tasks - types: add startedAt? to HousekeepingTask Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1
backend/migrations/028_task_started_at.sql
Normal file
1
backend/migrations/028_task_started_at.sql
Normal file
@@ -0,0 +1 @@
|
||||
ALTER TABLE housekeeping_tasks ADD COLUMN IF NOT EXISTS started_at TIMESTAMPTZ;
|
||||
@@ -60,7 +60,7 @@ const housekeeping: FastifyPluginAsync = async (fastify) => {
|
||||
// ── POST /api/hotels/:slug/housekeeping ────────────────────────────────────
|
||||
fastify.post<SlugParam & { Body: {
|
||||
room_id?: string; type: string; priority?: string
|
||||
assignee_id?: string; notes?: string; due_date?: string; category?: string
|
||||
assignee_id?: string; notes?: string; due_date?: string; category?: string; photos?: string[]
|
||||
} }>(
|
||||
'/api/hotels/:slug/housekeeping',
|
||||
{ onRequest: [fastify.authenticate] },
|
||||
@@ -72,13 +72,21 @@ const housekeeping: FastifyPluginAsync = async (fastify) => {
|
||||
const hotelId = await getHotelId(slug)
|
||||
if (!hotelId) return reply.code(404).send({ error: 'Hotel not found' })
|
||||
|
||||
const { room_id, type, priority = 'medium', assignee_id, notes, due_date, category = 'housekeeping' } = request.body
|
||||
const { rows } = await db.query(
|
||||
const { room_id, type, priority = 'medium', assignee_id, notes, due_date, category = 'housekeeping', photos = [] } = request.body
|
||||
const { rows: inserted } = await db.query(
|
||||
`INSERT INTO housekeeping_tasks
|
||||
(hotel_id, room_id, type, priority, assignee_id, notes, due_date, category)
|
||||
VALUES ($1,$2,$3,$4,$5,$6,$7,$8) RETURNING *`,
|
||||
(hotel_id, room_id, type, priority, assignee_id, notes, due_date, category, photos)
|
||||
VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9) RETURNING id`,
|
||||
[hotelId, room_id ?? null, type, priority,
|
||||
assignee_id ?? null, notes ?? null, due_date ?? null, category],
|
||||
assignee_id ?? null, notes ?? null, due_date ?? null, category, photos],
|
||||
)
|
||||
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
|
||||
LEFT JOIN rooms r ON r.id = t.room_id
|
||||
LEFT JOIN users u ON u.id = t.assignee_id
|
||||
WHERE t.id = $1`,
|
||||
[inserted[0].id],
|
||||
)
|
||||
return reply.code(201).send(rows[0])
|
||||
},
|
||||
@@ -109,7 +117,10 @@ const housekeeping: FastifyPluginAsync = async (fastify) => {
|
||||
}
|
||||
}
|
||||
|
||||
// Auto-set completed_at when marking done
|
||||
// Auto-set timestamps based on status transitions
|
||||
if (request.body.status === 'in_progress') {
|
||||
updates.push(`started_at = COALESCE(started_at, NOW())`)
|
||||
}
|
||||
if (request.body.status === 'done') {
|
||||
updates.push(`completed_at = NOW()`)
|
||||
} else if (request.body.status && request.body.status !== 'done') {
|
||||
@@ -119,12 +130,21 @@ const housekeeping: FastifyPluginAsync = async (fastify) => {
|
||||
if (updates.length === 0) return reply.code(400).send({ error: 'Nothing to update' })
|
||||
values.push(id, hotelId)
|
||||
|
||||
const { rows } = await db.query(
|
||||
const { rows: updated } = await db.query(
|
||||
`UPDATE housekeeping_tasks SET ${updates.join(', ')}
|
||||
WHERE id = $${idx} AND hotel_id = $${idx + 1} RETURNING *`,
|
||||
WHERE id = $${idx} AND hotel_id = $${idx + 1} RETURNING id`,
|
||||
values,
|
||||
)
|
||||
if (!rows[0]) return reply.code(404).send({ error: 'Task not found' })
|
||||
if (!updated[0]) return reply.code(404).send({ error: 'Task not found' })
|
||||
|
||||
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
|
||||
LEFT JOIN rooms r ON r.id = t.room_id
|
||||
LEFT JOIN users u ON u.id = t.assignee_id
|
||||
WHERE t.id = $1`,
|
||||
[updated[0].id],
|
||||
)
|
||||
const task = rows[0]
|
||||
|
||||
// When task is marked in_progress → room becomes 'cleaning'
|
||||
|
||||
Reference in New Issue
Block a user