This commit is contained in:
monoid 2021-01-05 21:33:37 +09:00
parent 6b2cd65434
commit 790df54525

View File

@ -59,6 +59,12 @@ const ContentQueryHandler = (controller : ContentAccessor) => async (ctx: Contex
} }
const UpdateContentHandler = (controller : ContentAccessor) => async (ctx: Context, next: Next) => { const UpdateContentHandler = (controller : ContentAccessor) => async (ctx: Context, next: Next) => {
const num = Number.parseInt(ctx.params['num']); 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<Content> & {id: number} = { const content_desc: Partial<Content> & {id: number} = {
id:num,...ctx.request.body id:num,...ctx.request.body
}; };
@ -130,7 +136,7 @@ export const getContentRouter = (controller: ContentAccessor)=>{
const ret = new Router(); const ret = new Router();
ret.get("/search",ContentQueryHandler(controller)); ret.get("/search",ContentQueryHandler(controller));
ret.get("/:num(\\d+)",ContentIDHandler(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.use("/:num(\\d+)/:content_type");
ret.post("/",CreateContentHandler(controller)); ret.post("/",CreateContentHandler(controller));
ret.get("/:num(\\d+)/tags",ContentTagIDHandler(controller)); ret.get("/:num(\\d+)/tags",ContentTagIDHandler(controller));