123456789101112131415161718192021222324252627 |
- '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');
- // 咨询师
- class AnswerTeaService extends CrudService {
- constructor(ctx) {
- super(ctx, 'answer_tea');
- this.model = this.ctx.model.Patent.AnswerTea;
- }
- async login({ phone, password }) {
- const object = await this.model.findOne({ phone }, '+password');
- if (!object) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到用户的信息');
- const { password: op } = object;
- const { secret } = op;
- if (secret !== password) throw new BusinessError(ErrorCode.BAD_PASSWORD, '密码错误');
- const data = _.omit(JSON.parse(JSON.stringify(object)), ['meta', 'password', '__v']);
- const { secret: secrets } = this.config.jwt;
- const jwt = require('jsonwebtoken');
- const token = jwt.sign(data, secrets);
- return token;
- }
- }
- module.exports = AnswerTeaService;
|