chore: complete create discount
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { BadRequestException, Injectable } from "@nestjs/common";
|
||||
import { FindOptionsWhere, IsNull } from "typeorm";
|
||||
import { FindOptionsWhere, In, IsNull } from "typeorm";
|
||||
|
||||
import { ParamDto } from "../../../common/DTO/param.dto";
|
||||
import { CategoryMessage, CommonMessage, ServiceMessage } from "../../../common/enums/message.enum";
|
||||
@@ -200,4 +200,54 @@ export class DanakServicesService {
|
||||
}
|
||||
|
||||
/******************************************** */
|
||||
|
||||
async findServicesByIds(ids: string[]) {
|
||||
const services = await this.danakServicesRepository.findBy({ id: In(ids) });
|
||||
return services;
|
||||
}
|
||||
|
||||
/******************************************** */
|
||||
|
||||
// async getDiscountedPrice(serviceId: string) {
|
||||
// const service = await this.danakServicesRepository.findOne({
|
||||
// where: {
|
||||
// id: serviceId,
|
||||
// },
|
||||
// relations: ["discount"],
|
||||
// });
|
||||
// if (!service) throw new BadRequestException(ServiceMessage.SERVICE_NOT_FOUND_BY_ID);
|
||||
|
||||
// const now = new Date();
|
||||
|
||||
// const serviceDiscount = service.discounts.filter(
|
||||
// (d) => d.type === DiscountType.DIRECT && d.isActive && d.startDate <= now && d.endDate >= now,
|
||||
// );
|
||||
|
||||
// const globalDiscounts = await this.discountRepository
|
||||
// .createQueryBuilder("discount")
|
||||
// .leftJoin("discount.services", "service")
|
||||
// .where("discount.type = :discountType", { discountType: DiscountType.DIRECT })
|
||||
// .andWhere("discount.isActive = true")
|
||||
// .andWhere("discount.startDate <= :now", { now })
|
||||
// .andWhere("discount.endDate >= :now", { now })
|
||||
// .andWhere("service.id IS NULL")
|
||||
// .getMany();
|
||||
|
||||
// const applicableDiscounts = [...serviceDiscount, ...globalDiscounts];
|
||||
// if (applicableDiscounts.length === 0) return service.;
|
||||
// let maxDiscountValue = 0;
|
||||
// for (const discount of applicableDiscounts) {
|
||||
// let discountValue = 0;
|
||||
// if (discount.calculationType === DiscountCalculationType.FIXED) {
|
||||
// discountValue = discount.amount;
|
||||
// } else if (discount.calculationType === DiscountCalculationType.PERCENTAGE) {
|
||||
// discountValue = service.price * (discount.amount / 100);
|
||||
// }
|
||||
// if (discountValue > maxDiscountValue) {
|
||||
// maxDiscountValue = discountValue;
|
||||
// }
|
||||
// }
|
||||
// const discountedPrice = service.price - maxDiscountValue;
|
||||
// return discountedPrice > 0 ? discountedPrice : 0;
|
||||
// }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user