diff options
author | HampusM <hampus@hampusmat.com> | 2021-08-15 15:03:44 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2021-08-15 15:03:44 +0200 |
commit | 9736749a779661a95211a91200617a03a1b9a702 (patch) | |
tree | 6bea5e5ec5773aa940e79e7e80c9ebac086eaa10 /packages/server/src/routes/api/v1 | |
parent | c32094d0b1fc3aa5160087d71bff36ed1779bc3a (diff) |
Added a count query parameter to the log API endpoint
Diffstat (limited to 'packages/server/src/routes/api/v1')
-rw-r--r-- | packages/server/src/routes/api/v1/index.ts | 6 | ||||
-rw-r--r-- | packages/server/src/routes/api/v1/repo/log.ts | 7 |
2 files changed, 12 insertions, 1 deletions
diff --git a/packages/server/src/routes/api/v1/index.ts b/packages/server/src/routes/api/v1/index.ts index fa7d8ab..fb9cd8a 100644 --- a/packages/server/src/routes/api/v1/index.ts +++ b/packages/server/src/routes/api/v1/index.ts @@ -9,6 +9,12 @@ import { ServerError } from "../../../git/error"; function setHandlers(fastify: FastifyInstance): void { fastify.setErrorHandler((err, req, reply) => { console.log(err); + + if(err.validation) { + reply.code(400).send({ error: `${err.validation[0].dataPath} ${err.validation[0].message}` }); + return; + } + reply.code(500).send({ error: "Internal server error!" }); }); fastify.setNotFoundHandler((req, reply) => { diff --git a/packages/server/src/routes/api/v1/repo/log.ts b/packages/server/src/routes/api/v1/repo/log.ts index aaad042..edca0b3 100644 --- a/packages/server/src/routes/api/v1/repo/log.ts +++ b/packages/server/src/routes/api/v1/repo/log.ts @@ -21,8 +21,13 @@ export default function(fastify: FastifyInstance, opts: FastifyPluginOptions, do fastify.route<Route>({ method: "GET", url: "/log", + schema: { + querystring: { + count: { type: "number" } + } + }, handler: async(req, reply) => { - const commits = await req.repository.commits(); + const commits = await req.repository.commits(Number(req.query.count)); reply.send({ data: await Promise.all(commits.map(commitMap)) |