documents.js 590 B

1234567891011121314151617
  1. import { Router } from "express";
  2. import { z } from "zod";
  3. import { listDocuments } from "../services/documentsService.js";
  4. export const documentsRouter = Router();
  5. documentsRouter.get("/", async (req, res, next) => {
  6. try {
  7. const limit = z.coerce.number().int().positive().max(200).catch(50).parse(req.query.limit);
  8. const offsetRaw = z.string().optional().parse(req.query.offset);
  9. const offset = offsetRaw && offsetRaw !== "0" ? offsetRaw : undefined;
  10. const result = await listDocuments({ limit, offset });
  11. res.json(result);
  12. } catch (err) {
  13. next(err);
  14. }
  15. });