0
0
Fork 0
This commit is contained in:
Xeltica 2021-09-14 04:11:43 +09:00
parent 587136a82d
commit 7eeb90eddc
13 changed files with 392 additions and 54 deletions

View file

@ -3,12 +3,12 @@
* @author Xeltica
*/
import { IsEnum } from 'class-validator';
import { Body, CurrentUser, Get, HttpCode, JsonController, OnUndefined, Post, Put } from 'routing-controllers';
import { Body, CurrentUser, Get, JsonController, OnUndefined, Post, Put } from 'routing-controllers';
import { DeepPartial } from 'typeorm';
import { getScores } from '../functions/get-scores';
import { updateUser } from '../functions/users';
import { User } from '../models/entities/user';
import { sendAlert } from '../services/send-alert';
import { UserSetting } from './UserSetting';
@JsonController('/session')
@ -25,14 +25,19 @@ export class SessionController {
@OnUndefined(204)
@Put() async updateSetting(@CurrentUser({ required: true }) user: User, @Body() setting: UserSetting) {
const s: DeepPartial<User> = {};
if (setting.alertMode) s.alertMode = setting.alertMode;
if (setting.visibility) s.visibility = setting.visibility;
if (setting.localOnly) s.localOnly = setting.localOnly;
if (setting.remoteFollowersOnly) s.remoteFollowersOnly = setting.remoteFollowersOnly;
if (setting.template) s.template = setting.template;
if (setting.alertMode != null) s.alertMode = setting.alertMode;
if (setting.visibility != null) s.visibility = setting.visibility;
if (setting.localOnly != null) s.localOnly = setting.localOnly;
if (setting.remoteFollowersOnly != null) s.remoteFollowersOnly = setting.remoteFollowersOnly;
if (setting.template != null) s.template = setting.template;
if (Object.keys(s).length === 0) return;
await updateUser(user.username, user.host, s);
}
@OnUndefined(204)
@Post('/alert') async testAlert(@CurrentUser({ required: true }) user: User) {
await sendAlert(user);
}
}