update: fix
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user