add branch tout-savoir
This commit is contained in:
1 parent
a75221ba0f
commit
5d5adbdc35
150 files changed
+17747
No files matched your search
@@ -0,0 +1,101 @@
|
||||
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?
|
||||
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[]
|
||||
gain 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?
|
||||
produit Produit? @relation(fields: [produitId], references: [id])
|
||||
produitId Int?
|
||||
user User? @relation(fields: [userId], references: [id])
|
||||
userId Int?
|
||||
actif Boolean @default(true)
|
||||
}
|
||||
|
||||
model Produit {
|
||||
id Int @id @default(autoincrement())
|
||||
actif Boolean?
|
||||
nomProduit String?
|
||||
prixTtc Int?
|
||||
image String?
|
||||
description String?
|
||||
refGain Gain[]
|
||||
}
|
||||
|
||||
enum Role {
|
||||
USER
|
||||
ADMIN
|
||||
SUPERADMIN
|
||||
}
|
||||
|
||||
model VerificationToken {
|
||||
identifier String
|
||||
token String @unique
|
||||
expires DateTime
|
||||
|
||||
@@unique([identifier, token])
|
||||
@@map("verificationtokens")
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
// import prisma from '../lib/prisma'
|
||||
|
||||
import { generateGains } from './seed/gains'
|
||||
import { produitsData } from './seed/produits'
|
||||
// import { userData } from './seed/user'
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
async function main() {
|
||||
console.log(`Start seeding ...`)
|
||||
|
||||
//création des tickets restants
|
||||
const tickets = await prisma.ticketsRestants.create({
|
||||
data: {
|
||||
total: 1500000
|
||||
},
|
||||
})
|
||||
console.log(`Created ticket: ${tickets.total}`)
|
||||
|
||||
|
||||
//création des produits
|
||||
for (const p of produitsData) {
|
||||
const produit = await prisma.produit.create({
|
||||
data: p,
|
||||
})
|
||||
console.log(`Created produit: ${produit.nomProduit}`)
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
//création des utilisateurs
|
||||
// for (const u of userData) {
|
||||
// const user = await prisma.user.create({
|
||||
// data: u,
|
||||
// })
|
||||
// console.log(`Created user with id: ${user.id}`)
|
||||
// }
|
||||
|
||||
//création de 5 gains
|
||||
for (let i = 1; i <= 5; i++) {
|
||||
await generateGains();
|
||||
}
|
||||
|
||||
console.log(`Seeding finished.`)
|
||||
}
|
||||
|
||||
|
||||
main()
|
||||
.then(async () => {
|
||||
await prisma.$disconnect()
|
||||
})
|
||||
.catch(async (e) => {
|
||||
console.error(e)
|
||||
await prisma.$disconnect()
|
||||
process.exit(1)
|
||||
})
|
||||
@@ -0,0 +1,50 @@
|
||||
// import { produits } from './produits';
|
||||
import prisma from '../../lib/prisma'
|
||||
import { Chance } from 'chance'
|
||||
import { Cadeaux } from '../../enum/cadeaux.enum';
|
||||
import cryptoRandomString from 'crypto-random-string';
|
||||
let chance = new Chance();
|
||||
|
||||
export const generateGains = async () => {
|
||||
//génération d'un code cadeau
|
||||
const randomNoGain = cryptoRandomString({ length: 10, type: 'distinguishable' });
|
||||
|
||||
//création d'un gain
|
||||
const gainCreated = await prisma.gain.create({
|
||||
data: {
|
||||
codeCadeau: randomNoGain,
|
||||
}
|
||||
})
|
||||
|
||||
//crétion d'un id de produit de façon pondérée
|
||||
let weightedRandomGain = chance.weighted([
|
||||
Cadeaux.GrandCoffretDecouverte,
|
||||
Cadeaux.CoffretDecouverte,
|
||||
Cadeaux.TheSignature,
|
||||
Cadeaux.TheDetox,
|
||||
Cadeaux.Infuseur],
|
||||
[4, 6, 10, 20, 60]);
|
||||
|
||||
//mise à jour du gain avec l'id de produit pondéré
|
||||
const gainUpdated = await prisma.gain.update({
|
||||
where: { id: gainCreated.id },
|
||||
data: {
|
||||
produitId: weightedRandomGain,
|
||||
}
|
||||
})
|
||||
//on retire 1 ticket
|
||||
await prisma.ticketsRestants.update({
|
||||
where: {
|
||||
id: 1
|
||||
},
|
||||
data: {
|
||||
total: {
|
||||
decrement: 1
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
console.log(`Created gain ! : ${gainUpdated.codeCadeau}`)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import { Prisma } from "@prisma/client";
|
||||
|
||||
export const produitsData: Prisma.ProduitCreateInput[] = [
|
||||
{
|
||||
nomProduit: 'Grand coffret découverte',
|
||||
prixTtc: 69,
|
||||
image: '/images/coffret-degustation.webp',
|
||||
description: "Une version XXL de notre fameux coffret découverte. Faites découvrir à vos invités leur saveur de thé préféré !"
|
||||
},
|
||||
{
|
||||
nomProduit: 'Coffret découverte',
|
||||
prixTtc: 39,
|
||||
image: '/images/coffret-degustation2.webp',
|
||||
description: "Ce coffret élégant vous permettra de découvrir les différentes saveurs de la gamme de Thé Tip Top. Offrez à votre palais de nouveaux horizons de saveurs. Découvrez avec ce coffret votre parfum préféré !"
|
||||
},
|
||||
{
|
||||
nomProduit: 'Thé signature',
|
||||
prixTtc: 10,
|
||||
image: '/images/the-signature.webp',
|
||||
description: "Le grand incontournable de notre gamme, le thé signature représente ce que Thé Tip Top souhaite vous transmettre : plus qu'un goût subtil et savoureux, c'est une expérience de saveur qui s'ouvre à vous !"
|
||||
},
|
||||
{
|
||||
nomProduit: 'Thé détox',
|
||||
prixTtc: 6,
|
||||
image: '/images/the-detox.webp',
|
||||
description: "Notre thé détox soutient l’élimination des déchets et purifie le corps des toxines accumulées. Il lutte contre la rétention d’eau. Pour chasser les toxines, il n’y a pas mieux !"
|
||||
},
|
||||
{
|
||||
nomProduit: 'Infuseur à thé',
|
||||
prixTtc: 3,
|
||||
image: '/images/infuseur.webp',
|
||||
description: "Préparer un bon thé chaud ou glacé de façon rapide et ludique. Profiter d'une infusion parfaite : L’infuseur permet aux feuilles de thé de se déployer librement, pleinement et de libérer ainsi toutes les molécules aromatiques au contact de l’eau. "
|
||||
}]
|
||||
@@ -0,0 +1,47 @@
|
||||
import { Prisma } from "@prisma/client";
|
||||
|
||||
export const userData: Prisma.UserCreateInput[] = [
|
||||
{
|
||||
name: 'Alice',
|
||||
email: 'alice@prisma.io',
|
||||
posts: {
|
||||
create: [
|
||||
{
|
||||
title: 'Join the Prisma Slack',
|
||||
content: 'https://slack.prisma.io',
|
||||
published: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Nilu',
|
||||
email: 'nilu@prisma.io',
|
||||
posts: {
|
||||
create: [
|
||||
{
|
||||
title: 'Follow Prisma on Twitter',
|
||||
content: 'https://www.twitter.com/prisma',
|
||||
published: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Mahmoud',
|
||||
email: 'mahmoud@prisma.io',
|
||||
posts: {
|
||||
create: [
|
||||
{
|
||||
title: 'Ask a question about Prisma on GitHub',
|
||||
content: 'https://www.github.com/prisma/prisma/discussions',
|
||||
published: true,
|
||||
},
|
||||
{
|
||||
title: 'Prisma on YouTube',
|
||||
content: 'https://pris.ly/youtube',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
Reference in new issue
Block a user