'use strict'; function getFireAlarmList(opts) { return async function (ctx, next) { const models = ctx.fs.dc.models; let errMsg = { message: '获取消防告警失败' } try { const res = await models.FireAlarm.findAll(); ctx.status = 200; ctx.body = res; } catch (error) { ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.status = 400; ctx.body = errMsg } } } // 新增消防告警 function addAlarm(opts) { return async function (ctx, next) { const models = ctx.fs.dc.models; try { const body = ctx.request.body await models.FireAlarm.create(body) ctx.status = 204; ctx.body = { message: '新建消防告警成功' } } catch (error) { ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.status = 400; ctx.body = { message: '新建消防告警失败' } } } } // 修改消防告警 function updateAlarm(opts) { return async function (ctx, next) { try { const models = ctx.fs.dc.models; const { id } = ctx.params; const body = ctx.request.body; await models.FireAlarm.update( body, { where: { id: id, } } ) ctx.status = 204; ctx.body = { message: '修改消防告警成功' } } catch (error) { ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.status = 400; ctx.body = { message: '修改消防告警失败' } } } } module.exports = { addAlarm, updateAlarm, getFireAlarmList }