1234567891011121314151617181920212223 |
- '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 NoticeService extends CrudService {
- constructor(ctx) {
- super(ctx, 'notice');
- this.model = this.ctx.model.User.Notice;
- }
- async create(body) {
- const { customer = [], ...others } = body;
- if (!_.isArray(customer)) throw new BusinessError(ErrorCode.DATA_INVALID, '数据格式错误');
- if (customer.length <= 0) throw new BusinessError(ErrorCode.BADPARAM, '缺少发送对象');
- const arr = customer.map(i => ({ customer: i, ...others }));
- await this.model.insertMany(arr);
- }
- }
- module.exports = NoticeService;
|