Skip to content

Commit b30d951

Browse files
authored
Merge pull request #74 from Dialogue-Bot/DIAL-42-implement-test-your-bot
Dial 42 implement test your bot
2 parents 0944a32 + 622fbf7 commit b30d951

22 files changed

+2249
-17
lines changed

server/src/constants/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ export const ENDPOINTS = {
6464
PREDICT: '/intent/predict',
6565
FOR_SELECT: '/intent/for-select',
6666
},
67+
CONVERSATION_LIVE_CHAT: {
68+
INDEX: '/conversation-live-chat',
69+
GET_MESSAGES: '/conversation-live-chat/:id',
70+
},
6771
}
6872

6973
export const LOCALE_KEY = 'lang'
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { LOCALE_KEY } from '@/constants'
2+
import { LocaleService } from '@/i18n/ctx'
3+
import { RequestWithUser } from '@/interfaces/auth.interface'
4+
import { ConversationLiveChatService } from '@/services/conversation-live-chat.service'
5+
import { MessageService } from '@/services/message.service'
6+
import { catchAsync } from '@/utils/catch-async'
7+
import { StatusCodes } from 'http-status-codes'
8+
import Container from 'typedi'
9+
10+
export class ConversationLiveChatController {
11+
private readonly conversationLiveChatService = Container.get(
12+
ConversationLiveChatService,
13+
)
14+
15+
private readonly localeService = Container.get<LocaleService>(LOCALE_KEY)
16+
17+
private readonly messageService = Container.get(MessageService)
18+
19+
public createConversation = catchAsync(async (req, res) => {
20+
const data = await this.conversationLiveChatService.createConversation(
21+
req.body,
22+
)
23+
24+
res.status(StatusCodes.OK).json({
25+
message: this.localeService
26+
.i18n()
27+
.CONVERSATION_LIVE_CHAT.CREATE_SUCCESS(),
28+
data,
29+
})
30+
})
31+
32+
public getConversations = catchAsync(async (req: RequestWithUser, res) => {
33+
const data = await this.conversationLiveChatService.getConversations(
34+
req.user.id as string,
35+
req.query as any,
36+
)
37+
38+
res.status(StatusCodes.OK).json({ data })
39+
})
40+
41+
public getMessages = catchAsync(async (req: RequestWithUser, res) => {
42+
const data = await this.messageService.getMessagesByConversationId(
43+
req.params.id as string,
44+
)
45+
46+
res.status(StatusCodes.OK).json({ data })
47+
})
48+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
ALTER TABLE "conversations" ADD COLUMN "channel_id" text;--> statement-breakpoint
2+
ALTER TABLE "conversations" ADD COLUMN "id" varchar(36) DEFAULT 'xr9chlw9p0c1mts5zp0ht9fg' NOT NULL;--> statement-breakpoint
3+
DO $$ BEGIN
4+
ALTER TABLE "conversations" ADD CONSTRAINT "conversations_channel_id_channels_id_fk" FOREIGN KEY ("channel_id") REFERENCES "channels"("id") ON DELETE set null ON UPDATE no action;
5+
EXCEPTION
6+
WHEN duplicate_object THEN null;
7+
END $$;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE "conversations" ALTER COLUMN "id" SET DEFAULT 'nsb2hhjuvcsh9gdi22rex2yw';
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
ALTER TABLE "messages" DROP CONSTRAINT "messages_conversation_id_conversations_user_id_fk";
2+
--> statement-breakpoint
3+
ALTER TABLE "conversations" ALTER COLUMN "id" SET DEFAULT 'fjcrx88jmtr9jh59nhupcmnk';--> statement-breakpoint
4+
DO $$ BEGIN
5+
ALTER TABLE "messages" ADD CONSTRAINT "messages_conversation_id_conversations_id_fk" FOREIGN KEY ("conversation_id") REFERENCES "conversations"("id") ON DELETE cascade ON UPDATE no action;
6+
EXCEPTION
7+
WHEN duplicate_object THEN null;
8+
END $$;

0 commit comments

Comments
 (0)