Browse Source

信鸽推送配置

release_0.0.2
巴林闲侠 2 years ago
parent
commit
11e81efaca
  1. 1
      api/app/lib/controllers/alarm/app.js
  2. 98
      api/app/lib/controllers/push/config.js
  3. 14
      api/app/lib/routes/push/index.js
  4. 1
      api/package.json

1
api/app/lib/controllers/alarm/app.js

@ -3,6 +3,7 @@
const moment = require('moment') const moment = require('moment')
async function inspection (ctx) { async function inspection (ctx) {
// 巡查
try { try {
const models = ctx.fs.dc.models; const models = ctx.fs.dc.models;
const { projectAppId, screenshot = [], } = ctx.request.body const { projectAppId, screenshot = [], } = ctx.request.body

98
api/app/lib/controllers/push/config.js

@ -1,10 +1,102 @@
'use strict'; 'use strict';
const moment = require('moment')
async function list (ctx) {
try {
const models = ctx.fs.dc.models;
const { keyword, alarmType, state, } = ctx.request.body
let findOption = {
where: {
}
}
if (keyword) {
findOption.where.$or = [
{
name: { $like: `%${keyword}%` }
},
]
}
if (alarmType) {
findOption.where.alarmType = { $contains: [alarmType] }
}
if (state) {
if (state == 'enable') {
findOption.where.disable = false
} else if (state == 'disable') {
findOption.where.disable = true
} else if (state == 'overtime') {
}
}
const listRes = await models.AlarmPushConfig.findAndCountAll(findOption)
ctx.status = 200;
ctx.body = listRes
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: error`);
ctx.status = 400;
ctx.body = {
message: typeof error == 'string' ? error : undefined
}
}
}
async function edit (ctx) { async function edit (ctx) {
try { try {
const models = ctx.fs.dc.models; const models = ctx.fs.dc.models;
const { userId } = ctx.fs.api
const { pushId, name, pepProjectId = [], alarmType = [], receiverPepUserId = [], timeType = [], disable } = ctx.request.body
let storageData = {
name, pepProjectId, alarmType, receiverPepUserId, timeType, disable
}
if (pushId) {
await models.AlarmPushConfig.update(storageData, {
where: {
id: pushId
}
})
} else {
storageData.createTime = moment().format()
storageData.createUserId = userId
await models.AlarmPushConfig.create(storageData)
}
ctx.status = 204;
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: error`);
ctx.status = 400;
ctx.body = {
message: typeof error == 'string' ? error : undefined
}
}
}
async function state (ctx) {
try {
const models = ctx.fs.dc.models;
const { pushId } = ctx.params
const { disable = undefined, del = undefined, } = ctx.request.body
if (del) {
await models.AlarmPushConfig.destroy({
where: {
id: pushId
}
})
} else {
await models.AlarmPushConfig.update({
disable,
}, {
where: {
id: pushId
}
})
}
ctx.status = 204; ctx.status = 204;
} catch (error) { } catch (error) {
@ -16,6 +108,8 @@ async function edit (ctx) {
} }
} }
module.exports = { module.exports = {
edit list, edit, state
}; };

14
api/app/lib/routes/push/index.js

@ -0,0 +1,14 @@
'use strict';
const push = require('../../controllers/push/config');
module.exports = function (app, router, opts) {
app.fs.api.logAttr['GET/push'] = { content: '获取推送配置列表', visible: true };
router.get('/push', push.list);
app.fs.api.logAttr['POST/push'] = { content: '新增/编辑推送配置', visible: true };
router.get('/push', push.edit);
app.fs.api.logAttr['PUT/push/:pushId'] = { content: '更改推送配置状态(禁用或删除)', visible: true };
router.put('/push/:pushId', push.state);
};

1
api/package.json

@ -17,6 +17,7 @@
"@fs/attachment": "^1.0.0", "@fs/attachment": "^1.0.0",
"args": "^3.0.7", "args": "^3.0.7",
"better-xlsx": "^0.7.6", "better-xlsx": "^0.7.6",
"clickhouse": "^2.6.0",
"crypto-js": "^4.0.0", "crypto-js": "^4.0.0",
"file-saver": "^2.0.2", "file-saver": "^2.0.2",
"fs-web-server-scaffold": "^2.0.2", "fs-web-server-scaffold": "^2.0.2",

Loading…
Cancel
Save