update: change the danak services fetch to another route and accept category id "
query for that
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user