You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
869 B
37 lines
869 B
|
|
import { Gain, Prisma, PrismaClient } from '@prisma/client'
|
|
|
|
import { Cadeaux } from '../enum/cadeaux.enum'
|
|
|
|
//instance du client prisma
|
|
const prisma = new PrismaClient()
|
|
|
|
|
|
export const makeGain = async (nbrGain: number, idProduit: number) => {
|
|
let generatedGains: any[] = [];
|
|
let code: string = '';
|
|
let i: number = 0;
|
|
|
|
//creation d'un nombre de gain
|
|
for (; i < nbrGain; i++) {
|
|
code = Array.from({ length: 10 }, () => Math.random().toString(36)[2]).join('').toUpperCase();
|
|
generatedGains.push({
|
|
codeActif: true,
|
|
retrait: false,
|
|
produitId: idProduit,
|
|
codeCadeau: code
|
|
})
|
|
|
|
console.log(`produit : ${Cadeaux[idProduit]}, n° : ${i}`)
|
|
}
|
|
|
|
|
|
|
|
|
|
const res = await prisma.gain.createMany({
|
|
data: generatedGains
|
|
})
|
|
|
|
console.log('YEYEEEEEEEEEEEEE', res);
|
|
}
|