chore: complete ticket service but not tested
This commit is contained in:
@@ -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