增加使用系统通知配置发送通知api

This commit is contained in:
whyour 2022-02-24 22:10:03 +08:00
parent 7ea9a8aa57
commit cb154437ac
2 changed files with 30 additions and 0 deletions

View File

@ -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);
}
},
);
};

View File

@ -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: '通知发送失败,请检查参数' };
}
}
}