chore: complete the the invoice module - not tested
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { InjectRepository } from "@nestjs/typeorm";
|
||||
import { Repository } from "typeorm";
|
||||
import { Brackets, Repository } from "typeorm";
|
||||
|
||||
import { PaginationUtils } from "../../utils/providers/pagination.utils";
|
||||
import { DanakServicesSearchQueryDto } from "../DTO/danak-services-search-query.dto";
|
||||
import { DanakService } from "../entities/danak-service.entity";
|
||||
|
||||
@Injectable()
|
||||
@@ -17,4 +19,43 @@ 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);
|
||||
|
||||
const queryBuilder = this.createQueryBuilder("service")
|
||||
.leftJoinAndSelect("service.category", "category")
|
||||
.orderBy("service.createdAt", "DESC")
|
||||
.skip(skip)
|
||||
.take(limit);
|
||||
|
||||
if (queryDto.isActive) {
|
||||
queryBuilder.andWhere("service.isActive = :isActive", { isActive: queryDto.isActive === 1 });
|
||||
}
|
||||
|
||||
if (queryDto.isDanakSuggest) {
|
||||
queryBuilder.andWhere("service.isDanakSuggest = :isDanakSuggest", { isDanakSuggest: queryDto.isDanakSuggest === 1 });
|
||||
}
|
||||
|
||||
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,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user