chore: add new service to add subs to danak services in array
This commit is contained in:
@@ -9,6 +9,7 @@ import { DanakServicesService } from "./providers/danak-services.service";
|
||||
import { AuthGuards } from "../../common/decorators/auth-guard.decorator";
|
||||
import { Pagination } from "../../common/decorators/pagination.decorator";
|
||||
import { Roles } from "../../common/decorators/roles.decorator";
|
||||
import { UserDec } from "../../common/decorators/user.decorator";
|
||||
import { ParamDto } from "../../common/DTO/param.dto";
|
||||
import { RoleEnum } from "../users/enums/role.enum";
|
||||
|
||||
@@ -44,7 +45,7 @@ export class DanakServicesController {
|
||||
}
|
||||
|
||||
@AuthGuards()
|
||||
@Roles(RoleEnum.USER)
|
||||
@Roles(RoleEnum.USER, RoleEnum.ADMIN)
|
||||
@ApiOperation({ summary: "Get all service categories user side" })
|
||||
@Get("categories/public")
|
||||
getCategoriesUserSide() {
|
||||
@@ -52,7 +53,7 @@ export class DanakServicesController {
|
||||
}
|
||||
|
||||
@AuthGuards()
|
||||
@Roles(RoleEnum.USER)
|
||||
@Roles(RoleEnum.USER, RoleEnum.ADMIN)
|
||||
@ApiOperation({ summary: "get category services with category id" })
|
||||
@Get("categories/:id/services")
|
||||
getCategoryServices(@Param() paramDto: ParamDto) {
|
||||
@@ -103,10 +104,10 @@ export class DanakServicesController {
|
||||
|
||||
@ApiOperation({ summary: "get danak service by id" })
|
||||
@AuthGuards()
|
||||
@Roles(RoleEnum.USER)
|
||||
@Roles(RoleEnum.USER, RoleEnum.ADMIN)
|
||||
@Get(":id")
|
||||
getDanakServiceById(@Param() paramDto: ParamDto) {
|
||||
return this.danakServicesService.getDanakServiceByID(paramDto.id);
|
||||
getDanakServiceById(@Param() paramDto: ParamDto, @UserDec("role") userRole: RoleEnum) {
|
||||
return this.danakServicesService.getDanakServiceByIdWithSubs(paramDto.id, userRole);
|
||||
}
|
||||
|
||||
// @AuthGuards()
|
||||
|
||||
@@ -25,5 +25,5 @@ export class DanakServiceCategory extends BaseEntity {
|
||||
parentId: string | null;
|
||||
|
||||
@OneToMany(() => DanakService, (danakService) => danakService.category)
|
||||
danakService: DanakService[];
|
||||
danakServices: DanakService[];
|
||||
}
|
||||
|
||||
@@ -14,6 +14,9 @@ export class DanakService extends BaseEntity {
|
||||
@Column({ type: "varchar", length: 100, nullable: false, unique: true })
|
||||
name: string;
|
||||
|
||||
@Column({ type: "varchar", length: 150, nullable: true })
|
||||
title: string;
|
||||
|
||||
@Column({ type: "boolean", nullable: false, default: false })
|
||||
isDanakSuggest: boolean;
|
||||
|
||||
@@ -47,7 +50,7 @@ export class DanakService extends BaseEntity {
|
||||
@Column({ type: "varchar", length: 255, nullable: false })
|
||||
icon: string;
|
||||
|
||||
@ManyToOne(() => DanakServiceCategory, (danakServiceCategory) => danakServiceCategory.danakService, {
|
||||
@ManyToOne(() => DanakServiceCategory, (danakServiceCategory) => danakServiceCategory.danakServices, {
|
||||
nullable: false,
|
||||
onDelete: "RESTRICT",
|
||||
})
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -25,6 +25,7 @@ export class DanakServicesRepository extends Repository<DanakService> {
|
||||
|
||||
const queryBuilder = this.createQueryBuilder("service")
|
||||
.leftJoinAndSelect("service.category", "category")
|
||||
.loadRelationCountAndMap("service.subscriptionCount", "service.subscriptionPlans")
|
||||
.orderBy("service.createdAt", "DESC")
|
||||
.skip(skip)
|
||||
.take(limit);
|
||||
|
||||
Reference in New Issue
Block a user