only number

This commit is contained in:
monoid 2021-01-01 03:28:42 +09:00
parent 5a733b747f
commit eb771fb5b7
1 changed files with 6 additions and 20 deletions

View File

@ -7,9 +7,6 @@ import {sendError} from './error_handler';
const ContentIDHandler = (controller: ContentAccessor) => async (ctx: Context,next: Next)=>{
const num = Number.parseInt(ctx.params['num']);
if (num === NaN){
return await next();
}
let content = await controller.findById(num,true);
if (content == undefined){
sendError(404,"content does not exist.");
@ -21,9 +18,6 @@ const ContentIDHandler = (controller: ContentAccessor) => async (ctx: Context,ne
};
const ContentTagIDHandler = (controller: ContentAccessor) => async (ctx: Context,next: Next)=>{
const num = Number.parseInt(ctx.params['num']);
if (num === NaN){
return await next();
}
let content = await controller.findById(num,true);
if (content == undefined){
sendError(404,"content does not exist.");
@ -73,9 +67,6 @@ const CreateContentHandler = (controller : ContentAccessor) => async (ctx: Conte
const AddTagHandler = (controller: ContentAccessor)=>async (ctx: Context, next: Next)=>{
let tag_name = ctx.params['tag'];
const num = Number.parseInt(ctx.params['num']);
if (num === NaN){
return await next();
}
if(typeof tag_name === undefined){
sendError(400,"??? Unreachable");
}
@ -92,9 +83,6 @@ const AddTagHandler = (controller: ContentAccessor)=>async (ctx: Context, next:
const DelTagHandler = (controller: ContentAccessor)=>async (ctx: Context, next: Next)=>{
let tag_name = ctx.params['tag'];
const num = Number.parseInt(ctx.params['num']);
if (num === NaN){
return await next();
}
if(typeof tag_name === undefined){
sendError(400,"?? Unreachable");
}
@ -110,9 +98,6 @@ const DelTagHandler = (controller: ContentAccessor)=>async (ctx: Context, next:
}
const DeleteContentHandler = (controller : ContentAccessor) => async (ctx: Context, next: Next) => {
const num = Number.parseInt(ctx.params['num']);
if (num === NaN){
return await next();
}
const r = await controller.del(num);
ctx.body = {"ret":r};
ctx.type = 'json';
@ -120,12 +105,13 @@ const DeleteContentHandler = (controller : ContentAccessor) => async (ctx: Conte
export const getContentRouter = (controller: ContentAccessor)=>{
const ret = new Router();
ret.get("/search",ContentQueryHandler(controller));
ret.get("/:num",ContentIDHandler(controller));
ret.get("/:num(\\d+)",ContentIDHandler(controller));
//ret.get("/:num(\\d+)/:content_type");
ret.post("/",CreateContentHandler(controller));
ret.get("/:num/tags",ContentTagIDHandler(controller));
ret.post("/:num/tags/:tag",AddTagHandler(controller));
ret.del("/:num/tags/:tag",DelTagHandler(controller));
ret.del("/:num",DeleteContentHandler(controller));
ret.get("/:num(\\d+)/tags",ContentTagIDHandler(controller));
ret.post("/:num(\\d+)/tags/:tag",AddTagHandler(controller));
ret.del("/:num(\\d+)/tags/:tag",DelTagHandler(controller));
ret.del("/:num(\\d+)",DeleteContentHandler(controller));
//ret.get("/");
return ret;
}