-
Notifications
You must be signed in to change notification settings - Fork 4
Add thread schema #210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add thread schema #210
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| --- | ||
| description: | ||
| globs: | ||
| alwaysApply: true | ||
| --- | ||
|
|
||
| # Your rule content | ||
|
|
||
| - This Project is a private npm package. it's for all projects to interact with mongo db. | ||
| - Always use clean code and design patterns. | ||
| - Alwyas propose the codes base on the current strctour. |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| import { IThread } from '../../../src/interfaces'; | ||
| import { Thread } from '../../../src/models'; | ||
|
|
||
| describe('Thread model', () => { | ||
| describe('thread validation', () => { | ||
| let thread: IThread; | ||
| beforeEach(() => { | ||
| thread = { | ||
| id: '123456789012345678', | ||
| type: 11, | ||
| guild_id: '987654321098765432', | ||
| parent_id: '111111111111111111', | ||
| owner_id: '222222222222222222', | ||
| name: 'Test Thread', | ||
| last_message_id: '333333333333333333', | ||
| message_count: 5, | ||
| member_count: 3, | ||
| rate_limit_per_user: 0, | ||
| thread_metadata: { | ||
| archived: false, | ||
| auto_archive_duration: 1440, | ||
| archive_timestamp: '2024-01-01T00:00:00.000Z', | ||
| locked: false, | ||
| invitable: true, | ||
| }, | ||
| total_message_sent: 5, | ||
| flags: 0, | ||
| applied_tags: ['444444444444444444'], | ||
| nsfw: false, | ||
| }; | ||
| }); | ||
|
|
||
| test('should correctly validate a valid Thread data', async () => { | ||
| await expect(new Thread(thread).validate()).resolves.toBeUndefined(); | ||
| }); | ||
|
|
||
| test('should fail validation with invalid thread type', async () => { | ||
| thread.type = 5 as any; | ||
| await expect(new Thread(thread).validate()).rejects.toThrow(); | ||
| }); | ||
|
|
||
| test('should fail validation with invalid auto_archive_duration', async () => { | ||
| thread.thread_metadata.auto_archive_duration = 999; | ||
| await expect(new Thread(thread).validate()).rejects.toThrow(); | ||
| }); | ||
|
|
||
| test('should fail validation with name too long', async () => { | ||
| thread.name = 'x'.repeat(101); | ||
| await expect(new Thread(thread).validate()).rejects.toThrow(); | ||
| }); | ||
|
|
||
| test('should fail validation with negative message_count', async () => { | ||
| thread.message_count = -1; | ||
| await expect(new Thread(thread).validate()).rejects.toThrow(); | ||
| }); | ||
|
|
||
| test('should fail validation with member_count over limit', async () => { | ||
| thread.member_count = 51; | ||
| await expect(new Thread(thread).validate()).rejects.toThrow(); | ||
| }); | ||
|
|
||
| test('should fail validation with rate_limit_per_user over limit', async () => { | ||
| thread.rate_limit_per_user = 21601; | ||
| await expect(new Thread(thread).validate()).rejects.toThrow(); | ||
| }); | ||
|
|
||
| test('should handle ANNOUNCEMENT_THREAD type', async () => { | ||
| thread.type = 10; | ||
| await expect(new Thread(thread).validate()).resolves.toBeUndefined(); | ||
| }); | ||
|
|
||
| test('should handle PRIVATE_THREAD type', async () => { | ||
| thread.type = 12; | ||
| thread.thread_metadata.invitable = false; | ||
| await expect(new Thread(thread).validate()).resolves.toBeUndefined(); | ||
| }); | ||
|
|
||
| test('should handle minimal required data', async () => { | ||
| const minimalThread = { | ||
| id: '123456789012345678', | ||
| type: 11, | ||
| guild_id: '987654321098765432', | ||
| parent_id: '111111111111111111', | ||
| owner_id: '222222222222222222', | ||
| name: 'Minimal Thread', | ||
| thread_metadata: { | ||
| archived: false, | ||
| auto_archive_duration: 1440, | ||
| archive_timestamp: '2024-01-01T00:00:00.000Z', | ||
| locked: false, | ||
| }, | ||
| }; | ||
| await expect(new Thread(minimalThread).validate()).resolves.toBeUndefined(); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import { Snowflake } from 'discord.js'; | ||
| import { Model } from 'mongoose'; | ||
|
|
||
| export interface IThreadMetadata { | ||
| archived: boolean; | ||
| auto_archive_duration: number; | ||
| archive_timestamp: string; | ||
| locked: boolean; | ||
| invitable?: boolean; | ||
| create_timestamp?: string; | ||
| } | ||
|
|
||
| export interface IThread { | ||
| id: Snowflake; | ||
| type: 10 | 11 | 12; | ||
| guild_id: Snowflake; | ||
| parent_id: Snowflake; | ||
| owner_id: Snowflake; | ||
| name: string; | ||
| last_message_id?: Snowflake | null; | ||
| message_count?: number; | ||
| member_count?: number; | ||
| rate_limit_per_user?: number; | ||
| thread_metadata: IThreadMetadata; | ||
| total_message_sent?: number; | ||
| flags?: number; | ||
| applied_tags?: Snowflake[]; | ||
| nsfw?: boolean; | ||
| deletedAt?: Date | null; | ||
| } | ||
|
|
||
| export interface IThreadUpdateBody { | ||
| name?: string; | ||
| archived?: boolean; | ||
| auto_archive_duration?: number; | ||
| locked?: boolean; | ||
| invitable?: boolean; | ||
| rate_limit_per_user?: number; | ||
| flags?: number; | ||
| applied_tags?: Snowflake[]; | ||
| nsfw?: boolean; | ||
| deletedAt?: Date | null; | ||
| } | ||
|
|
||
| export interface IThreadMethods { | ||
| softDelete: () => Promise<void>; | ||
| } | ||
|
|
||
| export interface ThreadModel extends Model<IThread, Record<string, unknown>, IThreadMethods> { | ||
| paginate: (filter: object, options: object) => any; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { model } from 'mongoose'; | ||
|
|
||
| import { IThread, ThreadModel } from '../interfaces'; | ||
| import { threadSchema } from './schemas'; | ||
|
|
||
| export default model<IThread, ThreadModel>('Thread', threadSchema); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix the filename typo.
The filename contains a typo: "Platfrom" should be "Platform". This could cause confusion and make the file harder to find.
Consider renaming the file to
Platform.interface.tsto correct the typo.🤖 Prompt for AI Agents