fix type error on 'additional'
This commit is contained in:
parent
8d072c82c6
commit
3f1f3abbe1
@ -51,9 +51,9 @@ class KnexContentsAccessor implements ContentAccessor{
|
|||||||
ret_tags = tags.map(x=>x.tag_name);
|
ret_tags = tags.map(x=>x.tag_name);
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
|
...first,
|
||||||
tags:ret_tags,
|
tags:ret_tags,
|
||||||
additional: JSON.parse(first.additional || "{}"),
|
additional: JSON.parse(first.additional || "{}"),
|
||||||
...first
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
async findList(option?:QueryListOption){
|
async findList(option?:QueryListOption){
|
||||||
@ -120,9 +120,9 @@ class KnexContentsAccessor implements ContentAccessor{
|
|||||||
async findListByBasePath(path:string):Promise<Content[]>{
|
async findListByBasePath(path:string):Promise<Content[]>{
|
||||||
let results = await this.knex.select("*").from("contents").where({basepath:path});
|
let results = await this.knex.select("*").from("contents").where({basepath:path});
|
||||||
return results.map(x=>({
|
return results.map(x=>({
|
||||||
additional:JSON.parse(x.additional || "{}"),
|
...x,
|
||||||
tags:[],
|
tags:[],
|
||||||
...x
|
additional:JSON.parse(x.additional || "{}"),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
async update(c:Partial<Content> & { id:number }){
|
async update(c:Partial<Content> & { id:number }){
|
||||||
|
@ -17,7 +17,7 @@ const ContentIDHandler = (controller: ContentAccessor) => async (ctx: Context,ne
|
|||||||
}
|
}
|
||||||
ctx.body = content;
|
ctx.body = content;
|
||||||
ctx.type = 'json';
|
ctx.type = 'json';
|
||||||
return await next();
|
console.log(content.additional);
|
||||||
};
|
};
|
||||||
const ContentTagIDHandler = (controller: ContentAccessor) => async (ctx: Context,next: Next)=>{
|
const ContentTagIDHandler = (controller: ContentAccessor) => async (ctx: Context,next: Next)=>{
|
||||||
const num = Number.parseInt(ctx.params['num']);
|
const num = Number.parseInt(ctx.params['num']);
|
||||||
@ -28,7 +28,6 @@ const ContentTagIDHandler = (controller: ContentAccessor) => async (ctx: Context
|
|||||||
}
|
}
|
||||||
ctx.body = content.tags || [];
|
ctx.body = content.tags || [];
|
||||||
ctx.type = 'json';
|
ctx.type = 'json';
|
||||||
return await next();
|
|
||||||
};
|
};
|
||||||
const ContentQueryHandler = (controller : ContentAccessor) => async (ctx: Context,next: Next)=>{
|
const ContentQueryHandler = (controller : ContentAccessor) => async (ctx: Context,next: Next)=>{
|
||||||
const limit = ParseQueryNumber(ctx.query['limit']);
|
const limit = ParseQueryNumber(ctx.query['limit']);
|
||||||
@ -139,7 +138,7 @@ export const getContentRouter = (controller: ContentAccessor)=>{
|
|||||||
ret.get("/search",ContentQueryHandler(controller));
|
ret.get("/search",ContentQueryHandler(controller));
|
||||||
ret.get("/:num(\\d+)",ContentIDHandler(controller));
|
ret.get("/:num(\\d+)",ContentIDHandler(controller));
|
||||||
ret.post("/: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));
|
||||||
ret.post("/:num(\\d+)/tags/:tag",AddTagHandler(controller));
|
ret.post("/:num(\\d+)/tags/:tag",AddTagHandler(controller));
|
||||||
|
Loading…
Reference in New Issue
Block a user