2024-08-16 23:57:25 +08:00

38 lines
1.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const { readNotifyConfig, writeNotifyConfig, readNotifyList, writeNotifyList } = require('../utils')
// const commonTemp = require('../template/commonTemp')
async function getNotifyConfig({ res }) {
const data = await readNotifyConfig()
return res.success({ data })
}
// 根据type待编写测试方法测试通过才保存到库
async function updateNotifyConfig({ res, request }) {
let { body: { noticeConfig } } = request
await writeNotifyConfig(noticeConfig)
return res.success()
}
async function getNotifyList({ res }) {
const data = await readNotifyList()
res.success({ data })
}
async function updateNotifyList({ res, request }) {
let { body: { type, sw } } = request
if (!([true, false].includes(sw))) return res.fail({ msg: `Error type for sw${ sw }, must be Boolean` })
const notifyList = await readNotifyList()
let target = notifyList.find((item) => item.type === type)
if (!target) return res.fail({ msg: `更新失败, 不存在该通知类型:${ type }` })
target.sw = sw
await writeNotifyList(notifyList)
res.success()
}
module.exports = {
getNotifyConfig,
updateNotifyConfig,
getNotifyList,
updateNotifyList
}