chore: create customer
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
import { BadRequestException, Injectable } from "@nestjs/common";
|
||||
import Decimal from "decimal.js";
|
||||
import { FindOptionsWhere, In, IsNull } from "typeorm";
|
||||
|
||||
import { ParamDto } from "../../../common/DTO/param.dto";
|
||||
import { CategoryMessage, CommonMessage, ServiceMessage } from "../../../common/enums/message.enum";
|
||||
import { DiscountCalculationType } from "../../discounts/enums/discount-type.enum";
|
||||
import { PaginationUtils } from "../../utils/providers/pagination.utils";
|
||||
import { AddReviewDto } from "../DTO/add-review.dto";
|
||||
import { CategoryListSearchQueryDto, CategorySearchQueryDto } from "../DTO/category-search-query.dto";
|
||||
@@ -179,10 +181,34 @@ export class DanakServicesService {
|
||||
async getDanakServiceByIdWithSubs(serviceId: string, isAdmin: boolean) {
|
||||
const danakService = await this.danakServicesRepository.findOne({
|
||||
where: { id: serviceId, ...(isAdmin && { isActive: true, subscriptionPlans: { isActive: true } }) },
|
||||
relations: { images: true, subscriptionPlans: true },
|
||||
relations: { images: true, subscriptionPlans: { discounts: true } },
|
||||
});
|
||||
if (!danakService) throw new BadRequestException(ServiceMessage.SERVICE_NOT_FOUND_BY_ID);
|
||||
|
||||
const transformedSubscriptions = danakService.subscriptionPlans.map((subscription) => {
|
||||
let price = new Decimal(subscription.price);
|
||||
|
||||
if (subscription.discounts && subscription.discounts.length > 0) {
|
||||
subscription.discounts.forEach((discount) => {
|
||||
if (discount.isActive && new Date() >= discount.startDate && new Date() <= discount.endDate) {
|
||||
if (discount.calculationType === DiscountCalculationType.PERCENTAGE) {
|
||||
const discountAmount = price.mul(discount.amount).div(100);
|
||||
price = price.sub(discountAmount);
|
||||
} else if (discount.calculationType === DiscountCalculationType.FIXED) {
|
||||
price = price.sub(discount.amount);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
...subscription,
|
||||
finalPrice: price.toNumber(),
|
||||
};
|
||||
});
|
||||
|
||||
danakService.subscriptionPlans = transformedSubscriptions;
|
||||
|
||||
const reviews = await this.danakServiceReviewRepository.find({
|
||||
where: { service: { id: serviceId }, status: ReviewStatus.APPROVED },
|
||||
relations: { user: true },
|
||||
|
||||
Reference in New Issue
Block a user