template.js 610 B

123456789101112131415161718192021
  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. const { ObjectId } = require('mongoose').Types;
  7. // 模板
  8. class TemplateService extends CrudService {
  9. constructor(ctx) {
  10. super(ctx, 'template');
  11. this.model = this.ctx.model.Template;
  12. }
  13. async toUse({ id }) {
  14. await this.model.updateMany({}, { is_use: false });
  15. await this.model.updateOne({ _id: ObjectId(id) }, { is_use: true });
  16. }
  17. }
  18. module.exports = TemplateService;