update: add is free to the subs plan
This commit is contained in:
@@ -13,7 +13,7 @@ export function databaseConfigs(): TypeOrmModuleAsyncOptions {
|
||||
username: configService.getOrThrow<string>("DB_USER"),
|
||||
password: configService.getOrThrow<string>("DB_PASS"),
|
||||
autoLoadEntities: true,
|
||||
synchronize: configService.getOrThrow<string>("NODE_ENV") == "production" ? false : false,
|
||||
synchronize: configService.getOrThrow<string>("NODE_ENV") == "production" ? false : true,
|
||||
logging: configService.getOrThrow<string>("NODE_ENV") == "production" ? false : true,
|
||||
migrationsTableName: "typeorm_migrations",
|
||||
migrationsRun: false,
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user