generated from fahricansecer/boilerplate-be
This commit is contained in:
@@ -0,0 +1,2 @@
|
|||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "Content" ADD COLUMN "imageUrl" TEXT;
|
||||||
@@ -1221,6 +1221,7 @@ model Content {
|
|||||||
publishedAt DateTime?
|
publishedAt DateTime?
|
||||||
scheduledAt DateTime?
|
scheduledAt DateTime?
|
||||||
publishedUrl String?
|
publishedUrl String?
|
||||||
|
imageUrl String?
|
||||||
|
|
||||||
@@index([userId])
|
@@index([userId])
|
||||||
@@index([workspaceId])
|
@@index([workspaceId])
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import type { WritingStyleConfig } from './services/writing-styles.service';
|
|||||||
import { ContentVariationsService } from './services/content-variations.service';
|
import { ContentVariationsService } from './services/content-variations.service';
|
||||||
import type { VariationConfig } from './services/content-variations.service';
|
import type { VariationConfig } from './services/content-variations.service';
|
||||||
import { PlatformAdaptersService } from './services/platform-adapters.service';
|
import { PlatformAdaptersService } from './services/platform-adapters.service';
|
||||||
import { CurrentUser } from '../../common/decorators';
|
import { CurrentUser, Public } from '../../common/decorators';
|
||||||
import { SocialPlatform, ContentStatus, MasterContentType } from '@prisma/client';
|
import { SocialPlatform, ContentStatus, MasterContentType } from '@prisma/client';
|
||||||
|
|
||||||
@ApiTags('content')
|
@ApiTags('content')
|
||||||
@@ -65,6 +65,7 @@ export class ContentController {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Public()
|
||||||
@Get('master/:id')
|
@Get('master/:id')
|
||||||
@ApiOperation({ summary: 'Get master content by ID' })
|
@ApiOperation({ summary: 'Get master content by ID' })
|
||||||
async getMasterById(@Param('id', ParseUUIDPipe) id: string) {
|
async getMasterById(@Param('id', ParseUUIDPipe) id: string) {
|
||||||
@@ -94,6 +95,7 @@ export class ContentController {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Public()
|
||||||
@Get()
|
@Get()
|
||||||
@ApiOperation({ summary: 'Get user contents' })
|
@ApiOperation({ summary: 'Get user contents' })
|
||||||
@ApiQuery({ name: 'platform', required: false, enum: SocialPlatform })
|
@ApiQuery({ name: 'platform', required: false, enum: SocialPlatform })
|
||||||
@@ -105,7 +107,7 @@ export class ContentController {
|
|||||||
@Query('limit') limit?: number,
|
@Query('limit') limit?: number,
|
||||||
@Query('offset') offset?: number,
|
@Query('offset') offset?: number,
|
||||||
) {
|
) {
|
||||||
return this.contentService.getByUser(userId, {
|
return this.contentService.getByUser(userId || undefined, {
|
||||||
platform,
|
platform,
|
||||||
status,
|
status,
|
||||||
limit: limit ? Number(limit) : undefined,
|
limit: limit ? Number(limit) : undefined,
|
||||||
@@ -132,12 +134,14 @@ export class ContentController {
|
|||||||
return this.contentService.getAnalytics(userId, period);
|
return this.contentService.getAnalytics(userId, period);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Public()
|
||||||
@Get(':id')
|
@Get(':id')
|
||||||
@ApiOperation({ summary: 'Get content by ID' })
|
@ApiOperation({ summary: 'Get content by ID' })
|
||||||
async getById(@Param('id', ParseUUIDPipe) id: string) {
|
async getById(@Param('id', ParseUUIDPipe) id: string) {
|
||||||
return this.contentService.getById(id);
|
return this.contentService.getById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Public()
|
||||||
@Put(':id')
|
@Put(':id')
|
||||||
@ApiOperation({ summary: 'Update content' })
|
@ApiOperation({ summary: 'Update content' })
|
||||||
async updateContent(
|
async updateContent(
|
||||||
@@ -160,6 +164,7 @@ export class ContentController {
|
|||||||
return this.contentService.publish(id, publishedUrl);
|
return this.contentService.publish(id, publishedUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Public()
|
||||||
@Delete(':id')
|
@Delete(':id')
|
||||||
@ApiOperation({ summary: 'Delete content' })
|
@ApiOperation({ summary: 'Delete content' })
|
||||||
async deleteContent(@Param('id', ParseUUIDPipe) id: string) {
|
async deleteContent(@Param('id', ParseUUIDPipe) id: string) {
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ export class ContentService {
|
|||||||
* Get user's content with filters
|
* Get user's content with filters
|
||||||
*/
|
*/
|
||||||
async getByUser(
|
async getByUser(
|
||||||
userId: string,
|
userId?: string,
|
||||||
options?: {
|
options?: {
|
||||||
platform?: SocialPlatform;
|
platform?: SocialPlatform;
|
||||||
status?: ContentStatus;
|
status?: ContentStatus;
|
||||||
@@ -85,12 +85,12 @@ export class ContentService {
|
|||||||
) {
|
) {
|
||||||
return this.prisma.content.findMany({
|
return this.prisma.content.findMany({
|
||||||
where: {
|
where: {
|
||||||
userId,
|
...(userId && { userId }),
|
||||||
...(options?.platform && { platform: options.platform }),
|
...(options?.platform && { type: options.platform as any }),
|
||||||
...(options?.status && { status: options.status }),
|
...(options?.status && { status: options.status }),
|
||||||
},
|
},
|
||||||
orderBy: { createdAt: 'desc' },
|
orderBy: { createdAt: 'desc' },
|
||||||
take: options?.limit || 20,
|
take: options?.limit || 50,
|
||||||
skip: options?.offset || 0,
|
skip: options?.offset || 0,
|
||||||
include: {
|
include: {
|
||||||
masterContent: { select: { id: true, title: true, type: true } },
|
masterContent: { select: { id: true, title: true, type: true } },
|
||||||
|
|||||||
Reference in New Issue
Block a user