彻底重构-4
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import { query } from '../db/client.js'
|
||||
|
||||
export async function createTaskEvent(taskId, eventType, payload = {}, createdAt) {
|
||||
const result = await query(
|
||||
`
|
||||
INSERT INTO task_events (
|
||||
task_id,
|
||||
event_type,
|
||||
payload_json,
|
||||
created_at
|
||||
) VALUES ($1, $2, $3::jsonb, $4)
|
||||
RETURNING *
|
||||
`,
|
||||
[
|
||||
Number(taskId),
|
||||
String(eventType || '').trim(),
|
||||
JSON.stringify(payload || {}),
|
||||
createdAt,
|
||||
],
|
||||
)
|
||||
|
||||
return result.rows[0] || null
|
||||
}
|
||||
|
||||
export async function listTaskEventsByTaskId(taskId, { limit = 20 } = {}) {
|
||||
const result = await query(
|
||||
`
|
||||
SELECT *
|
||||
FROM task_events
|
||||
WHERE task_id = $1
|
||||
ORDER BY created_at DESC, id DESC
|
||||
LIMIT $2
|
||||
`,
|
||||
[Number(taskId), Math.max(1, Number(limit || 20))],
|
||||
)
|
||||
|
||||
return result.rows
|
||||
}
|
||||
Reference in New Issue
Block a user