commit
6884518f1e
@ -0,0 +1,3 @@
|
|||||||
|
node_modules/
|
||||||
|
dist/
|
||||||
|
*.env*
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"workbench.colorCustomizations": {
|
||||||
|
"activityBar.background": "#43252A",
|
||||||
|
"titleBar.activeBackground": "#5E333B",
|
||||||
|
"titleBar.activeForeground": "#FCF9FA"
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,12 @@
|
|||||||
|
# API Gain
|
||||||
|
|
||||||
|
Api Gain - The Tip Top
|
||||||
|
|
||||||
|
## Getting started
|
||||||
|
|
||||||
|
Install npm dependencies:
|
||||||
|
|
||||||
|
```
|
||||||
|
npm install
|
||||||
|
```
|
||||||
|
|
||||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"name": "rest-express",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"license": "MIT",
|
||||||
|
"scripts": {
|
||||||
|
"dev": "ts-node src/index.ts"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@prisma/client": "4.7.1",
|
||||||
|
"dotenv": "^16.0.3",
|
||||||
|
"express": "4.18.2"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/express": "4.17.14",
|
||||||
|
"@types/node": "18.11.12",
|
||||||
|
"nodemon": "^2.0.20",
|
||||||
|
"prisma": "4.7.1",
|
||||||
|
"ts-node": "10.9.1",
|
||||||
|
"typescript": "4.9.4"
|
||||||
|
},
|
||||||
|
"prisma": {
|
||||||
|
"seed": "ts-node prisma/seed.ts"
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,104 @@
|
|||||||
|
generator client {
|
||||||
|
provider = "prisma-client-js"
|
||||||
|
}
|
||||||
|
|
||||||
|
datasource db {
|
||||||
|
provider = "postgresql"
|
||||||
|
url = env("DATABASE_URL")
|
||||||
|
}
|
||||||
|
|
||||||
|
model Account {
|
||||||
|
id Int @id @default(autoincrement())
|
||||||
|
userId Int @map("user_id")
|
||||||
|
type String
|
||||||
|
provider String
|
||||||
|
providerAccountId String @map("provider_account_id")
|
||||||
|
refresh_token String?
|
||||||
|
access_token String?
|
||||||
|
expires_at Int?
|
||||||
|
token_type String?
|
||||||
|
scope String?
|
||||||
|
id_token String?
|
||||||
|
session_state String?
|
||||||
|
oauth_token_secret String?
|
||||||
|
oauth_token String?
|
||||||
|
|
||||||
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||||
|
|
||||||
|
@@unique([provider, providerAccountId])
|
||||||
|
@@map("accounts")
|
||||||
|
}
|
||||||
|
|
||||||
|
model Session {
|
||||||
|
id Int @id @default(autoincrement())
|
||||||
|
sessionToken String @unique @map("session_token")
|
||||||
|
userId Int @map("user_id")
|
||||||
|
expires DateTime
|
||||||
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||||
|
|
||||||
|
@@map("sessions")
|
||||||
|
}
|
||||||
|
|
||||||
|
model User {
|
||||||
|
id Int @id @default(autoincrement())
|
||||||
|
name String?
|
||||||
|
surname String?
|
||||||
|
address String?
|
||||||
|
zipCode Int?
|
||||||
|
isBigWinner Boolean?
|
||||||
|
phoneNumber Int?
|
||||||
|
email String? @unique
|
||||||
|
emailVerified DateTime? @map("email_verified")
|
||||||
|
image String?
|
||||||
|
createdAt DateTime @default(now()) @map(name: "created_at")
|
||||||
|
updatedAt DateTime @updatedAt @map(name: "updated_at")
|
||||||
|
accounts Account[]
|
||||||
|
sessions Session[]
|
||||||
|
gains Gain[]
|
||||||
|
role Role @default(USER)
|
||||||
|
|
||||||
|
@@map(name: "users")
|
||||||
|
}
|
||||||
|
|
||||||
|
model TicketsRestants {
|
||||||
|
id Int @id @default(autoincrement())
|
||||||
|
total Int
|
||||||
|
}
|
||||||
|
|
||||||
|
model Gain {
|
||||||
|
id Int @id @default(autoincrement())
|
||||||
|
codeCadeau String @unique
|
||||||
|
dateRetrait DateTime?
|
||||||
|
dateAchat DateTime?
|
||||||
|
produit Produit? @relation(fields: [produitId], references: [id])
|
||||||
|
produitId Int?
|
||||||
|
user User? @relation(fields: [userId], references: [id])
|
||||||
|
userId Int?
|
||||||
|
codeActif Boolean @default(true)
|
||||||
|
retrait Boolean @default(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
model Produit {
|
||||||
|
id Int @id @default(autoincrement())
|
||||||
|
nomProduit String?
|
||||||
|
prixTtc Int?
|
||||||
|
image String?
|
||||||
|
description String?
|
||||||
|
refGain Gain[]
|
||||||
|
}
|
||||||
|
|
||||||
|
enum Role {
|
||||||
|
USER
|
||||||
|
SELLER
|
||||||
|
ADMIN
|
||||||
|
SUPERADMIN
|
||||||
|
}
|
||||||
|
|
||||||
|
model VerificationToken {
|
||||||
|
identifier String
|
||||||
|
token String @unique
|
||||||
|
expires DateTime
|
||||||
|
|
||||||
|
@@unique([identifier, token])
|
||||||
|
@@map("verificationtokens")
|
||||||
|
}
|
||||||
@ -0,0 +1,41 @@
|
|||||||
|
import { Gain, Prisma, PrismaClient } from '@prisma/client'
|
||||||
|
import express from 'express'
|
||||||
|
import dotenv from 'dotenv'
|
||||||
|
|
||||||
|
//chargement des variables d'environnement
|
||||||
|
dotenv.config()
|
||||||
|
|
||||||
|
//instance du client prisma
|
||||||
|
const prisma = new PrismaClient()
|
||||||
|
|
||||||
|
//déclaration de l'application express
|
||||||
|
const app = express()
|
||||||
|
|
||||||
|
app.use(express.json())
|
||||||
|
const PORT = process.env.NODE_DOCKER_PORT || 8990;
|
||||||
|
|
||||||
|
app.get('/feed', async (req, res) => {
|
||||||
|
|
||||||
|
try {
|
||||||
|
//selectionne un code gain de façon aléatoire
|
||||||
|
const randomGain: Gain[] = await prisma.$queryRawUnsafe(
|
||||||
|
`SELECT * FROM public."Gain" WHERE "dateAchat" IS NULL ORDER BY RANDOM() LIMIT 1;`,
|
||||||
|
)
|
||||||
|
|
||||||
|
//met à jour la date d'achat du gain séléctionné
|
||||||
|
const updatedGain: Gain = await prisma.gain.update({
|
||||||
|
where: {
|
||||||
|
id: randomGain[0].id,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
dateAchat: new Date(),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
res.json({ message: 'Emission de numero sur un ticket', number: updatedGain.codeCadeau, date: updatedGain.dateAchat })
|
||||||
|
} catch (error) {
|
||||||
|
console.log('oups!', error)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
app.listen(PORT, () => console.log(`🚀 Server ready at PORT : ${PORT}`),
|
||||||
|
)
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"sourceMap": true,
|
||||||
|
"outDir": "dist",
|
||||||
|
"strict": true,
|
||||||
|
"lib": ["esnext"],
|
||||||
|
"esModuleInterop": true
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in new issue