notice.js 770 B

1234567891011121314151617181920212223
  1. 'use strict';
  2. const { CrudService } = require('naf-framework-mongoose-free/lib/service');
  3. const { BusinessError, ErrorCode } = require('naf-core').Error;
  4. const _ = require('lodash');
  5. const assert = require('assert');
  6. //
  7. class NoticeService extends CrudService {
  8. constructor(ctx) {
  9. super(ctx, 'notice');
  10. this.model = this.ctx.model.User.Notice;
  11. }
  12. async create(body) {
  13. const { customer = [], ...others } = body;
  14. if (!_.isArray(customer)) throw new BusinessError(ErrorCode.DATA_INVALID, '数据格式错误');
  15. if (customer.length <= 0) throw new BusinessError(ErrorCode.BADPARAM, '缺少发送对象');
  16. const arr = customer.map(i => ({ customer: i, ...others }));
  17. await this.model.insertMany(arr);
  18. }
  19. }
  20. module.exports = NoticeService;