添加通知设置页面

This commit is contained in:
hanhh
2021-09-18 01:44:55 +08:00
parent bb0ad6c325
commit 0a9e9e972d
8 changed files with 278 additions and 6 deletions
+32 -4
View File
@@ -268,10 +268,38 @@ export default class AuthService {
});
}
public async updateNotificationMode(notificationInfo: NotificationInfo) {
return await this.insertDb({
type: AuthDataType.notification,
info: { notificationInfo },
private async updateNotificationDb(payload: AuthInfo): Promise<any> {
return new Promise((resolve) => {
this.authDb.update(
{ type: AuthDataType.notification },
payload,
{ upsert: true, returnUpdatedDocs: true },
(err, num, doc: any) => {
if (err) {
resolve({} as NotificationInfo);
} else {
resolve(doc.info);
}
},
);
});
}
public async updateNotificationMode(notificationInfo: NotificationInfo) {
const code = Math.random().toString().slice(-6);
const isSuccess = await this.notificationService.testNotify(
notificationInfo,
'青龙',
`【蛟龙】您本次的验证码:${code}`,
);
if (isSuccess) {
const result = await this.updateNotificationDb({
type: AuthDataType.notification,
info: { ...notificationInfo },
});
return { code: 200, data: { ...result, code } };
} else {
return { code: 400, data: '通知发送失败,请检查参数' };
}
}
}
+1 -1
View File
@@ -16,7 +16,7 @@ export default class CronService {
private cronDb = new DataStore({ filename: config.cronDbFile });
private queue = new PQueue({
concurrency: parseInt(process.env.MaxConcurrentNum) || 5,
concurrency: parseInt(process.env.MaxConcurrentNum as string) || 5,
});
constructor(@Inject('logger') private logger: winston.Logger) {
+20 -1
View File
@@ -39,7 +39,26 @@ export default class NotificationService {
this.content = content;
this.params = rest;
const notificationModeAction = this.modeMap.get(type);
notificationModeAction?.call(this);
try {
return await notificationModeAction?.call(this);
} catch (error: any) {
return error.message;
}
}
}
public async testNotify(
info: NotificationInfo,
title: string,
content: string,
) {
const { type, ...rest } = info;
if (type) {
this.title = title;
this.content = content;
this.params = rest;
const notificationModeAction = this.modeMap.get(type);
return await notificationModeAction?.call(this);
}
}