|
| 1 | +import type { Request, Response } from 'express' |
| 2 | +import { z } from 'zod' |
| 3 | + |
| 4 | +import { listStewardshipActivity } from '@crowd/data-access-layer' |
| 5 | + |
| 6 | +import { getPackagesQx } from '@/db/packagesDb' |
| 7 | +import { ok } from '@/utils/api' |
| 8 | +import { validateOrThrow } from '@/utils/validation' |
| 9 | + |
| 10 | +const querySchema = z.object({ |
| 11 | + page: z.coerce.number().int().min(1).default(1), |
| 12 | + pageSize: z.coerce.number().int().min(1).max(100).default(25), |
| 13 | +}) |
| 14 | + |
| 15 | +export async function activityFeedHandler(req: Request, res: Response): Promise<void> { |
| 16 | + const { page, pageSize } = validateOrThrow(querySchema, req.query) |
| 17 | + |
| 18 | + const qx = await getPackagesQx() |
| 19 | + const { rows, total } = await listStewardshipActivity(qx, { page, pageSize }) |
| 20 | + |
| 21 | + ok(res, { |
| 22 | + rows: rows.map((r) => ({ |
| 23 | + id: r.id, |
| 24 | + stewardshipId: r.stewardshipId, |
| 25 | + packagePurl: r.packagePurl, |
| 26 | + packageName: r.packageName, |
| 27 | + packageEcosystem: r.packageEcosystem, |
| 28 | + actorUserId: r.actorUserId, |
| 29 | + actorName: r.actorUserId, // TODO: resolve display name from crowd.dev users/members table by actorUserId |
| 30 | + actorType: r.actorType, |
| 31 | + activityType: r.activityType, |
| 32 | + content: r.content, |
| 33 | + metadata: r.metadata, |
| 34 | + stewardshipStatus: r.stewardshipStatus, |
| 35 | + createdAt: r.createdAt, |
| 36 | + })), |
| 37 | + total, |
| 38 | + page, |
| 39 | + pageSize, |
| 40 | + }) |
| 41 | +} |
0 commit comments