Compare commits

...

4 Commits

Author SHA1 Message Date
70ca3fc5de plugin postgre database with prisma 2026-03-27 18:34:13 +01:00
d79ba35e1d initialisation de Fastify 2026-03-27 17:49:51 +01:00
b60d656978 restart from 0 2026-03-27 17:40:17 +01:00
45431a523a Mise en place du serveur de base 2026-03-26 20:51:00 +01:00
12 changed files with 1167 additions and 1126 deletions

6
.gitignore vendored
View File

@@ -51,3 +51,9 @@ docker-compose.override.yml
coverage/
.tmp/
.cache/
/src/generated/prisma
/src/generated/prisma
/src/generated/prisma

View File

2106
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,32 +1,31 @@
{
"name": "bo_liste",
"version": "1.0.0",
"description": "Back Office de l'application des listes",
"description": "BO pour la liste application",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "ts-node-dev --respawn --transpile-only src/core/server.ts",
"dev": "tsx src/server.ts",
"build": "tsc",
"start": "node dist/core/server.js",
"prisma:generate": "prisma generate",
"prisma:migrate": "prisma migrate dev"
"start": "node dist/server.js"
},
"repository": {
"type": "git",
"url": "git@gitea.raffiskender.com:raffi/bo_listes.git"
"url": "bo_liste"
},
"author": "Raffi",
"license": "ISC",
"dependencies": {
"@fastify/jwt": "^10.0.0",
"@prisma/client": "^7.5.0",
"argon2": "^0.44.0",
"fastify": "^5.8.4"
"@prisma/adapter-pg": "^7.6.0",
"@prisma/client": "^7.6.0",
"fastify": "^5.8.4",
"fastify-plugin": "^5.1.0",
"pg": "^8.20.0"
},
"devDependencies": {
"@types/node": "^25.5.0",
"prisma": "^7.5.0",
"ts-node-dev": "^2.0.0",
"prisma": "^7.6.0",
"tsx": "^4.21.0",
"typescript": "^6.0.2"
}
}

14
prisma.config.ts Normal file
View File

@@ -0,0 +1,14 @@
// This file was generated by Prisma, and assumes you have installed the following:
// npm install --save-dev prisma dotenv
import "dotenv/config";
import { defineConfig, env } from "prisma/config";
export default defineConfig({
schema: "prisma/schema.prisma",
migrations: {
path: "prisma/migrations",
},
datasource: {
url: env("DATABASE_URL"),
},
});

44
prisma/schema.prisma Normal file
View File

@@ -0,0 +1,44 @@
generator client {
provider = "prisma-client"
output = "../src/generated/prisma"
}
datasource db {
provider = "postgresql"
}
model ActionToken {
id String @id
userId String
token String @unique
type String
expiresAt DateTime
used Boolean @default(false)
createdAt DateTime @default(now())
User User @relation(fields: [userId], references: [id], onDelete: Cascade)
}
model AuthToken {
id String @id
userId String
token String @unique
expiresAt DateTime
createdAt DateTime @default(now())
revoked Boolean @default(false)
User User @relation(fields: [userId], references: [id], onDelete: Cascade)
}
model User {
id String @id
email String @unique
passwordHash String
displayName String
isConfirmed Boolean @default(false)
isGoogleUser Boolean @default(false)
avatar String
createdAt DateTime @default(now())
publicKey String?
encryptedPrivateKey String?
ActionToken ActionToken[]
AuthToken AuthToken[]
}

14
src/app.ts Normal file
View File

@@ -0,0 +1,14 @@
import Fastify from 'fastify'
import prismaPlugin from './plugins/prisma'
import userRoutes from './routes/users.js'
export default function buildApp() {
const app = Fastify({ logger: true })
app.register(prismaPlugin)
app.register(userRoutes, { prefix: '/api' })
app.get('/health', async () => ({ status: 'ok' }))
return app
}

24
src/plugins/prisma.ts Normal file
View File

@@ -0,0 +1,24 @@
import fp from 'fastify-plugin'
import { FastifyInstance } from 'fastify'
import { PrismaClient } from '../generated/prisma/client.js'
import { PrismaPg } from '@prisma/adapter-pg'
declare module 'fastify' {
interface FastifyInstance {
prisma: PrismaClient
}
}
export default fp(async (fastify: FastifyInstance) => {
const adapter = new PrismaPg({
connectionString: process.env.DATABASE_URL,
})
const prisma = new PrismaClient({ adapter })
fastify.decorate('prisma', prisma)
fastify.addHook('onClose', async () => {
await prisma.$disconnect()
})
})

19
src/routes/users.ts Normal file
View File

@@ -0,0 +1,19 @@
import { FastifyInstance } from 'fastify'
export default async function userRoutes(fastify: FastifyInstance) {
fastify.get('/users', async (request, reply) => {
const users = await fastify.prisma.user.findMany({
select: {
id: true,
email: true,
displayName: true,
isConfirmed: true,
isGoogleUser: true,
avatar: true,
createdAt: true,
},
})
return users
})
}

15
src/server.ts Normal file
View File

@@ -0,0 +1,15 @@
import 'dotenv/config'
import buildApp from './app.js'
const app = buildApp()
const start = async () => {
try {
await app.listen({ port: 1234, host: '0.0.0.0' })
} catch (err) {
app.log.error(err)
process.exit(1)
}
}
start()

7
src/types/fastify.d.ts vendored Normal file
View File

@@ -0,0 +1,7 @@
import { PrismaClient } from '../generated/prisma/client.js'
declare module 'fastify' {
interface FastifyInstance {
prisma: PrismaClient
}
}

View File

@@ -1,18 +1,15 @@
{
"compilerOptions": {
"rootDir": "./src",
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"outDir": "./dist",
"module": "CommonJS",
"target": "ES2020",
"types": ["node"],
"sourceMap": true,
"rootDir": "./src",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true
}
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
},
"include": ["src"],
"exclude": ["node_modules", "dist"]
}