From 790df5452587691cf0eacae79835a15a5196f25f Mon Sep 17 00:00:00 2001 From: monoid Date: Tue, 5 Jan 2021 21:33:37 +0900 Subject: [PATCH] fix bug --- src/route/contents.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/route/contents.ts b/src/route/contents.ts index b995cce..9ea88e4 100644 --- a/src/route/contents.ts +++ b/src/route/contents.ts @@ -59,6 +59,12 @@ const ContentQueryHandler = (controller : ContentAccessor) => async (ctx: Contex } const UpdateContentHandler = (controller : ContentAccessor) => async (ctx: Context, next: Next) => { const num = Number.parseInt(ctx.params['num']); + if(ctx.request.type !== 'json'){ + sendError(400,"update fail. invalid content type: it is not json."); + } + if(typeof ctx.request.body !== "object"){ + sendError(400,"update fail. invalid argument: not"); + } const content_desc: Partial & {id: number} = { id:num,...ctx.request.body }; @@ -130,7 +136,7 @@ export const getContentRouter = (controller: ContentAccessor)=>{ const ret = new Router(); ret.get("/search",ContentQueryHandler(controller)); ret.get("/:num(\\d+)",ContentIDHandler(controller)); - ret.get("/:num(\\d+)",UpdateContentHandler(controller)); + ret.post("/:num(\\d+)",UpdateContentHandler(controller)); ret.use("/:num(\\d+)/:content_type"); ret.post("/",CreateContentHandler(controller)); ret.get("/:num(\\d+)/tags",ContentTagIDHandler(controller));