CRUD recette avec Swagger
$ npm install
# lancer volume DB
$ docker-compose up -d
# developpement
$ npm run start
# watch mode dev
$ npm run start:dev
# production mode
$ npm run start:prod
- Prérequis
Si NESTCLI non installé
$ npm i -g @nestjs/cli
- Création du project
$ nest new recipe
- Création volume DB Docker
$ touch docker-compose.yml
- Compose Up du file
$ docker-compose up -d
# pour stopper
$ docker-compose down
- Setup Prisma
$ npm install prisma -D
# init primsam
$ npx prisma init
- Set variable Environnement
- Une fois modele créer migrer la DB
$ npx prisma migrate dev --name init
- (Optionnel) creer une seed
$ touch prisma/seed.ts
# dans le fichier
import { PrismaClient } from '@prisma/client';
// initialize Prisma Client
const prisma = new PrismaClient();
async function main() {
// create two dummy recipes
const recipe1 = await prisma.recipe.upsert({
where: { title: 'Spaghetti Bolognese' },
update: {},
create: {
title: 'Spaghetti Bolognese',
description: 'A classic Italian dish',
ingredients:
'Spaghetti, minced beef,
tomato sauce, onions, garlic, olive oil, salt, pepper',
instructions:
'1. Cook the spaghetti. 2. Fry the minced beef. 3.
Add the tomato sauce to the beef.
4. Serve the spaghetti with the sauce.'
}
});
const recipe2 = await prisma.recipe.upsert({
where: { title: 'Chicken Curry' },
update: {},
create: {
title: 'Chicken Curry',
description: 'A spicy Indian dish',
ingredients:
'Chicken, curry powder, onions, garlic,
coconut milk, olive oil, salt, pepper',
instructions:
'1. Fry the chicken. 2. Add the curry powder to the
chicken. 3. Add the coconut milk.
4. Serve the curry with rice.'
}
});
console.log({ recipe1, recipe2 });
}
// execute the main function
main()
.catch(e => {
console.error(e);
process.exit(1);
})
.finally(async () => {
// close Prisma Client at the end
await prisma.$disconnect();
});
# package.json
"prisma": {
"seed": "ts-node prisma/seed.ts"
}
# puis
npx prisma db seed