From 3519889bc14d262cf9d3754b2660ce79168c5352 Mon Sep 17 00:00:00 2001 From: Nevo David Date: Thu, 10 Jul 2025 13:36:16 +0700 Subject: [PATCH] feat: force fields check in public api --- .../public-api/routes/v1/public.integrations.controller.ts | 3 ++- .../src/database/prisma/posts/posts.service.ts | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/apps/backend/src/public-api/routes/v1/public.integrations.controller.ts b/apps/backend/src/public-api/routes/v1/public.integrations.controller.ts index 60c6befe..bb584300 100644 --- a/apps/backend/src/public-api/routes/v1/public.integrations.controller.ts +++ b/apps/backend/src/public-api/routes/v1/public.integrations.controller.ts @@ -69,7 +69,8 @@ export class PublicIntegrationsController { @GetOrgFromRequest() org: Organization, @Body() rawBody: any ) { - const body = await this._postsService.mapTypeToPost(rawBody, org.id); + const body = await this._postsService.mapTypeToPost(rawBody, org.id, rawBody.type === 'draft'); + body.type = rawBody.type; console.log(JSON.stringify(body, null, 2)); return this._postsService.createPost(org.id, body); diff --git a/libraries/nestjs-libraries/src/database/prisma/posts/posts.service.ts b/libraries/nestjs-libraries/src/database/prisma/posts/posts.service.ts index 3bdc60d3..1889280e 100644 --- a/libraries/nestjs-libraries/src/database/prisma/posts/posts.service.ts +++ b/libraries/nestjs-libraries/src/database/prisma/posts/posts.service.ts @@ -74,7 +74,8 @@ export class PostsService { async mapTypeToPost( body: CreatePostDto, - organization: string + organization: string, + replaceDraft: boolean = false ): Promise { if (!body?.posts?.every((p) => p?.integration?.id)) { throw new BadRequestException('All posts must have an integration id'); @@ -82,6 +83,7 @@ export class PostsService { const mappedValues = { ...body, + type: replaceDraft ? 'schedule': body.type, posts: await Promise.all( body.posts.map(async (post) => { const integration = await this._integrationService.getIntegrationById(