1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- '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 CompanyService extends CrudService {
- constructor(ctx) {
- super(ctx, 'company');
- this.model = this.ctx.model.Company;
- }
- // 更新其他信息
- async updateotherinfo({ id }, data) {
- assert(id, 'id为必填项');
- const { _id, info_name, remark, url_info } = data;
- assert(_id, '_id为必填项');
- const company = await this.model.findById(id);
- if (!company) {
- throw new BusinessError(ErrorCode.DATA_NOT_EXIST);
- }
- const otherinfo = company.other_info.id(_id);
- otherinfo.info_name = info_name;
- otherinfo.remark = remark;
- otherinfo.url_info = url_info;
- const res = await company.save();
- return res;
- }
- // 删除其他信息
- async deleteotherinfo({ id }, { _id }) {
- assert(id, 'id为必填项');
- assert(_id, '_id为必填项');
- const company = await this.model.findById(id);
- if (!company) {
- throw new BusinessError(ErrorCode.DATA_NOT_EXIST);
- }
- company.other_info.id(_id).remove();
- const res = await company.save();
- return res;
- }
- }
- module.exports = CompanyService;
|