fix type error on 'additional'

This commit is contained in:
monoid 2021-01-10 15:45:55 +09:00
parent 8d072c82c6
commit 3f1f3abbe1
2 changed files with 5 additions and 6 deletions

View File

@ -51,9 +51,9 @@ class KnexContentsAccessor implements ContentAccessor{
ret_tags = tags.map(x=>x.tag_name);
}
return {
...first,
tags:ret_tags,
additional: JSON.parse(first.additional || "{}"),
...first
};
};
async findList(option?:QueryListOption){
@ -120,9 +120,9 @@ class KnexContentsAccessor implements ContentAccessor{
async findListByBasePath(path:string):Promise<Content[]>{
let results = await this.knex.select("*").from("contents").where({basepath:path});
return results.map(x=>({
additional:JSON.parse(x.additional || "{}"),
...x,
tags:[],
...x
additional:JSON.parse(x.additional || "{}"),
}));
}
async update(c:Partial<Content> & { id:number }){

View File

@ -17,7 +17,7 @@ const ContentIDHandler = (controller: ContentAccessor) => async (ctx: Context,ne
}
ctx.body = content;
ctx.type = 'json';
return await next();
console.log(content.additional);
};
const ContentTagIDHandler = (controller: ContentAccessor) => async (ctx: Context,next: Next)=>{
const num = Number.parseInt(ctx.params['num']);
@ -28,7 +28,6 @@ const ContentTagIDHandler = (controller: ContentAccessor) => async (ctx: Context
}
ctx.body = content.tags || [];
ctx.type = 'json';
return await next();
};
const ContentQueryHandler = (controller : ContentAccessor) => async (ctx: Context,next: Next)=>{
const limit = ParseQueryNumber(ctx.query['limit']);
@ -139,7 +138,7 @@ export const getContentRouter = (controller: ContentAccessor)=>{
ret.get("/search",ContentQueryHandler(controller));
ret.get("/:num(\\d+)",ContentIDHandler(controller));
ret.post("/:num(\\d+)",UpdateContentHandler(controller));
ret.use("/:num(\\d+)/:content_type");
//ret.use("/:num(\\d+)/:content_type");
ret.post("/",CreateContentHandler(controller));
ret.get("/:num(\\d+)/tags",ContentTagIDHandler(controller));
ret.post("/:num(\\d+)/tags/:tag",AddTagHandler(controller));