From 3f1f3abbe1d8525010c8e58c580ee235dd11c019 Mon Sep 17 00:00:00 2001 From: monoid Date: Sun, 10 Jan 2021 15:45:55 +0900 Subject: [PATCH] fix type error on 'additional' --- src/db/contents.ts | 6 +++--- src/route/contents.ts | 5 ++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/db/contents.ts b/src/db/contents.ts index 67c92d5..bd310d7 100644 --- a/src/db/contents.ts +++ b/src/db/contents.ts @@ -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{ 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 & { id:number }){ diff --git a/src/route/contents.ts b/src/route/contents.ts index 7b1125a..5894ae7 100644 --- a/src/route/contents.ts +++ b/src/route/contents.ts @@ -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));