Skip to content

πŸ“¨ The ultimate agentic social media scheduling tool πŸ€–

feat: change post status

Nevo David288a4d428be9
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 40ec9ff45..2c9bf9349 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
@@ -23,6 +23,7 @@ import { FileInterceptor } from '@nestjs/platform-express';
import { UploadFactory } from '@gitroom/nestjs-libraries/upload/upload.factory';
import { MediaService } from '@gitroom/nestjs-libraries/database/prisma/media/media.service';
import { GetPostsDto } from '@gitroom/nestjs-libraries/dtos/posts/get.posts.dto';
+import { ChangePostStatusDto } from '@gitroom/nestjs-libraries/dtos/posts/change.post.status.dto';
import {
AuthorizationActions,
Sections,
@@ -358,6 +359,16 @@ export class PublicIntegrationsController {
return this._postsService.getMissingContent(org.id, id);
}
+ @Put('/posts/:id/status')
+ async changePostStatus(
+ @GetOrgFromRequest() org: Organization,
+ @Param('id') id: string,
+ @Body() body: ChangePostStatusDto
+ ) {
+ Sentry.metrics.count('public_api-request', 1);
+ return this._postsService.changePostStatus(org.id, id, body.status);
+ }
+
@Put('/posts/:id/release-id')
async updateReleaseId(
@GetOrgFromRequest() org: Organization,
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 e89ced6a4..6d05be203 100644
--- a/libraries/nestjs-libraries/src/database/prisma/posts/posts.service.ts
+++ b/libraries/nestjs-libraries/src/database/prisma/posts/posts.service.ts
@@ -784,6 +784,31 @@ export class PostsService {
return this._postRepository.changeState(id, state, err, body);
}
+ async changePostStatus(
+ orgId: string,
+ id: string,
+ status: 'draft' | 'schedule'
+ ) {
+ const getPostById = await this._postRepository.getPostById(id, orgId);
+ if (!getPostById) {
+ throw new BadRequestException('Post not found');
+ }
+
+ const state: State = status === 'draft' ? 'DRAFT' : 'QUEUE';
+ await this._postRepository.changeState(id, state);
+
+ try {
+ await this.startWorkflow(
+ getPostById.integration.providerIdentifier.split('-')[0].toLowerCase(),
+ getPostById.id,
+ orgId,
+ state
+ );
+ } catch (err) {}
+
+ return { id, state };
+ }
+
async changeDate(
orgId: string,
id: string,
diff --git a/libraries/nestjs-libraries/src/dtos/posts/change.post.status.dto.ts b/libraries/nestjs-libraries/src/dtos/posts/change.post.status.dto.ts
new file mode 100644
index 000000000..466502bfc
--- /dev/null
+++ b/libraries/nestjs-libraries/src/dtos/posts/change.post.status.dto.ts
@@ -0,0 +1,6 @@
+import { IsIn } from 'class-validator';
+
+export class ChangePostStatusDto {
+ @IsIn(['draft', 'schedule'])
+ status: 'draft' | 'schedule';
+}