Skip to content

LionAB/RecipeCRUDNest

Repository files navigation

Nest Logo

Description

CRUD recette avec Swagger

Installation

$ npm install

Running the app

# lancer volume DB 
$ docker-compose up -d 
# developpement
$ npm run start

# watch mode dev
$ npm run start:dev

# production mode
$ npm run start:prod

Creation

  1. Prérequis

Si NESTCLI non installé

$ npm i -g @nestjs/cli
  1. Création du project
$ nest new recipe
  1. Création volume DB Docker
$ touch docker-compose.yml
  1. Compose Up du file
$ docker-compose up -d
# pour stopper
$ docker-compose down
  1. Setup Prisma
$ npm install prisma -D
# init primsam
$ npx prisma init
  1. Set variable Environnement
  2. Une fois modele créer migrer la DB
$ npx prisma migrate dev --name init
  1. (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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published