diff --git a/src/configs/typeorm.config.ts b/src/configs/typeorm.config.ts index 9391ab2..8d8378f 100755 --- a/src/configs/typeorm.config.ts +++ b/src/configs/typeorm.config.ts @@ -13,7 +13,7 @@ export function databaseConfigs(): TypeOrmModuleAsyncOptions { username: configService.getOrThrow("DB_USER"), password: configService.getOrThrow("DB_PASS"), autoLoadEntities: true, - synchronize: configService.getOrThrow("NODE_ENV") == "production" ? false : false, + synchronize: configService.getOrThrow("NODE_ENV") == "production" ? false : true, logging: configService.getOrThrow("NODE_ENV") == "production" ? false : true, migrationsTableName: "typeorm_migrations", migrationsRun: false, diff --git a/src/modules/subscriptions/DTO/create-subscription.dto.ts b/src/modules/subscriptions/DTO/create-subscription.dto.ts index 46b2414..d487aab 100755 --- a/src/modules/subscriptions/DTO/create-subscription.dto.ts +++ b/src/modules/subscriptions/DTO/create-subscription.dto.ts @@ -1,6 +1,6 @@ import { ApiProperty } from "@nestjs/swagger"; import { Type } from "class-transformer"; -import { ArrayMinSize, IsArray, IsBoolean, IsInt, IsNotEmpty, IsString, IsUUID, Length, Min, ValidateNested } from "class-validator"; +import { ArrayMinSize, IsArray, IsBoolean, IsInt, IsNotEmpty, IsString, IsUUID, Length, ValidateNested } from "class-validator"; import { SubscriptionMessage } from "../../../common/enums/message.enum"; @@ -18,7 +18,7 @@ export class SubscriptionPlanDto { @IsNotEmpty({ message: SubscriptionMessage.PRICE_REQUIRED }) @IsInt({ message: SubscriptionMessage.PRICE_SHOULD_BE_INT }) - @Min(100_000, { message: SubscriptionMessage.PRICE_SHOULD_BE_GREATER_THAN_100_000 }) + // @Min(100_000, { message: SubscriptionMessage.PRICE_SHOULD_BE_GREATER_THAN_100_000 }) @ApiProperty({ description: "the price of the subscription plan", example: 10_000_000 }) price: number; diff --git a/src/modules/subscriptions/entities/subscription.entity.ts b/src/modules/subscriptions/entities/subscription.entity.ts index bc2e005..3b4d956 100755 --- a/src/modules/subscriptions/entities/subscription.entity.ts +++ b/src/modules/subscriptions/entities/subscription.entity.ts @@ -16,6 +16,9 @@ export class SubscriptionPlan extends BaseEntity { @Column({ type: "int", nullable: false }) duration: number; + @Column({ type: "boolean", default: false }) + isFree: boolean; + @Column({ type: "decimal", precision: 16, scale: 2, nullable: false, transformer: new DecimalTransformer() }) price: Decimal; diff --git a/src/modules/subscriptions/providers/subscriptions.service.ts b/src/modules/subscriptions/providers/subscriptions.service.ts index 6ebc9f8..81c5cd2 100755 --- a/src/modules/subscriptions/providers/subscriptions.service.ts +++ b/src/modules/subscriptions/providers/subscriptions.service.ts @@ -48,7 +48,9 @@ export class SubscriptionsService { const subscriptions = createDto.subs.map((sub) => ({ ...sub, service: { id: createDto.serviceId }, - originalPrice: new Decimal(sub.price), + price: sub.price < 100_000 ? new Decimal(0) : new Decimal(sub.price), + originalPrice: sub.price < 100_000 ? new Decimal(0) : new Decimal(sub.price), + isFree: sub.price < 100_000, })); const subscriptionNames = createDto.subs.map((sub) => sub.name); @@ -134,11 +136,14 @@ export class SubscriptionsService { if (updateDto.duration) subscription.duration = updateDto.duration; if (updateDto.price) { - subscription.price = new Decimal(updateDto.price); - subscription.originalPrice = new Decimal(updateDto.price); + subscription.price = updateDto.price < 100_000 ? new Decimal(0) : new Decimal(updateDto.price); + subscription.originalPrice = updateDto.price < 100_000 ? new Decimal(0) : new Decimal(updateDto.price); } - await this.subscriptionsPlanRepository.save(subscription); + await this.subscriptionsPlanRepository.save({ + ...subscription, + isFree: updateDto.price ? updateDto.price < 100_000 : false, + }); return { message: SubscriptionMessage.UPDATED,