修复关闭通知

This commit is contained in:
hanhh 2021-09-18 02:09:06 +08:00
parent 0a9e9e972d
commit 6c87634bb3
5 changed files with 17 additions and 15 deletions

View File

@ -204,8 +204,8 @@ export default (app: Router) => {
const logger: Logger = Container.get('logger');
try {
const authService = Container.get(AuthService);
const data = await authService.updateNotificationMode(req.body);
res.send({ code: 200, data });
const result = await authService.updateNotificationMode(req.body);
res.send(result);
} catch (e) {
logger.error('🔥 error: %o', e);
return next(e);

View File

@ -272,7 +272,7 @@ export default class AuthService {
return new Promise((resolve) => {
this.authDb.update(
{ type: AuthDataType.notification },
payload,
{ ...payload },
{ upsert: true, returnUpdatedDocs: true },
(err, num, doc: any) => {
if (err) {

View File

@ -60,6 +60,7 @@ export default class NotificationService {
const notificationModeAction = this.modeMap.get(type);
return await notificationModeAction?.call(this);
}
return true;
}
private async goCqHttpBot() {

View File

@ -7,22 +7,25 @@ const { Option } = Select;
const NotificationSetting = ({ data }: any) => {
const [loading, setLoading] = useState(false);
const [notificationMode, setNotificationMode] = useState<string>('');
const [notificationMode, setNotificationMode] = useState<string>('closed');
const [fields, setFields] = useState<any[]>([]);
const [form] = Form.useForm();
const handleOk = (values: any) => {
if (values.type == 'closed') {
values.type = '';
}
request
.put(`${config.apiPrefix}user/notification`, {
data: {
...values,
},
})
.then((data: any) => {
if (data && data.code === 200) {
message.success('通知发送成功');
.then((_data: any) => {
if (_data && _data.code === 200) {
message.success(values.type ? '通知发送成功' : '通知关闭成功');
} else {
message.error(data.data);
message.error(_data.data);
}
})
.catch((error: any) => {
@ -33,7 +36,7 @@ const NotificationSetting = ({ data }: any) => {
const notificationModeChange = (value: string) => {
setNotificationMode(value);
const _fields = (config.notificationModeMap as any)[value];
setFields(_fields);
setFields(_fields || []);
};
useEffect(() => {
@ -70,11 +73,9 @@ const NotificationSetting = ({ data }: any) => {
<Input.TextArea autoSize={true} placeholder={`请输入${x.label}`} />
</Form.Item>
))}
{notificationMode !== '' && (
<Button type="primary" htmlType="submit">
</Button>
)}
<Button type="primary" htmlType="submit">
</Button>
</Form>
</div>
);

View File

@ -74,7 +74,7 @@ export default {
{ value: 'iGot', label: 'IGot' },
{ value: 'pushPlus', label: 'PushPlus' },
{ value: 'email', label: '邮箱' },
{ value: '', label: '已关闭' },
{ value: 'closed', label: '已关闭' },
],
notificationModeMap: {
goCqHttpBot: [