chore: complete the the invoice module - not tested
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { BadRequestException, Injectable } from "@nestjs/common";
|
||||
import { Brackets, FindOptionsWhere, IsNull } from "typeorm";
|
||||
import { FindOptionsWhere, IsNull } from "typeorm";
|
||||
|
||||
import { ParamDto } from "../../../common/DTO/param.dto";
|
||||
import { CategoryMessage, CommonMessage, ServiceMessage } from "../../../common/enums/message.enum";
|
||||
@@ -79,33 +79,56 @@ export class DanakServicesService {
|
||||
}
|
||||
/******************************************** */
|
||||
|
||||
// async getUserServices(userId: string) {
|
||||
// const userServices = await this.danakServicesRepository.find({
|
||||
// where: { users: { id: userId } },
|
||||
// });
|
||||
async getCategoriesUserSide() {
|
||||
const categories = await this.danakServicesCategoryRepository.find({
|
||||
where: { isActive: true },
|
||||
order: { createdAt: "DESC" },
|
||||
});
|
||||
return {
|
||||
categories,
|
||||
};
|
||||
}
|
||||
/******************************************** */
|
||||
|
||||
async getCategoryServices(categoryId: string) {
|
||||
const category = await this.danakServicesCategoryRepository.findOne({
|
||||
where: { id: categoryId },
|
||||
relations: {
|
||||
danakService: true,
|
||||
},
|
||||
order: { createdAt: "DESC" },
|
||||
});
|
||||
if (!category) throw new BadRequestException(CategoryMessage.CATEGORY_NOT_EXIST);
|
||||
return {
|
||||
category,
|
||||
};
|
||||
}
|
||||
|
||||
// return {
|
||||
// userServices,
|
||||
// };
|
||||
// }
|
||||
/******************************************** */
|
||||
|
||||
async toggleCategoryStatus(paramDto: ParamDto) {
|
||||
const category = await this.danakServicesCategoryRepository.findOneById(paramDto.id);
|
||||
if (!category) throw new BadRequestException(CategoryMessage.CATEGORY_NOT_EXIST);
|
||||
//
|
||||
category.isActive = !category.isActive;
|
||||
//
|
||||
await this.danakServicesCategoryRepository.save(category);
|
||||
//
|
||||
return {
|
||||
message: CommonMessage.UPDATE_SUCCESS,
|
||||
isActive: category.isActive,
|
||||
};
|
||||
}
|
||||
/******************************************** */
|
||||
|
||||
async toggleServiceStatus(paramDto: ParamDto) {
|
||||
const service = await this.danakServicesRepository.findServiceById(paramDto.id);
|
||||
if (!service) throw new BadRequestException(ServiceMessage.SERVICE_NOT_EXIST);
|
||||
//
|
||||
service.isActive = !service.isActive;
|
||||
//
|
||||
await this.danakServicesRepository.save(service);
|
||||
//
|
||||
return {
|
||||
message: CommonMessage.UPDATE_SUCCESS,
|
||||
isActive: service.isActive,
|
||||
@@ -133,42 +156,30 @@ export class DanakServicesService {
|
||||
/******************************************** */
|
||||
|
||||
async getServicesList(queryDto: DanakServicesSearchQueryDto) {
|
||||
const { limit, skip } = PaginationUtils(queryDto);
|
||||
return this.danakServicesRepository.getServicesForAdmin(queryDto);
|
||||
}
|
||||
|
||||
const queryBuilder = this.danakServicesRepository
|
||||
.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();
|
||||
/******************************************** */
|
||||
|
||||
async getDanakSuggestServices() {
|
||||
const danakServices = await this.danakServicesRepository.find({
|
||||
where: { isDanakSuggest: true, isActive: true },
|
||||
order: { createdAt: "DESC" },
|
||||
});
|
||||
return {
|
||||
services,
|
||||
count,
|
||||
danakServices,
|
||||
};
|
||||
}
|
||||
/******************************************** */
|
||||
|
||||
async getDanakServiceByID(serviceId: string) {
|
||||
const danakService = await this.danakServicesRepository.findOne({
|
||||
where: { id: serviceId, isActive: true },
|
||||
relations: { images: true, subscriptionPlans: true },
|
||||
});
|
||||
if (!danakService) throw new BadRequestException(ServiceMessage.SERVICE_NOT_FOUND_BY_ID);
|
||||
return {
|
||||
danakService,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user