123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- 'use strict';
- const assert = require('assert');
- const _ = require('lodash');
- const { ObjectId } = require('mongoose').Types;
- const { CrudService } = require('naf-framework-mongoose/lib/service');
- const { BusinessError, ErrorCode } = require('naf-core').Error;
- class ExpertService extends CrudService {
- constructor(ctx) {
- super(ctx, 'expert');
- this.model = this.ctx.model.Expert;
- this.umodel = this.ctx.model.User;
- }
- async update({ id }, data) {
- const expert = await this.model.findById(id);
- const { name, gender, id_number, phone, address, birthday, email, img_url, level, levelname, position, school, education, degree, major, profession, resume, project, academic, status } = data;
- const user = (await this.umodel.find({ userid: id }))[0];
- if (name) {
- user.name = name;
- expert.name = name;
- await user.save();
- }
- if (gender) {
- expert.gender = gender;
- }
- if (phone) {
- const _user = await this.umodel.find({ phone });
- console.log(phone);
- console.log(_user);
- if (_user.length === 0 || (_user.lenght === 1 && _user[0].id === user.id)) {
- user.phone = phone;
- expert.phone = phone;
- await user.save();
- } else {
- throw new BusinessError(ErrorCode.DATA_EXISTED);
- }
- }
- if (address) {
- expert.address = address;
- }
- if (birthday) {
- expert.birthday = birthday;
- }
- if (id_number) {
- expert.id_number = id_number;
- }
- if (email) {
- expert.email = email;
- }
- if (img_url) {
- expert.img_url = img_url;
- }
- if (level) {
- expert.level = level;
- }
- if (levelname) {
- expert.levelname = levelname;
- }
- if (position) {
- expert.position = position;
- }
- if (school) {
- expert.school = school;
- }
- if (education) {
- expert.education = education;
- }
- if (degree) {
- expert.degree = degree;
- }
- if (major) {
- expert.major = major;
- }
- if (profession) {
- expert.profession = profession;
- }
- if (resume) {
- expert.resume = resume;
- }
- if (project) {
- expert.project = project;
- }
- if (academic) {
- expert.academic = academic;
- }
- if (status) {
- expert.status = status;
- }
- const res = await expert.save();
- return res;
- }
- }
- module.exports = ExpertService;
|