Skip to content

Commit

Permalink
feat: 💥 Breaking: POST '/threads route now uses a different payload…
Browse files Browse the repository at this point in the history
… format.
  • Loading branch information
spuxx1701 committed Apr 4, 2024
1 parent 365e93f commit 27ac574
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 58 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/).

## [2.3.3] - 2024-04-04
## [3.0.0] - UNRELEASED

### Changed

- 💥 Breaking: `POST '/threads` route now uses a different payload format.

### Fixed

Expand Down
3 changes: 3 additions & 0 deletions src/posts/resources/post.properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,21 @@ export const postProperties = {
convertUrls: {
description: 'Whether URLs should be converted to URL tags automatically.',
default: true,
required: false,
} as ApiPropertyOptions,

disableBbCode: {
description:
'Whether BBCode should not be used. If set to true, BBCode tags will be displayed as plain text.',
default: false,
required: false,
} as ApiPropertyOptions,

disableEmojis: {
description:
'Whether emojis should not be converted automatically. If set to true, emojis will be displayed as plain text.',
default: false,
required: false,
} as ApiPropertyOptions,

url: {
Expand Down
77 changes: 42 additions & 35 deletions src/threads/resources/thread.create.resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,57 +12,30 @@ import { postIcons } from 'src/posts/config/post-icons';
import { postProperties } from 'src/posts/resources/post.properties';
import { Trim } from 'src/utility/transformers/trim.transformer';

export class ThreadCreateResource {
@ApiProperty({
description: 'The board you want the thread to create in.',
example: '75',
})
@IsNumberString()
boardId: string;

@ApiProperty({
description: "The thread's title.",
example: 'This thread was created using potber-api!',
})
@IsString()
@Trim()
@MinLength(1)
@MaxLength(255)
title: string;

export class OpeningPostResource {
@ApiProperty({
description: "The thread's subtitle.",
description:
"The opening post's title. Acts as the thread's subtitle. Can be empty.",
example: "It's a lot of fun!",
required: false,
})
@IsString()
@Trim()
@MaxLength(255)
@IsOptional()
subtitle?: string;
title?: string;

@ApiProperty({
description:
"The thread's icon. Will be the same as as the opening post's icon.",
description: "The opening posts's icon. Acts as the thread's icon.",
example: '37',
required: false,
})
@IsNumberString()
@IsIn(postIcons)
@IsOptional()
icon?: string;

@ApiProperty({
description: "The thread's tags.",
example: ['potber', 'potber-api'],
})
@IsString({ each: true })
@IsOptional()
tags?: string[] = [];

@ApiProperty({
description: "The message body of the thread's opening post.",
example:
'This thread was created using potber-api. Find out more about potber-api [url=https://github.com/spuxx1701/potber-api]here[/url]!',
})
@ApiProperty(postProperties.message)
@IsString()
@Trim()
@MinLength(1)
Expand All @@ -83,6 +56,40 @@ export class ThreadCreateResource {
@IsOptional()
@IsBoolean()
disableEmojis?: boolean = postProperties.disableEmojis.default;
}

export class ThreadCreateResource {
@ApiProperty({
description: 'The board you want the thread to create in.',
example: '75',
})
@IsNumberString()
boardId: string;

@ApiProperty({
description: "The thread's title.",
example: 'This thread was created using potber-api!',
})
@IsString()
@Trim()
@MinLength(1)
@MaxLength(255)
title: string;

@ApiProperty({
description: "The thread's tags.",
example: ['potber', 'potber-api'],
required: false,
})
@IsString({ each: true })
@IsOptional()
tags?: string[] = [];

@ApiProperty({
description: 'The opening post of the thread.',
type: OpeningPostResource,
})
openingPost: OpeningPostResource;

constructor(init: ThreadCreateResource) {
for (const key in init) {
Expand Down
12 changes: 6 additions & 6 deletions src/threads/services/threads.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,13 @@ export class ThreadsService {
BID: thread.boardId,
token,
thread_title: thread.title,
thread_subtitle: thread.subtitle ?? '',
thread_subtitle: thread.openingPost.title ?? '',
thread_tags: thread.tags.length > 0 ? thread.tags.join('++') : '',
thread_icon: thread.icon ?? '0',
message: thread.message,
thread_converturls: thread.convertUrls ? '1' : '0',
thread_disablebbcode: thread.disableBbCode ? '1' : '0',
thread_disablesmilies: thread.disableEmojis ? '1' : '0',
thread_icon: thread.openingPost.icon ?? '0',
message: thread.openingPost.message,
thread_converturls: thread.openingPost.convertUrls ? '1' : '0',
thread_disablebbcode: thread.openingPost.disableBbCode ? '1' : '0',
thread_disablesmilies: thread.openingPost.disableEmojis ? '1' : '0',
submit: 'Eintragen',
},
{
Expand Down
45 changes: 29 additions & 16 deletions src/threads/threads.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { TestContainer, createTestContainer } from 'test/container';
import { ThreadsModule } from './threads.module';
import { threadsHandlers } from 'test/msw/handlers/threads/threads.handlers';
import { fakeRequest } from 'test/helpers/fake-request';
import { ThreadCreateResource } from './resources/thread.create.resource';
import {
OpeningPostResource,

Check warning on line 6 in src/threads/threads.e2e.test.ts

View workflow job for this annotation

GitHub Actions / lint / Lint

'OpeningPostResource' is defined but never used
ThreadCreateResource,
} from './resources/thread.create.resource';
import { ThreadReadResource } from './resources/thread.read.resource';

describe('Threads | e2e', () => {
Expand All @@ -22,9 +25,11 @@ describe('Threads | e2e', () => {
const response = await request.send({
boardId: '75',
title: 'neuer thread',
subtitle: 'dies ist ein neuer thread',
message: 'das ist der startpost',
icon: '37',
openingPost: {
title: 'dies ist ein neuer thread',
message: 'das ist der startpost',
icon: '37',
},
} as ThreadCreateResource);
expect(response.status).toBe(201);
expect(response.body).toStrictEqual({
Expand Down Expand Up @@ -87,9 +92,11 @@ describe('Threads | e2e', () => {
const response = await request.send({
boardId: '75',
title: 'neuer thread',
subtitle: 'dies ist ein neuer thread',
message: 'das ist der startpost',
icon: '37',
openingPost: {
title: 'dies ist ein neuer thread',
message: 'das ist der startpost',
icon: '37',
},
} as ThreadCreateResource);
expect(response.status).toBe(401);
});
Expand All @@ -99,9 +106,11 @@ describe('Threads | e2e', () => {
const response = await request.send({
boardId: '75',
title: '',
subtitle: 'dies ist ein neuer thread',
message: 'das ist der startpost',
icon: '37',
openingPost: {
title: 'dies ist ein neuer thread',
message: 'das ist der startpost',
icon: '37',
},
} as ThreadCreateResource);
expect(response.status).toBe(400);
expect(response.body.message).toContain(
Expand All @@ -114,9 +123,11 @@ describe('Threads | e2e', () => {
const response = await request.send({
boardId: '75',
title: 'neuer thread',
subtitle: 'dies ist ein neuer thread',
message: '',
icon: '37',
openingPost: {
title: 'dies ist ein neuer thread',
message: '',
icon: '37',
},
} as ThreadCreateResource);
expect(response.status).toBe(400);
expect(response.body.message).toContain(
Expand All @@ -129,9 +140,11 @@ describe('Threads | e2e', () => {
const response = await request.send({
boardId: '',
title: 'neuer thread',
subtitle: 'dies ist ein neuer thread',
message: 'das ist der startpost',
icon: '37',
openingPost: {
title: 'dies ist ein neuer thread',
message: 'das ist der startpost',
icon: '37',
},
} as ThreadCreateResource);
expect(response.status).toBe(400);
expect(response.body.message).toContain(
Expand Down

0 comments on commit 27ac574

Please sign in to comment.