update: change the danak services fetch to another route and accept category id "

query for that
This commit is contained in:
mahyargdz
2025-03-02 15:19:55 +03:30
parent af9f365bc7
commit 4d0344c376
9 changed files with 99 additions and 25 deletions
@@ -3,7 +3,7 @@ import { InjectRepository } from "@nestjs/typeorm";
import { Brackets, Repository } from "typeorm";
import { PaginationUtils } from "../../utils/providers/pagination.utils";
import { DanakServicesSearchQueryDto } from "../DTO/danak-services-search-query.dto";
import { DanakServicesQueryDto, DanakServicesSearchQueryDto } from "../DTO/danak-services-search-query.dto";
import { DanakService } from "../entities/danak-service.entity";
@Injectable()
@@ -19,7 +19,7 @@ export class DanakServicesRepository extends Repository<DanakService> {
async findServiceById(id: string): Promise<DanakService | null> {
return this.findOneBy({ id });
}
//+********************
async getServicesForAdmin(queryDto: DanakServicesSearchQueryDto) {
const { limit, skip } = PaginationUtils(queryDto);
@@ -54,6 +54,31 @@ export class DanakServicesRepository extends Repository<DanakService> {
}
const [services, count] = await queryBuilder.getManyAndCount();
return {
services,
count,
};
}
//+********************
async getServicesForUser(queryDto: DanakServicesQueryDto) {
const { limit, skip } = PaginationUtils(queryDto);
const queryBuilder = this.createQueryBuilder("service");
queryBuilder
.innerJoin("service.subscriptionPlans", "subscriptionPlans", "subscriptionPlans.isActive = :isActive", { isActive: true })
.leftJoinAndSelect("service.category", "category")
.where("service.isActive = :isActive", { isActive: true })
.andWhere("service.isDanakSuggest = :isDanakSuggest", { isDanakSuggest: true })
.orderBy("service.createdAt", "DESC")
.skip(skip)
.take(limit);
if (queryDto.categoryId) {
queryBuilder.andWhere("service.categoryId = :categoryId", { categoryId: queryDto.categoryId });
}
const [services, count] = await queryBuilder.getManyAndCount();
return {
services,
count,