chore: add new service to add subs to danak services in array

This commit is contained in:
mahyargdz
2025-02-13 13:27:21 +03:30
parent 95b9c38031
commit caa968ab4a
24 changed files with 317 additions and 98 deletions
@@ -3,6 +3,7 @@ import { FindOptionsWhere, In, IsNull } from "typeorm";
import { ParamDto } from "../../../common/DTO/param.dto";
import { CategoryMessage, CommonMessage, ServiceMessage } from "../../../common/enums/message.enum";
import { RoleEnum } from "../../users/enums/role.enum";
import { PaginationUtils } from "../../utils/providers/pagination.utils";
import { CategoryListSearchQueryDto, CategorySearchQueryDto } from "../DTO/category-search-query.dto";
import { CreateCategoryDto } from "../DTO/create-category.dto";
@@ -92,9 +93,9 @@ export class DanakServicesService {
async getCategoryServices(categoryId: string) {
const category = await this.danakServicesCategoryRepository.findOne({
where: { id: categoryId },
where: { id: categoryId, isActive: true, danakServices: { isActive: true } },
relations: {
danakService: true,
danakServices: true,
},
order: { createdAt: "DESC" },
});
@@ -172,9 +173,9 @@ export class DanakServicesService {
}
/******************************************** */
async getDanakServiceByID(serviceId: string) {
async getDanakServiceByIdWithSubs(serviceId: string, role: RoleEnum) {
const danakService = await this.danakServicesRepository.findOne({
where: { id: serviceId, isActive: true },
where: { id: serviceId, ...(role !== RoleEnum.ADMIN && { isActive: true, subscriptionPlans: { isActive: true } }) },
relations: { images: true, subscriptionPlans: true },
});
if (!danakService) throw new BadRequestException(ServiceMessage.SERVICE_NOT_FOUND_BY_ID);