Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
harishmohanraj committed Nov 10, 2023
1 parent 1d16006 commit 26925ad
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion main.wasp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ query getChats {

query getConversations {
fn: import { getConversations } from "@server/queries.js",
entities: [Conversation]
entities: [Chat, Conversation]
}

// query getConversations {
Expand Down
26 changes: 25 additions & 1 deletion src/server/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import HttpError from '@wasp/core/HttpError.js';

import type { Chat, Conversation } from '@wasp/entities';
import type { GetChats, GetConversations } from '@wasp/queries/types';
import internal from 'stream';

// import type { Conversation } from '@wasp/entities';
// import type { GetConversations } from '@wasp/queries/types';
Expand Down Expand Up @@ -40,12 +41,35 @@ type GetConversationPayload = {
chatId: number
}

type Chats = {
id: number;
createdAt: Date;
updatedAt: Date;
userId: number;
name: string;
}

export const getConversations: GetConversations<GetConversationPayload, Conversation> = async (args, context) => {
if (!context.user) {
throw new HttpError(401);
}
const chats: Chats[] = await context.entities.Chat.findMany({
where: {
user: {
id: context.user.id
}
},
orderBy: { id: 'desc' },
})
const chatIds: number[] = chats.map((item) => item.id);
if (args.chatId && !chatIds.includes(args.chatId)) {
return {}
}

return context.entities.Conversation.findFirstOrThrow({
where: { chatId: args.chatId },
where: {
chatId: args.chatId
},
})
}

Expand Down

0 comments on commit 26925ad

Please sign in to comment.