fix - modifications importantes
This commit is contained in:
1 parent
10e415e53e
commit
34700a46d9
14 files changed
+265
-321
No files matched your search
@@ -1,52 +0,0 @@
|
||||
// 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,
|
||||
codeActif: true,
|
||||
retrait: false
|
||||
}
|
||||
})
|
||||
|
||||
//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}`)
|
||||
}
|
||||
|
||||
|
||||
+56
-1
@@ -11,7 +11,7 @@ export const userData: Prisma.UserCreateInput[] = [
|
||||
name: 'John',
|
||||
email: 'john@prisma.io',
|
||||
createdAt: new Date(),
|
||||
role: 'SELLER'
|
||||
role: 'USER'
|
||||
},
|
||||
{
|
||||
name: 'Mosse',
|
||||
@@ -19,4 +19,59 @@ export const userData: Prisma.UserCreateInput[] = [
|
||||
createdAt: new Date(),
|
||||
role: 'USER'
|
||||
},
|
||||
{
|
||||
name: 'doug',
|
||||
email: 'doug@prisma.io',
|
||||
createdAt: new Date(),
|
||||
role: 'USER'
|
||||
},
|
||||
{
|
||||
name: 'molda',
|
||||
email: 'molda@prisma.io',
|
||||
createdAt: new Date(),
|
||||
role: 'USER'
|
||||
},
|
||||
{
|
||||
name: 'pierro',
|
||||
email: 'pierro@prisma.io',
|
||||
createdAt: new Date(),
|
||||
role: 'USER'
|
||||
},
|
||||
{
|
||||
name: 'brian',
|
||||
email: 'brian@prisma.io',
|
||||
createdAt: new Date(),
|
||||
role: 'USER'
|
||||
},
|
||||
{
|
||||
name: 'benji',
|
||||
email: 'benji@prisma.io',
|
||||
createdAt: new Date(),
|
||||
role: 'USER'
|
||||
},
|
||||
{
|
||||
name: 'abdel',
|
||||
email: 'abdel@prisma.io',
|
||||
createdAt: new Date(),
|
||||
role: 'USER'
|
||||
},
|
||||
{
|
||||
name: 'guillaume',
|
||||
email: 'guillaume@prisma.io',
|
||||
createdAt: new Date(),
|
||||
role: 'USER'
|
||||
},
|
||||
{
|
||||
name: 'roger',
|
||||
email: 'roger@prisma.io',
|
||||
createdAt: new Date(),
|
||||
role: 'USER'
|
||||
},
|
||||
{
|
||||
name: 'jacko',
|
||||
email: 'jacko@prisma.io',
|
||||
createdAt: new Date(),
|
||||
role: 'USER'
|
||||
},
|
||||
|
||||
]
|
||||
Reference in new issue
Block a user