Merge branch 'main' of git.targo.ca:Targo/targo_backend

This commit is contained in:
Matthieu Haineault 2026-01-13 09:16:15 -05:00
commit 052cebe003
6 changed files with 16 additions and 3 deletions

View File

@ -4,17 +4,21 @@ import { UserMessageDto } from 'src/chatbot/dtos/user-message.dto';
import { ChatbotService } from 'src/chatbot/chatbot.service'; import { ChatbotService } from 'src/chatbot/chatbot.service';
import { PageContextDto } from 'src/chatbot/dtos/page-context.dto'; import { PageContextDto } from 'src/chatbot/dtos/page-context.dto';
import { Access } from 'src/common/decorators/module-access.decorators'; import { Access } from 'src/common/decorators/module-access.decorators';
import { ModuleAccessAllowed } from 'src/common/decorators/modules-guard.decorators';
import { Modules as ModulesEnum } from ".prisma/client";
@Controller('chatbot') @Controller('chatbot')
export class ChatbotController { export class ChatbotController {
constructor(private readonly chatbotService: ChatbotService) {} constructor(private readonly chatbotService: ChatbotService) {}
@Post('') @Post('')
@ModuleAccessAllowed(ModulesEnum.chatbot)
async testConnection(@Body() body: UserMessageDto): Promise<Message> { async testConnection(@Body() body: UserMessageDto): Promise<Message> {
return await this.chatbotService.pingExternalApi(body); return await this.chatbotService.pingExternalApi(body);
} }
@Post('context') @Post('context')
@ModuleAccessAllowed(ModulesEnum.chatbot)
async sendContext(@Body() body: PageContextDto): Promise<string> { async sendContext(@Body() body: PageContextDto): Promise<string> {
const sendPageContext = await this.chatbotService.sendPageContext(body); const sendPageContext = await this.chatbotService.sendPageContext(body);
return sendPageContext; return sendPageContext;
@ -22,6 +26,7 @@ export class ChatbotController {
// Will have to modify later on to accomodate newer versions of User Auth/User type Structure // Will have to modify later on to accomodate newer versions of User Auth/User type Structure
@Post('user') @Post('user')
@ModuleAccessAllowed(ModulesEnum.chatbot)
async sendUserCredentials(@Access('email') email: string,): Promise<boolean> { async sendUserCredentials(@Access('email') email: string,): Promise<boolean> {
const sendUserContext = await this.chatbotService.sendUserContext(email); const sendUserContext = await this.chatbotService.sendUserContext(email);
return sendUserContext; return sendUserContext;

View File

@ -19,9 +19,11 @@ export class ChatbotService {
), ),
); );
console.log('chatbot response: ', response);
const cleanText = const cleanText =
Array.isArray(response) && response[0]?.output Array.isArray(response.data) && response.data[0]?.output
? response[0].output ? response.data[0].output
: JSON.stringify(response); : JSON.stringify(response);
return { return {

View File

@ -6,7 +6,8 @@ export type Modules =
| 'employee_list' | 'employee_list'
| 'employee_management' | 'employee_management'
| 'personal_profile' | 'personal_profile'
| 'dashboard'; | 'dashboard'
| 'chatbot';
export const module_list = [ export const module_list = [
'timesheets', 'timesheets',
@ -15,4 +16,5 @@ export const module_list = [
'employee_management', 'employee_management',
'personal_profile', 'personal_profile',
'dashboard', 'dashboard',
'chatbot',
] as const; ] as const;

View File

@ -154,6 +154,7 @@ export class EmployeesGetService {
personal_profile: true, personal_profile: true,
timesheets: true, timesheets: true,
timesheets_approval: true, timesheets_approval: true,
chatbot: true,
}, },
}, },
}, },

View File

@ -53,6 +53,7 @@ export class EmployeesUpdateService {
personal_profile: normalized_access.personal_profile, personal_profile: normalized_access.personal_profile,
timesheets: normalized_access.timesheets, timesheets: normalized_access.timesheets,
timesheets_approval: normalized_access.timesheets_approval, timesheets_approval: normalized_access.timesheets_approval,
chatbot: normalized_access.chatbot,
}, },
create: { create: {
user_id: user_id.data, user_id: user_id.data,
@ -62,6 +63,7 @@ export class EmployeesUpdateService {
personal_profile: normalized_access.personal_profile, personal_profile: normalized_access.personal_profile,
timesheets: normalized_access.timesheets, timesheets: normalized_access.timesheets,
timesheets_approval: normalized_access.timesheets_approval, timesheets_approval: normalized_access.timesheets_approval,
chatbot: normalized_access.chatbot,
}, },
}); });

View File

@ -19,6 +19,7 @@ export abstract class AbstractUserService {
personal_profile: true, personal_profile: true,
timesheets: true, timesheets: true,
timesheets_approval: true, timesheets_approval: true,
chatbot: true,
}, },
}, },
}, },