chore: create legal and real user data info
This commit is contained in:
@@ -2,8 +2,15 @@ import { BadRequestException, Injectable } from "@nestjs/common";
|
||||
import slugify from "slugify";
|
||||
import { In, Not, QueryRunner } from "typeorm";
|
||||
|
||||
// import { CreateFinancialDto } from "../DTO/create-legal-user.dto";
|
||||
import { AdminMessage, AdsMessage, CommonMessage, UserMessage } from "../../../common/enums/message.enum";
|
||||
import {
|
||||
AdminMessage,
|
||||
AdsMessage,
|
||||
CommonMessage,
|
||||
LegalUserMessage,
|
||||
RealUserMessage,
|
||||
UserMessage,
|
||||
} from "../../../common/enums/message.enum";
|
||||
import { AddressService } from "../../address/providers/address.service";
|
||||
import { CompleteRegistrationDto } from "../../auth/DTO/complete-register.dto";
|
||||
import { UserSettingsService } from "../../settings/providers/user-settings.service";
|
||||
import { PaginationUtils } from "../../utils/providers/pagination.utils";
|
||||
@@ -11,6 +18,8 @@ import { PasswordService } from "../../utils/providers/password.service";
|
||||
import { WalletsService } from "../../wallets/providers/wallets.service";
|
||||
import { CheckValidityDTO } from "../DTO/check-validity.dto";
|
||||
import { CreateAdminDto } from "../DTO/create-admin.dto";
|
||||
import { CreateLegalUserDto } from "../DTO/create-legal-user.dto";
|
||||
import { CreateRealUserDto } from "../DTO/create-real-user.dto";
|
||||
import { CreateRoleDto } from "../DTO/create-role.dto";
|
||||
import { SearchAdminQueryDto } from "../DTO/search-admins-query.dto";
|
||||
import { SearchCustomersDto } from "../DTO/search-customers.dto";
|
||||
@@ -21,7 +30,9 @@ import { Role } from "../entities/role.entity";
|
||||
import { User } from "../entities/user.entity";
|
||||
import { RoleEnum } from "../enums/role.enum";
|
||||
import { ValidityType } from "../enums/validity-type.enum";
|
||||
import { LegalUserRepository } from "../repositories/legal-user.repository";
|
||||
import { PermissionsRepository } from "../repositories/permissions.repository";
|
||||
import { RealUserRepository } from "../repositories/real-user.repository";
|
||||
import { RoleRepository } from "../repositories/roles.repository";
|
||||
import { UserGroupRepository } from "../repositories/user-group.repository";
|
||||
import { UserRepository } from "../repositories/users.repository";
|
||||
@@ -36,6 +47,9 @@ export class UsersService {
|
||||
private readonly rolesRepository: RoleRepository,
|
||||
private readonly permissionsRepository: PermissionsRepository,
|
||||
private readonly passwordService: PasswordService,
|
||||
private readonly realUserRepository: RealUserRepository,
|
||||
private readonly legalUserRepository: LegalUserRepository,
|
||||
private readonly addressService: AddressService,
|
||||
) {}
|
||||
|
||||
/************************************************************ */
|
||||
@@ -63,6 +77,22 @@ export class UsersService {
|
||||
|
||||
/************************************************************ */
|
||||
|
||||
async getMyFinancialInfo(userId: string) {
|
||||
const user = await this.userRepository
|
||||
.createQueryBuilder("user")
|
||||
.leftJoinAndSelect("user.address", "address")
|
||||
.leftJoinAndSelect("address.city", "city")
|
||||
.leftJoinAndSelect("city.province", "province")
|
||||
.leftJoinAndSelect("user.realUser", "realUser")
|
||||
.leftJoinAndSelect("user.legalUser", "legalUser")
|
||||
.where("user.id = :id", { id: userId })
|
||||
.getOne();
|
||||
if (!user) throw new BadRequestException(UserMessage.USER_NOT_FOUND);
|
||||
return { user };
|
||||
}
|
||||
|
||||
/************************************************************ */
|
||||
|
||||
async updateProfile(userId: string, updateProfileDto: UpdateProfileDto) {
|
||||
if (updateProfileDto.userName) {
|
||||
//
|
||||
@@ -347,5 +377,74 @@ export class UsersService {
|
||||
};
|
||||
}
|
||||
|
||||
async createRealUserData(createDto: CreateRealUserDto, userId: string) {
|
||||
const userExist = await this.userRepository.findOneBy({
|
||||
id: userId,
|
||||
});
|
||||
if (!userExist) throw new BadRequestException(UserMessage.USER_NOT_FOUND);
|
||||
console.log(userExist);
|
||||
const existingRealUser = await this.realUserRepository.findOne({
|
||||
where: { user: { id: userExist.id } },
|
||||
});
|
||||
console.log(existingRealUser);
|
||||
|
||||
if (existingRealUser) throw new BadRequestException(RealUserMessage.REAL_DATA_EXIST);
|
||||
|
||||
const { city } = await this.addressService.getCity(+createDto.cityId);
|
||||
|
||||
const realUser = this.realUserRepository.create({
|
||||
...createDto,
|
||||
user: userExist,
|
||||
address: {
|
||||
address: createDto.address,
|
||||
city,
|
||||
postalCode: createDto.postalCode,
|
||||
user: userExist,
|
||||
},
|
||||
});
|
||||
|
||||
await this.realUserRepository.save(realUser);
|
||||
|
||||
return {
|
||||
message: CommonMessage.CREATED,
|
||||
realUser,
|
||||
};
|
||||
}
|
||||
|
||||
// /************************************************************ */
|
||||
|
||||
async createLegalUserData(createDto: CreateLegalUserDto, userId: string) {
|
||||
const userExist = await this.userRepository.findOneBy({
|
||||
id: userId,
|
||||
});
|
||||
if (!userExist) throw new BadRequestException(UserMessage.USER_NOT_FOUND);
|
||||
|
||||
const existingLegalUser = await this.legalUserRepository.findOne({
|
||||
where: { user: { id: userExist.id } },
|
||||
});
|
||||
|
||||
if (existingLegalUser) throw new BadRequestException(LegalUserMessage.LEGAL_DATA_EXIST);
|
||||
|
||||
const { city } = await this.addressService.getCity(+createDto.cityId);
|
||||
|
||||
const legalUser = this.legalUserRepository.create({
|
||||
...createDto,
|
||||
user: userExist,
|
||||
address: {
|
||||
address: createDto.address,
|
||||
city,
|
||||
postalCode: createDto.postalCode,
|
||||
user: userExist,
|
||||
},
|
||||
});
|
||||
|
||||
await this.legalUserRepository.save(legalUser);
|
||||
|
||||
return {
|
||||
message: CommonMessage.CREATED,
|
||||
legalUser,
|
||||
};
|
||||
}
|
||||
|
||||
/************************************************************ */
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user