1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- 'use strict';
- const assert = require('assert');
- const _ = require('lodash');
- const { ObjectId } = require('mongoose').Types;
- const { CrudService } = require('naf-framework-mongoose/lib/service');
- const { BusinessError, ErrorCode } = require('naf-core').Error;
- class SettingService extends CrudService {
- constructor(ctx) {
- super(ctx, 'setting');
- this.model = this.ctx.model.Setting;
- }
- async findone() {
- return await this.model.findOne();
- }
- async update({ id }, { planyearid, planid, termid, user_email, auth_code, am_start, am_end, pm_start, pm_end, bd_start, bd_end,ques_setting }) {
- assert(id, '缺少部分信息项');
- const setting = await this.model.findById(id);
- if (!setting) {
- throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '设置信息不存在');
- }
- if (planyearid) {
- setting.planyearid = planyearid;
- }
- if (planid) {
- setting.planid = planid;
- }
- if (termid) {
- setting.termid = termid;
- }
- if (user_email) {
- setting.user_email = user_email;
- }
- if (auth_code) {
- setting.auth_code = auth_code;
- }
- if (am_start) {
- setting.am_start = am_start;
- }
- if (am_end) {
- setting.am_end = am_end;
- }
- if (pm_start) {
- setting.pm_start = pm_start;
- }
- if (pm_end) {
- setting.pm_end = pm_end;
- }
- if (bd_start) {
- setting.bd_start = bd_start;
- }
- if (bd_end) {
- setting.bd_end = bd_end;
- }
- if (ques_setting) {
- setting.ques_setting = ques_setting;
- }
- await setting.save();
- return setting;
- }
- }
- module.exports = SettingService;
|