update: join the address to the real and legal user

This commit is contained in:
mahyargdz
2025-05-04 09:54:43 +03:30
parent 4da14a09cf
commit 29c8a675fb
2 changed files with 24 additions and 3 deletions
+1 -1
View File
@@ -13,7 +13,7 @@ export function databaseConfigs(): TypeOrmModuleAsyncOptions {
username: configService.getOrThrow<string>("DB_USER"), username: configService.getOrThrow<string>("DB_USER"),
password: configService.getOrThrow<string>("DB_PASS"), password: configService.getOrThrow<string>("DB_PASS"),
autoLoadEntities: true, autoLoadEntities: true,
synchronize: configService.getOrThrow<string>("NODE_ENV") == "production" ? false : true, synchronize: configService.getOrThrow<string>("NODE_ENV") == "production" ? false : false,
logging: configService.getOrThrow<string>("NODE_ENV") == "production" ? false : true, logging: configService.getOrThrow<string>("NODE_ENV") == "production" ? false : true,
migrationsTableName: "typeorm_migrations", migrationsTableName: "typeorm_migrations",
migrationsRun: false, migrationsRun: false,
@@ -92,9 +92,30 @@ export class UserRepository extends Repository<User> {
.leftJoin("user.roles", "role") .leftJoin("user.roles", "role")
.where("role.name = :roleName", { roleName: RoleEnum.USER }) .where("role.name = :roleName", { roleName: RoleEnum.USER })
.leftJoin("user.legalUser", "legalUser") .leftJoin("user.legalUser", "legalUser")
.addSelect(["legalUser.id", "legalUser.registrationName"]) .addSelect([
"legalUser.id",
"legalUser.registrationName",
"legalUser.nationalIdentity",
"legalUser.economicCode",
"legalUser.registrationCode",
])
.leftJoinAndSelect("legalUser.address", "address")
.leftJoinAndSelect("address.city", "city")
.leftJoinAndSelect("city.province", "province")
.leftJoin("user.realUser", "realUser") .leftJoin("user.realUser", "realUser")
.addSelect(["realUser.id", "realUser.firstName", "realUser.lastName"]) .addSelect([
"realUser.id",
"realUser.firstName",
"realUser.lastName",
"realUser.phone",
"realUser.gender",
"realUser.nationalCode",
"realUser.birthDate",
"realUser.nationality",
])
.leftJoinAndSelect("realUser.address", "realAddress")
.leftJoinAndSelect("realAddress.city", "realCity")
.leftJoinAndSelect("realCity.province", "realProvince")
.loadRelationCountAndMap("user.invoicesCount", "user.invoices") .loadRelationCountAndMap("user.invoicesCount", "user.invoices")
.loadRelationCountAndMap("user.subscriptionsCount", "user.subscriptions") .loadRelationCountAndMap("user.subscriptionsCount", "user.subscriptions")
.loadRelationCountAndMap("user.ticketsCount", "user.tickets"); .loadRelationCountAndMap("user.ticketsCount", "user.tickets");