public
anord
read
Ledger
Why work hard when you can work easier?
Languages
Repository composition by tracked source files.
TypeScript
86%
CSS
10%
SQL
3%
Shell
1%
HTML
0%
Trace
apps/api/src/http/routes/feedback.ts
Trace helps you understand code history line by line. See who changed each line, when it changed, and which commit introduced it.
Author
Date
Commit
Line
Code
1
import { Router } from "express";
2
import { z } from "zod";
3
import { pool } from "../../db/pool.js";
4
import { enqueueWebhookEvent } from "../../services/webhooks.js";
5
import { logAudit } from "../../services/audit.js";
7
const feedbackSchema = z.object({
8
pageId: z.string().uuid(),
9
revisionId: z.string().uuid().optional(),
10
helpful: z.boolean(),
11
comment: z.string().max(1000).optional()
12
});
14
export const feedbackRouter = Router();
16
feedbackRouter.post("/", async (req, res) => {
17
const input = feedbackSchema.parse(req.body);
19
const result = await pool.query(
20
`
21
INSERT INTO feedback (page_id, page_revision_id, user_id, helpful, comment)
22
VALUES ($1, $2, $3, $4, $5)
23
RETURNING id
24
`,
25
[
26
input.pageId,
27
input.revisionId ?? null,
28
req.user?.id ?? null,
29
input.helpful,
30
input.comment ?? null
31
]
32
);
34
await enqueueWebhookEvent("feedback.created", {
35
feedbackId: result.rows[0].id,
36
pageId: input.pageId,
37
helpful: input.helpful
38
}, {
39
actor: req.user
40
? {
41
id: req.user.id,
42
name: req.user.displayName,
43
email: req.user.email
44
}
45
: null
46
});
48
await logAudit(req.user?.id ?? null, "feedback.create", "feedback", result.rows[0].id, {
49
pageId: input.pageId
50
});
52
return res.status(201).json({ feedbackId: result.rows[0].id });
53
});