feat: 增加打手工单备注
This commit is contained in:
@@ -384,6 +384,50 @@ export async function updateWorkOrderShareAcceptanceRecord(input: {
|
||||
return getWorkOrderShareById(share.id)
|
||||
}
|
||||
|
||||
export async function listWorkerWorkOrderNotes(
|
||||
workerId: number | string,
|
||||
workOrderIds: number[],
|
||||
): Promise<Array<{ work_order_id: number; note: string }>> {
|
||||
if (workOrderIds.length === 0) return []
|
||||
const result = await query<{ work_order_id: number; note: string }>(
|
||||
`
|
||||
SELECT work_order_id, note
|
||||
FROM worker_work_order_notes
|
||||
WHERE worker_id = $1 AND work_order_id = ANY($2::bigint[])
|
||||
`,
|
||||
[Number(workerId), workOrderIds],
|
||||
)
|
||||
return result.rows
|
||||
}
|
||||
|
||||
export async function upsertWorkerWorkOrderNote(input: {
|
||||
workOrderId: number
|
||||
workerId: number
|
||||
note: string
|
||||
now: string
|
||||
}): Promise<string> {
|
||||
const result = await query<{ note: string }>(
|
||||
`
|
||||
INSERT INTO worker_work_order_notes (
|
||||
work_order_id, worker_id, note, created_at, updated_at
|
||||
) VALUES ($1, $2, $3, $4, $4)
|
||||
ON CONFLICT (work_order_id, worker_id) DO UPDATE
|
||||
SET note = EXCLUDED.note, updated_at = EXCLUDED.updated_at
|
||||
RETURNING note
|
||||
`,
|
||||
[input.workOrderId, input.workerId, input.note, input.now],
|
||||
)
|
||||
return String(result.rows[0]?.note || '')
|
||||
}
|
||||
|
||||
async function getWorkOrderShareById(shareId: number): Promise<WorkOrderShareRow | null> {
|
||||
const result = await query<WorkOrderShareRow>(
|
||||
`${WORK_ORDER_SHARE_SELECT} WHERE wos.id = $1 LIMIT 1`,
|
||||
[shareId],
|
||||
)
|
||||
return result.rows[0] || null
|
||||
}
|
||||
|
||||
export async function getWorkCategoryByKey(categoryKey: string): Promise<WorkCategoryRow | null> {
|
||||
const result = await query<WorkCategoryRow>(
|
||||
'SELECT * FROM work_categories WHERE category_key = $1 LIMIT 1',
|
||||
|
||||
Reference in New Issue
Block a user