tDigitalService.js 925 B

123456789101112131415161718192021222324252627282930
  1. 'use strict';
  2. const assert = require('assert');
  3. const _ = require('lodash');
  4. const {ObjectId} = require('mongoose').Types;
  5. const {CrudService} = require('naf-framework-mongoose/lib/service');
  6. const {BusinessError, ErrorCode} = require('naf-core').Error;
  7. class TDigitalServiceService extends CrudService {
  8. constructor(ctx) {
  9. super(ctx, 't_digital_service');
  10. this.model = this.ctx.model.TDigitalService;
  11. }
  12. // 重写创建方法
  13. async create(data) {
  14. const {type, title, phone} = data;
  15. assert(type && title && phone, '缺少部分信息项');
  16. assert(/^\d{11}$/i.test(phone), 'phone无效');
  17. /*const temp = await this.model.findOne({type, title});
  18. if (temp) {
  19. throw new BusinessError(ErrorCode.DATA_EXISTED);
  20. }*/
  21. const res = await this.model.create(data);
  22. return res;
  23. }
  24. }
  25. module.exports = TDigitalServiceService;