update: add no paginate to the user get
This commit is contained in:
@@ -122,6 +122,7 @@ export const enum CommonMessage {
|
||||
SEARCH_QUERY_STRING = "رشته جستجو باید یک رشته باشد",
|
||||
UPDATED = "با موفقیت آپدیت شد",
|
||||
IS_ACTIVE_SHOULD_BE_1_0 = "وضعیت باید یکی از مقادیر ۰ و ۱ باشد",
|
||||
PAGINATE_SHOULD_BE_1_0 = "PAGINATE_SHOULD_BE_1_0",
|
||||
}
|
||||
|
||||
export const enum CategoryMessage {
|
||||
@@ -525,6 +526,8 @@ export const enum InvoiceMessage {
|
||||
DISCOUNT_MUST_BE_BETWEEN_0_AND_100 = "تخفیف باید بین ۰ تا ۱۰۰ باشد",
|
||||
TOTAL_PRICE_MUST_BE_POSITIVE = "قیمت کل باید مثبت باشد",
|
||||
DISCOUNT_NOT_FOR_THIS_USER = "این تخفیف برای شما معتبر نیست",
|
||||
DISCOUNT_IS_NOT_ACTIVE = "تخفیف فعال نیست",
|
||||
DISCOUNT_NOT_STARTED = "تخفیف هنوز شروع نشده است",
|
||||
}
|
||||
|
||||
export const enum LearningMessage {
|
||||
|
||||
@@ -693,12 +693,17 @@ export class InvoicesService {
|
||||
relations: { user: true },
|
||||
});
|
||||
|
||||
if (discount?.user?.id && discount?.user?.id !== userId) throw new BadRequestException(InvoiceMessage.DISCOUNT_NOT_FOR_THIS_USER);
|
||||
|
||||
if (!discount) throw new BadRequestException(InvoiceMessage.INVALID_DISCOUNT_CODE);
|
||||
|
||||
if (discount?.user?.id && discount?.user?.id !== userId) throw new BadRequestException(InvoiceMessage.DISCOUNT_NOT_FOR_THIS_USER);
|
||||
|
||||
if (discount?.isActive) throw new BadRequestException(InvoiceMessage.DISCOUNT_IS_NOT_ACTIVE);
|
||||
|
||||
if (discount.endDate && dayjs(discount.endDate).isBefore(dayjs())) throw new BadRequestException(InvoiceMessage.DISCOUNT_EXPIRED);
|
||||
|
||||
if (discount.startDate && dayjs(discount.startDate).isAfter(dayjs()))
|
||||
throw new BadRequestException(InvoiceMessage.DISCOUNT_NOT_STARTED);
|
||||
|
||||
if (!invoice.originalPrice) invoice.originalPrice = new Decimal(invoice.totalPrice);
|
||||
|
||||
let discountAmount: Decimal;
|
||||
|
||||
@@ -17,7 +17,7 @@ export class TicketMessage extends BaseEntity {
|
||||
@ManyToOne(() => Ticket, (ticket) => ticket.messages, { onDelete: "CASCADE", nullable: false })
|
||||
ticket: Ticket;
|
||||
|
||||
@ManyToOne(() => User, (user) => user.ticketMessage, { onDelete: "SET NULL", nullable: true })
|
||||
@ManyToOne(() => User, (user) => user.ticketMessage, { onDelete: "CASCADE", nullable: false })
|
||||
@JoinColumn()
|
||||
author: User;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,19 @@
|
||||
import { ApiPropertyOptional } from "@nestjs/swagger";
|
||||
import { IsOptional, IsString } from "class-validator";
|
||||
import { Type } from "class-transformer";
|
||||
import { IsIn, IsOptional, IsString } from "class-validator";
|
||||
|
||||
import { PaginationDto } from "../../../common/DTO/pagination.dto";
|
||||
import { FinancialMessage } from "../../../common/enums/message.enum";
|
||||
import { CommonMessage, 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;
|
||||
|
||||
@IsOptional()
|
||||
@Type(() => Number)
|
||||
@IsIn([1, 0], { message: CommonMessage.PAGINATE_SHOULD_BE_1_0 })
|
||||
@ApiPropertyOptional({ description: "paginate status", example: 1 })
|
||||
paginate?: number;
|
||||
}
|
||||
|
||||
@@ -374,9 +374,14 @@ export class CustomersService {
|
||||
/************************************************************ */
|
||||
|
||||
async getCustomers(queryDto: SearchCustomersDto) {
|
||||
const [customers, count] = await this.userRepository.getCustomer(queryDto);
|
||||
if (queryDto.paginate !== undefined && queryDto.paginate === 0) {
|
||||
const customers = await this.userRepository.getCustomersWithoutPagination(queryDto);
|
||||
return { customers };
|
||||
} else {
|
||||
const [customers, count] = await this.userRepository.getCustomer(queryDto);
|
||||
|
||||
return { customers, count };
|
||||
return { customers, count };
|
||||
}
|
||||
}
|
||||
|
||||
/************************************************************ */
|
||||
|
||||
@@ -85,6 +85,51 @@ export class UserRepository extends Repository<User> {
|
||||
|
||||
//************* */
|
||||
|
||||
async getCustomersWithoutPagination(queryDto: SearchCustomersDto) {
|
||||
const queryBuilder = this.createQueryBuilder("user")
|
||||
.leftJoin("user.roles", "role")
|
||||
.where("role.name = :roleName", { roleName: RoleEnum.USER })
|
||||
.leftJoin("user.legalUser", "legalUser")
|
||||
.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")
|
||||
.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.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}%` });
|
||||
}
|
||||
|
||||
return queryBuilder.getMany();
|
||||
}
|
||||
|
||||
//========
|
||||
|
||||
async getCustomer(queryDto: SearchCustomersDto) {
|
||||
const { limit, skip } = PaginationUtils(queryDto);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user