diff --git a/prisma/postgres/schema.prisma b/prisma/postgres/schema.prisma index 59ec36d..74749f9 100644 --- a/prisma/postgres/schema.prisma +++ b/prisma/postgres/schema.prisma @@ -16,6 +16,7 @@ model Users { phone_number String residence String? role Roles @default(EMPLOYEE) + notifications Notifications? @relation("UserNotification") employee Employees? @relation("UserEmployee") oauth_sessions OAuthSessions[] @relation("UserOAuthSessions") preferences Preferences? @relation("UserPreferences") @@ -24,6 +25,20 @@ model Users { @@map("users") } +model Notifications { + id Int @id @default(autoincrement()) + user_id String @unique @db.Uuid + affected_module Modules + subject String + description String + metadata Json @db.JsonB + created_at DateTime @default(now()) + viewed_at DateTime? + user Users @relation("UserNotification", fields: [user_id], references: [id]) + + @@map("notifications") +} + model userModuleAccess { id Int @id @default(autoincrement()) user_id String @unique @db.Uuid diff --git a/prisma/postgres/scripts/create-table-notifications.sql b/prisma/postgres/scripts/create-table-notifications.sql new file mode 100644 index 0000000..c4128de --- /dev/null +++ b/prisma/postgres/scripts/create-table-notifications.sql @@ -0,0 +1,15 @@ +CREATE TABLE notifications ( + id integer GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + user_id uuid NOT NULL, + affected_module text, + subject text NOT NULL, + description text, + metadata jsonb, + created_at timestamptz NOT NULL DEFAULT now(), + viewed_at timestamptz NULL, + + CONSTRAINT notifications_user_id_fkey + FOREIGN KEY (user_id) + REFERENCES users(id) + ON DELETE CASCADE +); \ No newline at end of file diff --git a/src/chatbot/chatbot.service.ts b/src/chatbot/chatbot.service.ts index 3df19d7..81a96b1 100644 --- a/src/chatbot/chatbot.service.ts +++ b/src/chatbot/chatbot.service.ts @@ -3,7 +3,6 @@ import { UserMessageDto } from 'src/chatbot/dtos/user-message.dto'; import { HttpService } from '@nestjs/axios'; import { firstValueFrom } from 'rxjs'; import { Message } from 'src/chatbot/dtos/dialog-message.dto'; -import { AxiosError, isAxiosError } from 'axios'; @Injectable() export class ChatbotService { @@ -12,13 +11,16 @@ export class ChatbotService { async pingExternalApi(body: UserMessageDto, email: string): Promise { try { - const { data } = await firstValueFrom(this.httpService.post( + const response = await firstValueFrom(this.httpService.post( 'https://n8nai.targo.ca/webhook/chatty-Mcbot', { userInput: body.userInput, userId: email, sessionId: this.sessionId, pageContext: body.pageContext ?? undefined } )); + + console.log('chatbot data received: ', response); return { - text: data[0].output, + // text: data[0].output, + text: 'success', sent: false, }; } catch (error) {