From 8598ffe67bda0d2d5f04e26e3b978106f50f8dea Mon Sep 17 00:00:00 2001 From: mahyargdz Date: Tue, 22 Apr 2025 15:41:56 +0330 Subject: [PATCH] fix: bug in the content type parser of fastify --- src/app.module.ts | 10 +++++++++- src/main.ts | 12 +++++++++++- src/modules/discounts/providers/discounts.service.ts | 2 +- .../subscriptions/entities/subscription.entity.ts | 2 +- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/app.module.ts b/src/app.module.ts index 1281a70..fb209bb 100755 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -50,7 +50,15 @@ import { WalletsModule } from "./modules/wallets/wallets.module"; CacheModule.registerAsync(cacheConfig()), TypeOrmModule.forRootAsync(databaseConfigs()), HttpModule.register({ global: true, timeout: 10000, headers: { "Content-Type": "application/json" } }), - FastifyMulterModule, + FastifyMulterModule.register({ + limits: { + fileSize: 10 * 1024 * 1024, + fieldNameSize: 200, + fieldSize: 10 * 1024 * 1024, + fields: 10, + parts: 10, + }, + }), AuthModule, UsersModule, TicketsModule, diff --git a/src/main.ts b/src/main.ts index 2918867..c9daba0 100755 --- a/src/main.ts +++ b/src/main.ts @@ -10,7 +10,17 @@ import { PaginationInterceptor } from "./core/interceptors/pagination.intercepto import { ResponseInterceptor } from "./core/interceptors/response.interceptor"; async function bootstrap() { const logger = new Logger("APP"); - const app = await NestFactory.create(AppModule, new FastifyAdapter()); + + const fastifyAdapter = new FastifyAdapter({ + bodyLimit: 10 * 1024 * 1024, + }); + + // Add multipart content type parser + fastifyAdapter.getInstance().addContentTypeParser("multipart/form-data", (_request, _payload, done) => { + done(null); + }); + + const app = await NestFactory.create(AppModule, fastifyAdapter); app.useGlobalPipes(new ValidationPipe({ transform: true, whitelist: true })); app.useGlobalInterceptors(new ResponseInterceptor(), new PaginationInterceptor(), new ClassSerializerInterceptor(app.get(Reflector))); diff --git a/src/modules/discounts/providers/discounts.service.ts b/src/modules/discounts/providers/discounts.service.ts index 01db945..8369408 100755 --- a/src/modules/discounts/providers/discounts.service.ts +++ b/src/modules/discounts/providers/discounts.service.ts @@ -384,7 +384,7 @@ export class DiscountsService { }); for (const plan of subscriptionPlans) { - plan.directDiscount = null!; + plan.directDiscount = null; plan.price = new Decimal(plan.originalPrice); await queryRunner.manager.save(SubscriptionPlan, plan); } diff --git a/src/modules/subscriptions/entities/subscription.entity.ts b/src/modules/subscriptions/entities/subscription.entity.ts index ea3d4c1..bc2e005 100755 --- a/src/modules/subscriptions/entities/subscription.entity.ts +++ b/src/modules/subscriptions/entities/subscription.entity.ts @@ -32,7 +32,7 @@ export class SubscriptionPlan extends BaseEntity { userSubscriptions: UserSubscription[]; @ManyToOne(() => Discount, (discount) => discount.subscriptionPlans, { nullable: true, onUpdate: "CASCADE" }) - directDiscount?: Discount; + directDiscount: Discount | null; @DeleteDateColumn({ nullable: true }) deletedAt?: Date;