-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathfind-user-ai-chat-by-id.use.case.ts
More file actions
33 lines (29 loc) · 1.4 KB
/
Copy pathfind-user-ai-chat-by-id.use.case.ts
File metadata and controls
33 lines (29 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { Inject, Injectable, NotFoundException } from '@nestjs/common';
import AbstractUseCase from '../../../../common/abstract-use.case.js';
import { IGlobalDatabaseContext } from '../../../../common/application/global-database-context.interface.js';
import { BaseType } from '../../../../common/data-injection.tokens.js';
import { Messages } from '../../../../exceptions/text/messages.js';
import { FindUserAiChatByIdDs } from '../application/data-structures/user-ai-chat.ds.js';
import { UserAiChatWithMessagesRO } from '../application/response-objects/user-ai-chat.ro.js';
import { buildUserAiChatWithMessagesRO } from '../application/utils/build-user-ai-chat-ro.util.js';
import { IFindUserAiChatById } from './user-ai-chat-use-cases.interface.js';
@Injectable()
export class FindUserAiChatByIdUseCase
extends AbstractUseCase<FindUserAiChatByIdDs, UserAiChatWithMessagesRO>
implements IFindUserAiChatById
{
constructor(
@Inject(BaseType.GLOBAL_DB_CONTEXT)
protected _dbContext: IGlobalDatabaseContext,
) {
super();
}
protected async implementation(inputData: FindUserAiChatByIdDs): Promise<UserAiChatWithMessagesRO> {
const { userId, chatId } = inputData;
const foundChat = await this._dbContext.userAiChatRepository.findChatWithMessagesByIdAndUserId(chatId, userId);
if (!foundChat) {
throw new NotFoundException(Messages.AI_CHAT_NOT_FOUND);
}
return buildUserAiChatWithMessagesRO(foundChat);
}
}