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 }