Add repair notes journal with running feed, visibility, and status tagging

New repair_note table for timestamped journal entries on tickets. Each
note captures author, content, visibility (internal or customer-facing),
and the ticket status at time of writing. Notes display as a running
feed on the ticket detail page with newest first. Internal notes have
a lock icon, customer-visible notes highlighted in blue. Supports add
and delete with appropriate permission gating.
This commit is contained in:
Ryan Moon
2026-03-29 10:27:39 -05:00
parent 01cff80f2b
commit 7eac03f6c2
11 changed files with 334 additions and 2 deletions

View File

@@ -5,6 +5,7 @@ import {
repairLineItems,
repairBatches,
repairServiceTemplates,
repairNotes,
} from '../db/schema/repairs.js'
import type {
RepairTicketCreateInput,
@@ -13,6 +14,7 @@ import type {
RepairLineItemUpdateInput,
RepairBatchCreateInput,
RepairBatchUpdateInput,
RepairNoteCreateInput,
RepairServiceTemplateCreateInput,
RepairServiceTemplateUpdateInput,
PaginationInput,
@@ -457,3 +459,36 @@ export const RepairServiceTemplateService = {
return template ?? null
},
}
export const RepairNoteService = {
async create(db: PostgresJsDatabase<any>, ticketId: string, authorId: string, authorName: string, ticketStatus: string, input: RepairNoteCreateInput) {
const [note] = await db
.insert(repairNotes)
.values({
repairTicketId: ticketId,
authorId,
authorName,
content: input.content,
visibility: input.visibility,
ticketStatus: ticketStatus as any,
})
.returning()
return note
},
async listByTicket(db: PostgresJsDatabase<any>, ticketId: string) {
return db
.select()
.from(repairNotes)
.where(eq(repairNotes.repairTicketId, ticketId))
.orderBy(repairNotes.createdAt)
},
async delete(db: PostgresJsDatabase<any>, id: string) {
const [note] = await db
.delete(repairNotes)
.where(eq(repairNotes.id, id))
.returning()
return note ?? null
},
}