-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
37 changed files
with
511 additions
and
374 deletions.
There are no files selected for viewing
This file contains 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,41 @@ | ||
import { db, selectUuid, sql } from '@member-protocol/db/node' | ||
import { Attachment } from '@/src/components/message/MessageContent' | ||
|
||
const getMessages = async (postId: string) => { | ||
return await db | ||
.selectFrom('messages') | ||
.leftJoin('attachments', 'attachments.messageId', 'messages.snowflakeId') | ||
.innerJoin('users', 'users.snowflakeId', 'messages.userId') | ||
.select([ | ||
selectUuid('messages.id').as('id'), | ||
'messages.snowflakeId', | ||
'messages.content', | ||
'messages.createdAt', | ||
selectUuid('users.id').as('authorId'), | ||
'users.avatarUrl as authorAvatarUrl', | ||
'users.username as authorUsername', | ||
'users.isPublic as userIsPublic', | ||
'users.isModerator as userIsModerator', | ||
sql<Attachment[]>` | ||
if( | ||
count(attachments.id) > 0, | ||
json_arrayagg( | ||
json_object( | ||
'id', ${selectUuid('attachments.id')}, | ||
'url', attachments.url, | ||
'name', attachments.name, | ||
'contentType', attachments.contentType | ||
) | ||
), | ||
json_array() | ||
) | ||
`.as('attachments'), | ||
]) | ||
.where('postId', '=', postId) | ||
.where('messages.snowflakeId', '!=', postId) | ||
.groupBy('messages.id') | ||
.orderBy('messages.createdAt', 'asc') | ||
.execute() | ||
} | ||
|
||
export default getMessages |
This file contains 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,29 @@ | ||
import { db, selectUuid } from '@member-protocol/db/node' | ||
|
||
const getPost = async (snowflakeId: string) => { | ||
return await db | ||
.selectFrom('posts') | ||
.innerJoin('users', 'users.snowflakeId', 'posts.userId') | ||
.innerJoin('channels', 'channels.snowflakeId', 'posts.channelId') | ||
.select([ | ||
selectUuid('posts.id').as('id'), | ||
'posts.snowflakeId', | ||
'posts.title', | ||
'posts.createdAt', | ||
'posts.answerId', | ||
'users.username', | ||
'users.isPublic as userIsPublic', | ||
'users.avatarUrl as userAvatar', | ||
'channels.name as channelName', | ||
(eb) => | ||
eb | ||
.selectFrom('messages') | ||
.select(eb.fn.countAll<number>().as('count')) | ||
.where('messages.postId', '=', eb.ref('posts.snowflakeId')) | ||
.as('messagesCount'), | ||
]) | ||
.where('posts.snowflakeId', '=', snowflakeId) | ||
.executeTakeFirst() | ||
} | ||
|
||
export default getPost |
This file contains 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,40 @@ | ||
import { db, selectUuid, sql } from '@member-protocol/db/node' | ||
import { Attachment } from '@/src/components/message/MessageContent' | ||
|
||
const getPostMessage = async (postId: string) => { | ||
return await db | ||
.selectFrom('messages') | ||
.leftJoin('attachments', 'attachments.messageId', 'messages.snowflakeId') | ||
.innerJoin('users', 'users.snowflakeId', 'messages.userId') | ||
.select([ | ||
selectUuid('messages.id').as('id'), | ||
'messages.content', | ||
'messages.createdAt', | ||
selectUuid('users.id').as('authorId'), | ||
'users.avatarUrl as authorAvatarUrl', | ||
'users.username as authorUsername', | ||
'users.isPublic as userIsPublic', | ||
'users.isModerator as userIsModerator', | ||
sql<Attachment[]>` | ||
if( | ||
count(attachments.id) > 0, | ||
json_arrayagg( | ||
json_object( | ||
'id', ${selectUuid('attachments.id')}, | ||
'url', attachments.url, | ||
'name', attachments.name, | ||
'contentType', attachments.contentType | ||
) | ||
), | ||
json_array() | ||
) | ||
`.as('attachments'), | ||
]) | ||
.where('messages.postId', '=', postId) | ||
.where('messages.snowflakeId', '=', postId) | ||
.groupBy('messages.id') | ||
.orderBy('messages.createdAt', 'asc') | ||
.executeTakeFirst() | ||
} | ||
|
||
export default getPostMessage |
This file contains 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 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 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 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.