update: add review count and also verification from admin panel
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
// eslint-disable-next-line import/no-named-as-default
|
||||
import Decimal from "decimal.js";
|
||||
import { Column, Entity, Index, ManyToMany, ManyToOne } from "typeorm";
|
||||
import { Column, Entity, Index, ManyToOne } from "typeorm";
|
||||
|
||||
import { BaseEntity } from "../../../common/entities/base.entity";
|
||||
import { DecimalTransformer } from "../../../common/transformers/decimal.transformer";
|
||||
import { DanakService } from "../../danak-services/entities/danak-service.entity";
|
||||
import { Discount } from "../../discounts/entities/discount.entity";
|
||||
// import { Discount } from "../../discounts/entities/discount.entity";
|
||||
|
||||
@Entity()
|
||||
@Index(["service", "name"], { unique: true })
|
||||
@@ -25,6 +25,6 @@ export class SubscriptionPlan extends BaseEntity {
|
||||
@ManyToOne(() => DanakService, (danakService) => danakService.subscriptionPlans, { nullable: false, onDelete: "CASCADE" })
|
||||
service: DanakService;
|
||||
|
||||
@ManyToMany(() => Discount, (discount) => discount.subscriptionPlans)
|
||||
discounts: Discount[];
|
||||
// @ManyToMany(() => Discount, (discount) => discount.subscriptionPlans)
|
||||
// discounts: Discount[];
|
||||
}
|
||||
|
||||
@@ -1,17 +1,12 @@
|
||||
import { BadRequestException, Injectable } from "@nestjs/common";
|
||||
import dayjs from "dayjs";
|
||||
// eslint-disable-next-line import/no-named-as-default
|
||||
import Decimal from "decimal.js";
|
||||
import { DataSource, In } from "typeorm";
|
||||
|
||||
import { ServiceMessage, SubscriptionMessage } from "../../../common/enums/message.enum";
|
||||
import { DanakServicesService } from "../../danak-services/providers/danak-services.service";
|
||||
import { DiscountCalculationType } from "../../discounts/enums/discount-type.enum";
|
||||
import { InvoicesService } from "../../invoices/providers/invoices.service";
|
||||
import { UsersService } from "../../users/providers/users.service";
|
||||
import { PaginationUtils } from "../../utils/providers/pagination.utils";
|
||||
// import { Wallet } from "../../wallets/entities/wallet.entity";
|
||||
// import { WalletsService } from "../../wallets/providers/wallets.service";
|
||||
import { AddSubscriptionsToServiceDto } from "../DTO/create-subscription.dto";
|
||||
import { SearchUserSubsQueryDto } from "../DTO/search-user-subs-query.dto";
|
||||
import { ServiceSubsQueryDto } from "../DTO/service-subs-query.dto";
|
||||
@@ -30,7 +25,6 @@ export class SubscriptionsService {
|
||||
private readonly userSubscriptionsRepository: UserSubscriptionsRepository,
|
||||
private readonly invoicesService: InvoicesService,
|
||||
private readonly usersService: UsersService,
|
||||
// private readonly walletsService: WalletsService,
|
||||
private readonly danakServices: DanakServicesService,
|
||||
private readonly dataSource: DataSource,
|
||||
) {}
|
||||
@@ -162,31 +156,9 @@ export class SubscriptionsService {
|
||||
|
||||
const [subscriptions, count] = await queryBuilder.skip(skip).take(limit).getManyAndCount();
|
||||
|
||||
const transformedSubscriptions = subscriptions.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(),
|
||||
};
|
||||
});
|
||||
|
||||
return {
|
||||
service,
|
||||
subscriptions: transformedSubscriptions,
|
||||
subscriptions,
|
||||
count,
|
||||
pagination: true,
|
||||
};
|
||||
@@ -219,7 +191,6 @@ export class SubscriptionsService {
|
||||
where: { id: subscribeDto.planId, service: { id: serviceId } },
|
||||
relations: {
|
||||
service: true,
|
||||
discounts: true,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -237,7 +208,7 @@ export class SubscriptionsService {
|
||||
//TODO: need queue handling for notification
|
||||
const invoiceDueDate = dayjs(userSubscription.startDate).add(5, "day").toDate();
|
||||
|
||||
const invoice = await this.invoicesService.createInvoiceForSubscription(userId, plan, userSubscription, invoiceDueDate, queryRunner);
|
||||
const invoice = await this.invoicesService.createInvoiceForSubscription(user, plan, userSubscription, invoiceDueDate, queryRunner);
|
||||
userSubscription.status = SubscriptionStatus.INACTIVE;
|
||||
|
||||
await queryRunner.manager.save(UserSubscription, userSubscription);
|
||||
|
||||
Reference in New Issue
Block a user