diff --git a/back/api/system.ts b/back/api/system.ts index 8de86351..e4fb65e9 100644 --- a/back/api/system.ts +++ b/back/api/system.ts @@ -111,4 +111,25 @@ export default (app: Router) => { } }, ); + + route.put( + '/notify', + celebrate({ + body: Joi.object({ + title: Joi.string().required(), + content: Joi.string().required(), + }), + }), + async (req: Request, res: Response, next: NextFunction) => { + const logger: Logger = Container.get('logger'); + try { + const systemService = Container.get(SystemService); + const result = await systemService.notify(req.body); + res.send(result); + } catch (e) { + logger.error('🔥 error: %o', e); + return next(e); + } + }, + ); }; diff --git a/back/services/system.ts b/back/services/system.ts index d791184b..ca8e5106 100644 --- a/back/services/system.ts +++ b/back/services/system.ts @@ -163,4 +163,13 @@ export default class SystemService { return { code: 200 }; } + + public async notify({ title, content }: { title: string; content: string }) { + const isSuccess = await this.notificationService.notify(title, content); + if (isSuccess) { + return { code: 200, data: '通知发送成功' }; + } else { + return { code: 400, data: '通知发送失败,请检查参数' }; + } + } }