diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 4fb2688..7a22a2a 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -42,14 +42,17 @@ model timetable { } model users { - id Int @id(map: "pk_users") @default(autoincrement()) - login String @unique @db.VarChar(25) - pass String @db.VarChar(100) - fullName String? @db.VarChar(100) - is_admin Boolean @default(false) - lore String? @db.Text() + id Int @id(map: "pk_users") @default(autoincrement()) + login String @unique @db.VarChar(25) + pass String @db.VarChar(100) + fullName String? @db.VarChar(100) + is_admin Boolean @default(false) + lore String? @db.Text() + timetable timetable[] user_session user_session[] + chat_message chat_message[] + user_in_chat user_in_chat[] } model user_session { @@ -58,3 +61,33 @@ model user_session { user users @relation(fields: [usersId], references: [id]) } + +model chat { + id String @id @default(uuid()) + title String + + chat_message chat_message[] + user_in_chat user_in_chat[] +} + +model chat_message { + id String @id @default(uuid()) + text String + + user users @relation(fields: [userId], references: [id]) + chat chat @relation(fields: [chatId], references: [id]) + + sendAt DateTime @default(now()) + + chatId String + userId Int +} + +model user_in_chat { + id Int @id @default(autoincrement()) + chatId String + userId Int + + chat chat @relation(fields: [chatId], references: [id]) + user users @relation(fields: [userId], references: [id]) +} diff --git a/src/components/ChatList.astro b/src/components/ChatList.astro new file mode 100644 index 0000000..51333cb --- /dev/null +++ b/src/components/ChatList.astro @@ -0,0 +1,31 @@ +--- +import type { users, timetable } from "@prisma/client"; +import { getUserChats } from "../db"; + +export interface Props { + user: users; +} + +const { user } = Astro.props; + +const chats = await getUserChats(user.id); +--- + +
{e.text}
+ + {e.user.fullName ?? e.user.login} • {formatDate(e.sendAt)} + +