From 25fc8326054e7d281692da430344edfa03911ca4 Mon Sep 17 00:00:00 2001 From: whyour Date: Thu, 24 Feb 2022 22:10:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BD=BF=E7=94=A8=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E9=80=9A=E7=9F=A5=E9=85=8D=E7=BD=AE=E5=8F=91=E9=80=81?= =?UTF-8?q?=E9=80=9A=E7=9F=A5api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/api/system.ts | 21 +++++++++++++++++++++ back/services/system.ts | 9 +++++++++ 2 files changed, 30 insertions(+) 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: '通知发送失败,请检查参数' }; + } + } }