configuration.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. 'use strict';
  2. const Service = require('egg').Service;
  3. const assert = require('assert');
  4. const moment = require('moment');
  5. class ConfigurationService extends Service {
  6. async create({ name, describe, company, phone, address, mail, postcode, record, path, isshow, isname, isShowTitle, homeTitle, homeUrl }) {
  7. const { Configuration: model } = this.ctx.model;
  8. const createAt = moment().format('x');
  9. try {
  10. await model.create({ name, describe, company, phone, address, mail, postcode, record, createAt, path, isshow, isname, isShowTitle, homeTitle, homeUrl });
  11. return { errmsg: '', errcode: 0 };
  12. } catch (error) {
  13. throw new Error('添加失败');
  14. }
  15. }
  16. async update({ name, describe, company, phone, address, mail, postcode, record, _id, path, isshow, isname, isShowTitle, homeTitle, homeUrl }) {
  17. assert(_id, 'id不存在');
  18. const { Configuration: model } = this.ctx.model;
  19. try {
  20. await model.findById(_id).update({ name, describe, company, phone, address, mail, postcode, record, path, isshow, isname, isShowTitle, homeTitle, homeUrl });
  21. return { errmsg: '', errcode: 0 };
  22. } catch (error) {
  23. throw new Error('修改失败');
  24. }
  25. }
  26. async query() {
  27. const { Configuration: model } = this.ctx.model;
  28. try {
  29. const res = await model.find();
  30. return { errmsg: '', errcode: 0, data: res[0] };
  31. } catch (error) {
  32. throw new Error('查询失败');
  33. }
  34. }
  35. }
  36. module.exports = ConfigurationService;