Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,21 @@ model Snippet {
createdAt DateTime @default(now())
}

model Room {
id String @id @default(auto()) @map("_id") @db.ObjectId
code String @unique
createdAt DateTime @default(now())
pastes Paste[]
}

model Paste {
id String @id @default(auto()) @map("_id") @db.ObjectId
text String
title String
password String?
id String @id @default(auto()) @map("_id") @db.ObjectId
text String
title String
password String?
paste_expiration Int?
encrypted Int?
createdAt DateTime @default(now())
encrypted Int?
createdAt DateTime @default(now())
roomId String? @db.ObjectId
room Room? @relation(fields: [roomId], references: [id])
}
13 changes: 12 additions & 1 deletion src/lib/dataStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,17 @@ const prisma = new PrismaClient();

// Function to insert a new paste
export async function insertPaste(data) {
const { text, title, password, paste_expiration, encrypted } = data;
const { text, title, password, paste_expiration, encrypted, roomCode } = data;

let roomId = undefined;
if (roomCode) {
const room = await prisma.room.findUnique({
where: { code: roomCode }
});
if (room) {
roomId = room.id;
}
}

// Insert the new paste into MongoDB
const newPaste = await prisma.paste.create({
Expand All @@ -16,6 +26,7 @@ export async function insertPaste(data) {
password,
paste_expiration,
encrypted,
roomId
},
});

Expand Down
Loading