chore: complete ticket service but not tested
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import { ApiPropertyOptional } from "@nestjs/swagger";
|
||||
import { IsEnum, IsOptional, IsString } from "class-validator";
|
||||
|
||||
import { PaginationDto } from "../../../common/DTO/pagination.dto";
|
||||
import { CategoryMessage } from "../../../common/enums/message.enum";
|
||||
import { ServiceStatus } from "../enums/service-status.enum";
|
||||
|
||||
export class DanakServicesSearchQueryDto extends PaginationDto {
|
||||
@IsOptional()
|
||||
@IsString({ message: CategoryMessage.CAT_ID_SHOULD_BE_UUID })
|
||||
@ApiPropertyOptional({ description: "Category id", example: "8b1e8b1e-8b1e-8b1e-8b1e-8b1e8b1e8b1e" })
|
||||
categoryId?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsEnum(ServiceStatus)
|
||||
@ApiPropertyOptional({ description: "services status", enum: ServiceStatus, example: ServiceStatus.ACTIVE })
|
||||
status?: ServiceStatus;
|
||||
|
||||
@IsOptional()
|
||||
@IsString({ message: CategoryMessage.SEARCH_QUERY_STRING })
|
||||
@ApiPropertyOptional({ description: "Search query", example: "search query" })
|
||||
q?: string;
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import { ApiOperation, ApiTags } from "@nestjs/swagger";
|
||||
import { CategoryListSearchQueryDto, CategorySearchQueryDto } from "./DTO/category-search-query.dto";
|
||||
import { CreateCategoryDto } from "./DTO/create-category.dto";
|
||||
import { CreateServiceDto } from "./DTO/create-service.dto";
|
||||
import { DanakServicesSearchQueryDto } from "./DTO/danak-services-search-query.dto";
|
||||
import { DanakServicesService } from "./providers/danak-services.service";
|
||||
import { AuthGuards } from "../../common/decorators/auth-guard.decorator";
|
||||
import { Pagination } from "../../common/decorators/pagination.decorator";
|
||||
@@ -61,6 +62,14 @@ export class DanakServicesController {
|
||||
return this.danakServicesService.createService(createDto);
|
||||
}
|
||||
|
||||
@AuthGuards()
|
||||
@ApiOperation({ summary: "get all danak services ==> admin route" })
|
||||
@Roles(RoleEnum.ADMIN)
|
||||
@Get("list")
|
||||
getServices(@Query() queryDto: DanakServicesSearchQueryDto) {
|
||||
return this.danakServicesService.getServicesList(queryDto);
|
||||
}
|
||||
|
||||
@AuthGuards()
|
||||
@Roles(RoleEnum.USER)
|
||||
@ApiOperation({ summary: "get all user purchased danak services" })
|
||||
|
||||
@@ -53,7 +53,7 @@ export class DanakService extends BaseEntity {
|
||||
})
|
||||
category: DanakServiceCategory;
|
||||
|
||||
@OneToMany(() => DanakServiceImage, (danakServiceImage) => danakServiceImage.danakService, { eager: true, cascade: true })
|
||||
@OneToMany(() => DanakServiceImage, (danakServiceImage) => danakServiceImage.danakService, { cascade: true })
|
||||
images: DanakServiceImage[];
|
||||
|
||||
@OneToMany(() => Announcement, (announcement) => announcement.service)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { BadRequestException, Injectable } from "@nestjs/common";
|
||||
import { FindOptionsWhere, IsNull } from "typeorm";
|
||||
import { Brackets, FindOptionsWhere, IsNull } from "typeorm";
|
||||
|
||||
import { ParamDto } from "../../../common/DTO/param.dto";
|
||||
import { CategoryMessage, CommonMessage, ServiceMessage } from "../../../common/enums/message.enum";
|
||||
@@ -7,6 +7,7 @@ import { PaginationUtils } from "../../utils/providers/pagination.utils";
|
||||
import { CategoryListSearchQueryDto, CategorySearchQueryDto } from "../DTO/category-search-query.dto";
|
||||
import { CreateCategoryDto } from "../DTO/create-category.dto";
|
||||
import { CreateServiceDto } from "../DTO/create-service.dto";
|
||||
import { DanakServicesSearchQueryDto } from "../DTO/danak-services-search-query.dto";
|
||||
import { DanakServiceCategory } from "../entities/danak-service-category.entity";
|
||||
import { DanakServicesCategoryRepository } from "../repositories/danak-services-category.repository";
|
||||
import { DanakServicesRepository } from "../repositories/danak-services.repository";
|
||||
@@ -120,6 +121,43 @@ export class DanakServicesService {
|
||||
}
|
||||
/******************************************** */
|
||||
|
||||
async getServicesList(queryDto: DanakServicesSearchQueryDto) {
|
||||
const { limit, skip } = PaginationUtils(queryDto);
|
||||
|
||||
const queryBuilder = this.danakServicesRepository
|
||||
.createQueryBuilder("service")
|
||||
.leftJoinAndSelect("service.category", "category")
|
||||
.orderBy("service.createdAt", "DESC")
|
||||
.skip(skip)
|
||||
.take(limit);
|
||||
|
||||
if (queryDto.status) {
|
||||
queryBuilder.andWhere("service.status = :status", { status: queryDto.status });
|
||||
}
|
||||
if (queryDto.categoryId) {
|
||||
queryBuilder.andWhere("service.categoryId = :categoryId", { categoryId: queryDto.categoryId });
|
||||
}
|
||||
|
||||
if (queryDto.q) {
|
||||
queryBuilder.andWhere(
|
||||
new Brackets((qb) => {
|
||||
qb.where("service.name LIKE :q", { q: `%${queryDto.q}%` })
|
||||
.orWhere("service.description LIKE :q", { q: `%${queryDto.q}%` })
|
||||
.orWhere("service.softwareLanguage LIKE :q", { q: `%${queryDto.q}%` })
|
||||
.orWhere("service.author LIKE :q", { q: `%${queryDto.q}%` });
|
||||
}),
|
||||
);
|
||||
}
|
||||
const [services, count] = await queryBuilder.getManyAndCount();
|
||||
|
||||
return {
|
||||
services,
|
||||
count,
|
||||
};
|
||||
}
|
||||
|
||||
/******************************************** */
|
||||
|
||||
async getServiceByName(name: string) {
|
||||
const danakService = await this.danakServicesRepository.findOneByName(name);
|
||||
if (!danakService) throw new BadRequestException(ServiceMessage.SERVICE_NOT_EXIST);
|
||||
|
||||
Reference in New Issue
Block a user