✅add : correction ajout de gain et api test code

This commit is contained in:
eric committed 2022-11-28 18:26:24 +01:00
1 parent 04423aa6c7
commit fec63499c6
16 files changed
+339 -83

No files matched your search

@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Gain" ADD COLUMN "disponible" BOOLEAN NOT NULL DEFAULT true;
@@ -0,0 +1,9 @@
/*
Warnings:
- You are about to drop the column `disponible` on the `Gain` table. All the data in the column will be lost.
*/
-- AlterTable
ALTER TABLE "Gain" DROP COLUMN "disponible",
ADD COLUMN "actif" BOOLEAN NOT NULL DEFAULT true;
+1
View File
@@ -86,6 +86,7 @@ model Gain {
produitId Int?
user User? @relation(fields: [userId], references: [id])
userId Int? @unique
actif Boolean @default(true)
}
model Produit {
+2 -1
View File
@@ -1,5 +1,6 @@
import { PrismaClient } from '@prisma/client';
// import prisma from '../lib/prisma'
import { PrismaClient } from '@prisma/client'
import { generateGains } from './seed/gains'
import { produitsData } from './seed/produits'
// import { userData } from './seed/user'
+3 -1
View File
@@ -2,11 +2,12 @@
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 = (Math.random() + 1).toString(36).substring(7).toUpperCase()
const randomNoGain = cryptoRandomString({ length: 10, type: 'distinguishable' });
//création d'un gain
const gainCreated = await prisma.gain.create({
@@ -46,3 +47,4 @@ export const generateGains = async () => {
console.log(`Created gain ! : ${gainUpdated.codeCadeau}`)
}