'use strict'; const Service = require('egg').Service; const assert = require('assert'); const moment = require('moment'); class ConfigurationService extends Service { async create({ name, describe, company, phone, address, mail, postcode, record, path, isshow, isname, isShowTitle, homeTitle, homeUrl }) { const { Configuration: model } = this.ctx.model; const createAt = moment().format('x'); try { await model.create({ name, describe, company, phone, address, mail, postcode, record, createAt, path, isshow, isname, isShowTitle, homeTitle, homeUrl }); return { errmsg: '', errcode: 0 }; } catch (error) { throw new Error('添加失败'); } } async update({ name, describe, company, phone, address, mail, postcode, record, _id, path, isshow, isname, isShowTitle, homeTitle, homeUrl }) { assert(_id, 'id不存在'); const { Configuration: model } = this.ctx.model; try { await model.findById(_id).update({ name, describe, company, phone, address, mail, postcode, record, path, isshow, isname, isShowTitle, homeTitle, homeUrl }); return { errmsg: '', errcode: 0 }; } catch (error) { throw new Error('修改失败'); } } async query() { const { Configuration: model } = this.ctx.model; try { const res = await model.find(); return { errmsg: '', errcode: 0, data: res[0] }; } catch (error) { throw new Error('查询失败'); } } } module.exports = ConfigurationService;