123456789101112131415161718192021222324252627 |
- 'use strict';
- const { CrudService } = require('naf-framework-mongoose/lib/service');
- const { BusinessError, ErrorCode } = require('naf-core').Error;
- const { ObjectId } = require('mongoose').Types;
- class CardService extends CrudService {
- constructor(ctx) {
- super(ctx, 'card');
- this.model = this.ctx.model.Card;
- }
- async create(data) {
- const { password, mobile } = data;
- const is_exists = await this.model.count({ mobile });
- if (is_exists) throw new BusinessError(ErrorCode.DATA_EXISTED, '手机号已存在');
- data.password = { secret: password };
- const res = await this.model.create(data);
- return res;
- }
- async passwd({ id, password }) {
- password = { secret: password };
- const res = await this.model.update({ _id: ObjectId(id) }, { password });
- return res;
- }
- }
- module.exports = CardService;
|