chore: add ticket module and tickets entity
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import { BadRequestException, Injectable, Logger } from "@nestjs/common";
|
||||
import slugify from "slugify";
|
||||
import { Not } from "typeorm";
|
||||
|
||||
import { RoleRepository } from "./roles.repository";
|
||||
import { UserRepository } from "./users.repository";
|
||||
@@ -6,8 +8,10 @@ import { roles } from "../../../../db/seeders/role.seeder";
|
||||
import { CommonMessage, UserMessage } from "../../../common/enums/message.enum";
|
||||
import { CompleteRegistrationDto } from "../../auth/DTO/complete-register.dto";
|
||||
import { CheckValidityDTO } from "../DTO/check-validity.dto";
|
||||
import { UpdateProfileDto } from "../DTO/update-profile.dto";
|
||||
import { User } from "../entities/user.entity";
|
||||
import { RoleEnum } from "../enums/role.enum";
|
||||
import { ValidityType } from "../enums/validity-type.enum";
|
||||
|
||||
@Injectable()
|
||||
export class UsersService {
|
||||
@@ -38,6 +42,31 @@ export class UsersService {
|
||||
if (!user) throw new BadRequestException(UserMessage.USER_NOT_FOUND);
|
||||
return { user };
|
||||
}
|
||||
|
||||
/************************************************************ */
|
||||
|
||||
async updateProfile(userId: string, updateProfileDto: UpdateProfileDto) {
|
||||
const { firstName, lastName, birthDate } = updateProfileDto;
|
||||
|
||||
if (updateProfileDto.userName) {
|
||||
updateProfileDto.userName = slugify(updateProfileDto.userName, { lower: true, trim: true });
|
||||
const existUserName = await this.userRepository.findOneBy({ userName: updateProfileDto.userName, id: Not(userId) });
|
||||
if (existUserName) throw new BadRequestException(UserMessage.USERNAME_EXIST);
|
||||
}
|
||||
const user = await this.userRepository.findOneBy({ id: userId });
|
||||
if (!user) throw new BadRequestException(UserMessage.USER_NOT_FOUND);
|
||||
|
||||
const { userName } = updateProfileDto;
|
||||
if (userName) user.userName = userName;
|
||||
if (firstName) user.firstName = firstName;
|
||||
if (lastName) user.lastName = lastName;
|
||||
if (birthDate) user.birthDate = birthDate;
|
||||
|
||||
await this.userRepository.save(user);
|
||||
return {
|
||||
message: CommonMessage.UPDATE_SUCCESS,
|
||||
};
|
||||
}
|
||||
/************************************************************ */
|
||||
|
||||
async findOneWithEmail(email: string): Promise<User | null> {
|
||||
@@ -65,10 +94,13 @@ export class UsersService {
|
||||
}
|
||||
/************************************************************ */
|
||||
|
||||
async checkValidity(checkDto: CheckValidityDTO) {
|
||||
const { type, value } = checkDto;
|
||||
const user = await this.userRepository.findOneBy({ [type]: value });
|
||||
async checkValidity(checkDto: CheckValidityDTO, userId: string) {
|
||||
const { type } = checkDto;
|
||||
if (type === ValidityType.USERNAME) checkDto.value = slugify(checkDto.value, { lower: true, trim: true });
|
||||
|
||||
const user = await this.userRepository.findOneBy({ [type]: checkDto.value, id: Not(userId) });
|
||||
if (user) throw new BadRequestException(UserMessage.USER_EXISTS);
|
||||
|
||||
return { message: CommonMessage.VALID_FOR_CHOOSE };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user