'use strict'; const { CrudService } = require('naf-framework-mongoose-free/lib/service'); const { BusinessError, ErrorCode } = require('naf-core').Error; const _ = require('lodash'); const assert = require('assert'); const moment = require('moment'); // class StoreShopService extends CrudService { constructor(ctx) { super(ctx, 'storeshop'); this.model = this.ctx.model.User.StoreShop; } async create({ shop }) { assert(shop, '缺少店铺信息'); const customer = _.get(this.ctx, 'user._id'); assert(customer, '缺少用户信息'); let data = await this.model.findOne({ customer, shop }); if (data) { await this.model.deleteOne({ customer, shop }); return { msg: '取消收藏', result: false }; } data = await this.model.create({ customer, shop, time: moment().format('YYYY-MM-DD HH:mm:ss') }); return { msg: '收藏成功', result: true }; } // 用户查看收藏店铺 async userView() {} // 检查是否收藏店铺 async check({ shop, customer }) { const num = await this.model.count({ shop, customer }); return num > 0; } } module.exports = StoreShopService;