Вшил пользователя admin. Его нельзя удалить, отредактировать. Пересоздается при каждом перезапуске приложения

This commit is contained in:
vigdorov
2020-08-08 23:01:04 +03:00
parent 221368874e
commit f0100ba084
2 changed files with 38 additions and 1 deletions

View File

@ -96,6 +96,10 @@ export class UserService {
}
async update(user: UpdateUserRequest): Promise<UserResponse> {
if (user.login === 'admin') {
throw new BadRequestException('Запрещено менять пользователя admin');
}
const searchUser = await this.userModel().findOne({login: user.login});
if (!searchUser) {
@ -127,6 +131,10 @@ export class UserService {
}
async removeOne(login: string): Promise<UserResponse> {
if (login === 'admin') {
throw new BadRequestException('Запрещено удалять пользователя admin');
}
const searchUser = await this.userModel().findOne({login});
if (!searchUser) {
@ -219,6 +227,9 @@ export class UserService {
async changePassword(access_token: string, old_password: string, new_password: string): Promise<string> {
const {login} = jwt.decode(access_token) as Token;
if (login === 'admin') {
throw new BadRequestException('Запрещено менять пароль пользователя admin');
}
const user = await this.userModel().findOne({login});
if (user && await this.checkPassword(old_password, user.password)) {
const salt = user.salt;