update: fix

This commit is contained in:
mahyargdz
2025-04-20 12:30:13 +03:30
parent 1c0ef1e1e1
commit b4dd3d2e01
6 changed files with 293 additions and 97 deletions
@@ -20,8 +20,8 @@ export class SubscriptionPlan extends BaseEntity {
@Column({ type: "decimal", precision: 16, scale: 2, nullable: false, transformer: new DecimalTransformer() })
price: Decimal;
@Column({ type: "decimal", precision: 16, scale: 2, nullable: true, transformer: new DecimalTransformer() })
originalPrice?: Decimal;
@Column({ type: "decimal", precision: 16, scale: 2, nullable: false, transformer: new DecimalTransformer() })
originalPrice: Decimal;
@Column({ type: "boolean", default: true })
isActive: boolean;
@@ -32,7 +32,7 @@ export class SubscriptionPlan extends BaseEntity {
@OneToMany(() => UserSubscription, (userSubscription) => userSubscription.plan)
userSubscriptions: UserSubscription[];
@ManyToOne(() => Discount, (discount) => discount.subscriptionPlans, { nullable: true })
@ManyToOne(() => Discount, (discount) => discount.subscriptionPlans, { nullable: true, onUpdate: "CASCADE" })
directDiscount?: Discount;
@DeleteDateColumn({ nullable: true })
@@ -37,7 +37,11 @@ export class SubscriptionsService {
const danakService = await this.danakServices.findServiceById(createDto.serviceId);
if (!danakService) throw new BadRequestException(ServiceMessage.SERVICE_NOT_FOUND_BY_ID);
const subscriptions = createDto.subs.map((sub) => ({ ...sub, service: { id: createDto.serviceId } }));
const subscriptions = createDto.subs.map((sub) => ({
...sub,
service: { id: createDto.serviceId },
originalPrice: new Decimal(sub.price),
}));
const subscriptionNames = createDto.subs.map((sub) => sub.name);
const existingSubscriptions = await this.subscriptionsPlanRepository.find({
@@ -124,7 +128,10 @@ export class SubscriptionsService {
}
if (updateDto.duration) subscription.duration = updateDto.duration;
if (updateDto.price) subscription.price = new Decimal(updateDto.price);
if (updateDto.price) {
subscription.price = new Decimal(updateDto.price);
subscription.originalPrice = new Decimal(updateDto.price);
}
await this.subscriptionsPlanRepository.save(subscription);