From a801b59610e06f83d1d17866522c22e1a645351e Mon Sep 17 00:00:00 2001 From: Nevo David Date: Tue, 7 Jan 2025 17:01:58 +0700 Subject: [PATCH] feat: return post list + delete post for public api --- .../v1/public.integrations.controller.ts | 18 ++++++++++-------- .../src/database/prisma/posts/posts.service.ts | 8 ++++++++ 2 files changed, 18 insertions(+), 8 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 74185e59..05dd16cc 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 @@ -1,12 +1,5 @@ import { - Body, - Controller, - Get, - HttpException, - Post, - Query, - UploadedFile, - UseInterceptors, + Body, Controller, Delete, Get, HttpException, Param, Post, Query, UploadedFile, UseInterceptors } from '@nestjs/common'; import { ApiTags } from '@nestjs/swagger'; import { GetOrgFromRequest } from '@gitroom/nestjs-libraries/user/org.from.request'; @@ -76,6 +69,15 @@ export class PublicIntegrationsController { return this._postsService.createPost(org.id, body); } + @Delete('/posts/:id') + async deletePost( + @GetOrgFromRequest() org: Organization, + @Param() body: { id: string } + ) { + const getPostById = await this._postsService.getPost(org.id, body.id); + return this._postsService.deletePost(org.id, getPostById.group); + } + @Get('/integrations') async listIntegration(@GetOrgFromRequest() org: Organization) { return (await this._integrationService.getIntegrationsList(org.id)).map( 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 d6d2155e..38a1cf68 100644 --- a/libraries/nestjs-libraries/src/database/prisma/posts/posts.service.ts +++ b/libraries/nestjs-libraries/src/database/prisma/posts/posts.service.ts @@ -549,6 +549,7 @@ export class PostsService { } async createPost(orgId: string, body: CreatePostDto) { + const postList = []; for (const post of body.posts) { const { previousPost, posts } = await this._postRepository.createOrUpdatePost( @@ -596,7 +597,14 @@ export class PostsService { }, }); } + + postList.push({ + postId: posts[0].id, + integration: post.integration.id, + }) } + + return postList; } async changeDate(orgId: string, id: string, date: string) {