setting.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 SettingService extends CrudService {
  8. constructor(ctx) {
  9. super(ctx, 'setting');
  10. this.model = this.ctx.model.Setting;
  11. }
  12. async findone() {
  13. return await this.model.findOne();
  14. }
  15. async update({ id }, { planyearid, planid, termid, user_email, auth_code, am_start, am_end, pm_start, pm_end, bd_start, bd_end,ques_setting }) {
  16. assert(id, '缺少部分信息项');
  17. const setting = await this.model.findById(id);
  18. if (!setting) {
  19. throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '设置信息不存在');
  20. }
  21. if (planyearid) {
  22. setting.planyearid = planyearid;
  23. }
  24. if (planid) {
  25. setting.planid = planid;
  26. }
  27. if (termid) {
  28. setting.termid = termid;
  29. }
  30. if (user_email) {
  31. setting.user_email = user_email;
  32. }
  33. if (auth_code) {
  34. setting.auth_code = auth_code;
  35. }
  36. if (am_start) {
  37. setting.am_start = am_start;
  38. }
  39. if (am_end) {
  40. setting.am_end = am_end;
  41. }
  42. if (pm_start) {
  43. setting.pm_start = pm_start;
  44. }
  45. if (pm_end) {
  46. setting.pm_end = pm_end;
  47. }
  48. if (bd_start) {
  49. setting.bd_start = bd_start;
  50. }
  51. if (bd_end) {
  52. setting.bd_end = bd_end;
  53. }
  54. if (ques_setting) {
  55. setting.ques_setting = ques_setting;
  56. }
  57. await setting.save();
  58. return setting;
  59. }
  60. }
  61. module.exports = SettingService;