feat(backend): add fastify api, auth, prisma schema and jobs

This commit is contained in:
Anton
2026-04-23 16:04:44 +03:00
parent 5f6a551b6c
commit 2972090c48
34 changed files with 1313 additions and 0 deletions

View 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])
}