Compare commits
6 Commits
135f910c62
...
first-step
| Author | SHA1 | Date | |
|---|---|---|---|
| ba68ef4695 | |||
| fd688f2ff3 | |||
| 70ca3fc5de | |||
| d79ba35e1d | |||
| b60d656978 | |||
| 45431a523a |
6
.gitignore
vendored
6
.gitignore
vendored
@@ -51,3 +51,9 @@ docker-compose.override.yml
|
||||
coverage/
|
||||
.tmp/
|
||||
.cache/
|
||||
|
||||
/src/generated/prisma
|
||||
|
||||
/src/generated/prisma
|
||||
|
||||
/src/generated/prisma
|
||||
|
||||
2058
package-lock.json
generated
2058
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
25
package.json
25
package.json
@@ -1,32 +1,35 @@
|
||||
{
|
||||
"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",
|
||||
"@prisma/adapter-pg": "^7.6.0",
|
||||
"@prisma/client": "^7.6.0",
|
||||
"argon2": "^0.44.0",
|
||||
"fastify": "^5.8.4"
|
||||
"fastify": "^5.8.4",
|
||||
"fastify-plugin": "^5.1.0",
|
||||
"nodemailer": "^8.0.4",
|
||||
"pg": "^8.20.0",
|
||||
"zod": "^4.3.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^25.5.0",
|
||||
"prisma": "^7.5.0",
|
||||
"ts-node-dev": "^2.0.0",
|
||||
"@types/nodemailer": "^7.0.11",
|
||||
"prisma": "^7.6.0",
|
||||
"tsx": "^4.21.0",
|
||||
"typescript": "^6.0.2"
|
||||
}
|
||||
}
|
||||
|
||||
14
prisma.config.ts
Normal file
14
prisma.config.ts
Normal 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
44
prisma/schema.prisma
Normal 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
14
src/app.ts
Normal 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
24
src/plugins/prisma.ts
Normal 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
19
src/routes/users.ts
Normal 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
15
src/server.ts
Normal 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
7
src/types/fastify.d.ts
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
import { PrismaClient } from '../generated/prisma/client.js'
|
||||
|
||||
declare module 'fastify' {
|
||||
interface FastifyInstance {
|
||||
prisma: PrismaClient
|
||||
}
|
||||
}
|
||||
@@ -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"]
|
||||
}
|
||||
Reference in New Issue
Block a user