From 7ab55c8556c52a30cf7cfa2ac33bb62ac3b712c6 Mon Sep 17 00:00:00 2001 From: zhl Date: Fri, 14 May 2021 19:59:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=BA=97=E9=93=BA=E7=9A=84?= =?UTF-8?q?=E5=AE=A1=E6=A0=B8=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/admin/controllers/shop.controller.ts | 13 +++++++++++++ src/models/shop/Shop.ts | 20 ++++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/admin/controllers/shop.controller.ts b/src/admin/controllers/shop.controller.ts index 6328a3c..c7ef5bc 100644 --- a/src/admin/controllers/shop.controller.ts +++ b/src/admin/controllers/shop.controller.ts @@ -81,6 +81,19 @@ class ShopController extends BaseController { return record.toJson() } + @permission(['shopman:review']) + @router('post /shop/publish') + async publish(req: any) { + let { id, publish } = req.params + let record = await Shop.findById(id) + if (!record) { + throw new ZError(11, 'record not found') + } + record.publish = publish + await record.save() + return record.toJson() + } + @permission(['shop:delete','shopman:delete']) @router('post /shop/:id/delete') async delete(req: any) { diff --git a/src/models/shop/Shop.ts b/src/models/shop/Shop.ts index 467c7d9..ed7098c 100644 --- a/src/models/shop/Shop.ts +++ b/src/models/shop/Shop.ts @@ -63,6 +63,9 @@ class ShopClass extends BaseModule { @prop({ type: () => [Number] }) public location: number[] + + @prop({default: false}) + public publish: boolean /** * 是否删除 * @type {boolean} @@ -120,8 +123,8 @@ class ShopClass extends BaseModule { public static parseQueryParam(params) { - let {key, timeBegin, timeEnd} = params - let opt: any = {deleted: false, show: true} + let {key, timeBegin, timeEnd, publish} = params + let opt: any = {deleted: false, show: true, publish: true} if (key) { opt.name = {$regex: key, $options: 'i'} } @@ -132,6 +135,19 @@ class ShopClass extends BaseModule { } else if (!timeBegin && timeEnd) { opt.createdAt = {$lte: timeEnd}; } + if (publish !== undefined) { + if (typeof publish === 'boolean') { + opt.publish = publish + } else { + if (publish === 'all') { + delete opt.publish + } else if (publish === 'true') { + opt.publish = true + } else if (publish === 'false') { + opt.publish = false + } + } + } let sort = {_id: -1} return { opt, sort }