R63 A1-A6:通知中心体验增强
这个提交包含在:
@@ -18,6 +18,7 @@ const LIST_QUERY_SCHEMA = z.object({
|
||||
page: z.coerce.number().int().min(1).optional(),
|
||||
pageSize: z.coerce.number().int().min(1).max(100).optional(),
|
||||
unreadOnly: z.enum(['0', '1', 'true', 'false']).optional(),
|
||||
type: z.string().optional(),
|
||||
});
|
||||
const DELIVERY_STATUS_VALUES = Object.freeze(['pending', 'success', 'failed']);
|
||||
const DELIVERY_QUERY_SCHEMA = z.object({
|
||||
@@ -140,11 +141,18 @@ function parseListQuery(query) {
|
||||
const pageSize = parsed.data.pageSize ?? 20;
|
||||
const unreadOnlyRaw = parsed.data.unreadOnly ?? '0';
|
||||
const unreadOnly = unreadOnlyRaw === '1' || unreadOnlyRaw === 'true';
|
||||
const types = uniqStrings(
|
||||
String(parsed.data.type ?? '')
|
||||
.split(',')
|
||||
.map((item) => item.trim())
|
||||
.filter(Boolean),
|
||||
);
|
||||
|
||||
return {
|
||||
page,
|
||||
pageSize,
|
||||
unreadOnly,
|
||||
types,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -362,6 +370,7 @@ async function notificationsRoutes(fastify) {
|
||||
const where = {
|
||||
recipient_employee_id: request.employee.id,
|
||||
...(query.unreadOnly ? { read_at: null } : {}),
|
||||
...(query.types.length ? { type: { in: query.types } } : {}),
|
||||
};
|
||||
|
||||
const [items, total, unreadCount] = await Promise.all([
|
||||
@@ -401,6 +410,28 @@ async function notificationsRoutes(fastify) {
|
||||
},
|
||||
);
|
||||
|
||||
fastify.post(
|
||||
'/notifications/mark-all-read',
|
||||
{
|
||||
preHandler: fastify.authenticate,
|
||||
},
|
||||
async (request, reply) => {
|
||||
const result = await fastify.prisma.notification.updateMany({
|
||||
where: {
|
||||
recipient_employee_id: request.employee.id,
|
||||
read_at: null,
|
||||
},
|
||||
data: {
|
||||
read_at: new Date(),
|
||||
},
|
||||
});
|
||||
|
||||
return sendData(reply, request, {
|
||||
updatedCount: Number(result?.count ?? 0),
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
fastify.post(
|
||||
'/notifications/:id/mark-read',
|
||||
{
|
||||
|
||||
在新工单中引用
屏蔽一个用户