fix: bug in the customer and tikcet for admin panel
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
// import { ApiPropertyOptional } from "@nestjs/swagger";
|
||||
// import { IsOptional, IsString } from "class-validator";
|
||||
import { ApiPropertyOptional } from "@nestjs/swagger";
|
||||
import { IsOptional, IsString } from "class-validator";
|
||||
|
||||
// import { PaginationDto } from "../../../common/DTO/pagination.dto";
|
||||
// import { FinancialMessage } from "../../../common/enums/message.enum";
|
||||
import { PaginationDto } from "../../../common/DTO/pagination.dto";
|
||||
import { FinancialMessage } from "../../../common/enums/message.enum";
|
||||
|
||||
// export class SearchCustomersDto extends PaginationDto {
|
||||
// @IsOptional()
|
||||
// @IsString({ message: FinancialMessage.SEARCH_QUERY_MUST_BE_A_STRING })
|
||||
// @ApiPropertyOptional({ description: "search query", example: "search query" })
|
||||
// q: string;
|
||||
// }
|
||||
export class SearchCustomersDto extends PaginationDto {
|
||||
@IsOptional()
|
||||
@IsString({ message: FinancialMessage.SEARCH_QUERY_MUST_BE_A_STRING })
|
||||
@ApiPropertyOptional({ description: "search query", example: "search query" })
|
||||
q?: string;
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ export class User extends BaseEntity {
|
||||
@Column({ type: "boolean", default: false })
|
||||
emailVerified: boolean;
|
||||
|
||||
@Column({ type: "enum", enum: FinancialType, nullable: true })
|
||||
@Column({ type: "enum", enum: FinancialType, nullable: true, default: null })
|
||||
financialType: FinancialType | null;
|
||||
|
||||
//-----------------------------------------
|
||||
|
||||
@@ -26,6 +26,7 @@ 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";
|
||||
import { SearchRolesQueryDto } from "../DTO/search-roles.dto";
|
||||
import { UpdateProfileDto } from "../DTO/update-profile.dto";
|
||||
import { CreateUserGroupDto } from "../DTO/user-group.dto";
|
||||
@@ -398,30 +399,30 @@ export class UsersService {
|
||||
|
||||
/************************************************************ */
|
||||
|
||||
// async findAllCustomers(queryDto: SearchCustomersDto) {
|
||||
// const { limit, skip } = PaginationUtils(queryDto);
|
||||
async getCustomers(queryDto: SearchCustomersDto) {
|
||||
const { limit, skip } = PaginationUtils(queryDto);
|
||||
|
||||
// const queryBuilder = this.userRepository
|
||||
// .createQueryBuilder("user")
|
||||
// .leftJoin("user.roles", "role")
|
||||
// .where("role.name = :roleName", { roleName: RoleEnum.USER })
|
||||
// .leftJoin("user.groups", "groups")
|
||||
// .addSelect(["groups.id", "groups.name"])
|
||||
// .loadRelationCountAndMap("user.invoicesCount", "user.invoices")
|
||||
// .loadRelationCountAndMap("user.subscriptionsCount", "user.subscriptions")
|
||||
// .loadRelationCountAndMap("user.ticketsCount", "user.tickets");
|
||||
const queryBuilder = this.userRepository
|
||||
.createQueryBuilder("user")
|
||||
.leftJoin("user.roles", "role")
|
||||
.where("role.name = :roleName", { roleName: RoleEnum.USER })
|
||||
.leftJoin("user.groups", "groups")
|
||||
.addSelect(["groups.id", "groups.name"])
|
||||
.loadRelationCountAndMap("user.invoicesCount", "user.invoices")
|
||||
.loadRelationCountAndMap("user.subscriptionsCount", "user.subscriptions")
|
||||
.loadRelationCountAndMap("user.ticketsCount", "user.tickets");
|
||||
|
||||
// if (queryDto.q) {
|
||||
// queryBuilder
|
||||
// .orWhere("user.firstName ILIKE :search", { search: `%${queryDto.q}%` })
|
||||
// .orWhere("user.lastName ILIKE :search", { search: `%${queryDto.q}%` })
|
||||
// .orWhere("user.userName ILIKE :search", { search: `%${queryDto.q}%` });
|
||||
// }
|
||||
if (queryDto.q) {
|
||||
queryBuilder
|
||||
.orWhere("user.firstName ILIKE :search", { search: `%${queryDto.q}%` })
|
||||
.orWhere("user.lastName ILIKE :search", { search: `%${queryDto.q}%` })
|
||||
.orWhere("user.userName ILIKE :search", { search: `%${queryDto.q}%` });
|
||||
}
|
||||
|
||||
// const [customers, count] = await queryBuilder.skip(skip).take(limit).getManyAndCount();
|
||||
const [customers, count] = await queryBuilder.skip(skip).take(limit).getManyAndCount();
|
||||
|
||||
// return { customers, count };
|
||||
// }
|
||||
return { customers, count };
|
||||
}
|
||||
|
||||
/************************************************************ */
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ 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";
|
||||
import { SearchRolesQueryDto } from "./DTO/search-roles.dto";
|
||||
import { UpdateProfileDto } from "./DTO/update-profile.dto";
|
||||
import { CreateUserGroupDto } from "./DTO/user-group.dto";
|
||||
@@ -117,13 +118,13 @@ export class UsersController {
|
||||
return this.usersService.findAllUsers();
|
||||
}
|
||||
|
||||
// @ApiOperation({ summary: "get all customers ==> admin route" })
|
||||
// @AuthGuards()
|
||||
// @PermissionsDec(PermissionEnum.ADMINS, PermissionEnum.CUSTOMERS)
|
||||
// @Get("customers")
|
||||
// customers(@Query() queryDto: SearchCustomersDto) {
|
||||
// return this.usersService.findAllCustomers(queryDto);
|
||||
// }
|
||||
@ApiOperation({ summary: "get all customers ==> admin route" })
|
||||
@AuthGuards()
|
||||
@PermissionsDec(PermissionEnum.ADMINS, PermissionEnum.CUSTOMERS)
|
||||
@Get("customers")
|
||||
getCustomers(@Query() queryDto: SearchCustomersDto) {
|
||||
return this.usersService.getCustomers(queryDto);
|
||||
}
|
||||
|
||||
@ApiOperation({ summary: "get all customers ==> admin route" })
|
||||
@AuthGuards()
|
||||
|
||||
Reference in New Issue
Block a user