feat(backend): add fastify api, auth, prisma schema and jobs
This commit is contained in:
81
apps/backend/prisma/schema.prisma
Normal file
81
apps/backend/prisma/schema.prisma
Normal file
@@ -0,0 +1,81 @@
|
||||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
}
|
||||
|
||||
datasource db {
|
||||
provider = "postgresql"
|
||||
url = env("DATABASE_URL")
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// Users
|
||||
//
|
||||
// There are exactly two users in this application. Their credentials
|
||||
// (username + bcrypt hash) live in env — see apps/backend/src/config/env.ts.
|
||||
// The DB stores only "public" fields to scope wishes and serve public
|
||||
// profiles. The password hash is intentionally NOT stored here; this keeps
|
||||
// the single source of truth for credentials in env and limits the
|
||||
// blast-radius of a DB dump.
|
||||
// --------------------------------------------------------------------
|
||||
model User {
|
||||
id String @id
|
||||
username String @unique
|
||||
slug String @unique
|
||||
displayName String
|
||||
bio String?
|
||||
avatarUrl String?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
wishes Wish[]
|
||||
}
|
||||
|
||||
enum WishStatus {
|
||||
ACTIVE
|
||||
ARCHIVED
|
||||
COMPLETED
|
||||
DELETED
|
||||
}
|
||||
|
||||
enum ImageSource {
|
||||
DEFAULT
|
||||
OG
|
||||
UPLOADED
|
||||
}
|
||||
|
||||
model Wish {
|
||||
id String @id @default(cuid())
|
||||
userId String
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
title String
|
||||
price Decimal? @db.Decimal(12, 2)
|
||||
currency String @default("RUB")
|
||||
url String?
|
||||
comment String?
|
||||
imageUrl String?
|
||||
imageSource ImageSource @default(DEFAULT)
|
||||
status WishStatus @default(ACTIVE)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
archivedAt DateTime?
|
||||
completedAt DateTime?
|
||||
deletedAt DateTime?
|
||||
sourceWishId String?
|
||||
|
||||
views GuestView[]
|
||||
|
||||
@@index([userId, status])
|
||||
@@index([deletedAt])
|
||||
@@index([createdAt])
|
||||
}
|
||||
|
||||
model GuestView {
|
||||
id String @id @default(cuid())
|
||||
guestId String
|
||||
wishId String
|
||||
wish Wish @relation(fields: [wishId], references: [id], onDelete: Cascade)
|
||||
seenAt DateTime @default(now())
|
||||
|
||||
@@unique([guestId, wishId])
|
||||
@@index([guestId])
|
||||
}
|
||||
37
apps/backend/prisma/seed.ts
Normal file
37
apps/backend/prisma/seed.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import { resolveUsers } from '../src/config/env.js';
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
async function main(): Promise<void> {
|
||||
const users = resolveUsers();
|
||||
for (const u of users) {
|
||||
await prisma.user.upsert({
|
||||
where: { username: u.username },
|
||||
update: {
|
||||
id: u.id,
|
||||
slug: u.slug,
|
||||
displayName: u.displayName,
|
||||
},
|
||||
create: {
|
||||
id: u.id,
|
||||
username: u.username,
|
||||
slug: u.slug,
|
||||
displayName: u.displayName,
|
||||
},
|
||||
});
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`seeded user: ${u.username} (slug=${u.slug}, id=${u.id})`);
|
||||
}
|
||||
}
|
||||
|
||||
main()
|
||||
.then(async () => {
|
||||
await prisma.$disconnect();
|
||||
})
|
||||
.catch(async (err) => {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(err);
|
||||
await prisma.$disconnect();
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user