feat(notifications): add notifications to schema

This commit is contained in:
Nic D 2026-02-25 11:05:55 -05:00
parent 043bc91a56
commit c75bbb445e
3 changed files with 35 additions and 3 deletions

View File

@ -16,6 +16,7 @@ model Users {
phone_number String phone_number String
residence String? residence String?
role Roles @default(EMPLOYEE) role Roles @default(EMPLOYEE)
notifications Notifications? @relation("UserNotification")
employee Employees? @relation("UserEmployee") employee Employees? @relation("UserEmployee")
oauth_sessions OAuthSessions[] @relation("UserOAuthSessions") oauth_sessions OAuthSessions[] @relation("UserOAuthSessions")
preferences Preferences? @relation("UserPreferences") preferences Preferences? @relation("UserPreferences")
@ -24,6 +25,20 @@ model Users {
@@map("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 { model userModuleAccess {
id Int @id @default(autoincrement()) id Int @id @default(autoincrement())
user_id String @unique @db.Uuid user_id String @unique @db.Uuid

View File

@ -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
);

View File

@ -3,7 +3,6 @@ import { UserMessageDto } from 'src/chatbot/dtos/user-message.dto';
import { HttpService } from '@nestjs/axios'; import { HttpService } from '@nestjs/axios';
import { firstValueFrom } from 'rxjs'; import { firstValueFrom } from 'rxjs';
import { Message } from 'src/chatbot/dtos/dialog-message.dto'; import { Message } from 'src/chatbot/dtos/dialog-message.dto';
import { AxiosError, isAxiosError } from 'axios';
@Injectable() @Injectable()
export class ChatbotService { export class ChatbotService {
@ -12,13 +11,16 @@ export class ChatbotService {
async pingExternalApi(body: UserMessageDto, email: string): Promise<Message> { async pingExternalApi(body: UserMessageDto, email: string): Promise<Message> {
try { try {
const { data } = await firstValueFrom(this.httpService.post( const response = await firstValueFrom(this.httpService.post(
'https://n8nai.targo.ca/webhook/chatty-Mcbot', 'https://n8nai.targo.ca/webhook/chatty-Mcbot',
{ userInput: body.userInput, userId: email, sessionId: this.sessionId, pageContext: body.pageContext ?? undefined } { userInput: body.userInput, userId: email, sessionId: this.sessionId, pageContext: body.pageContext ?? undefined }
)); ));
console.log('chatbot data received: ', response);
return { return {
text: data[0].output, // text: data[0].output,
text: 'success',
sent: false, sent: false,
}; };
} catch (error) { } catch (error) {