政务数据资源中心(Government data Resource center) 03专项3期主要建设内容
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

63 lines
1.7 KiB

'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
}