GithubHelp home page GithubHelp logo

js-crud's Introduction

Product & Inventory manager

                                         

Description

Inventory manager with the following functions:

  • Add a piece of clothing (name, size, description and price)
  • View inventory;
  • Update product price;
  • Delete product from database.

In this project was used the following tools:

  • JavaScript
  • React
  • NodeJs
  • mySQL

Along with the API's and Packages:

Steps

After download the code, run on terminal (in both folders):

npm install

Open backend folder and run:

npm install mysql express cors

To start the aplication

on frontend folder, run:

npm start

on backend folder, run:

node index.js

Function Overview

  • Insert function, will receive the data from fronend end send it to the backend.
//post requet, vai inserrir os dados no database
app.post('/create', (req, res) => { // rota ; font end -> back end
    //variáveis do front end
    /*
    const name = req.body.name;
    const num = req.body.num;
    const desc = req.body.desc;
    const price = req.body.price;
    */
    const { name, num, desc, price } = req.body;
    
    database.query('INSERT INTO produtos (`name`, `num`, `desc`, `price`) VALUES (?,?,?,?)', //insert
    [name, num, desc, price], (err, result) => { //verify
        if (err) {
            console.log(err);
        } else {
            res.send("inserido!");
        }
    }
);
});
  • Display function, will show on the screen the registeres product.
app.get('/estoque', (req, res) => {
    database.query('SELECT * FROM produtos', (err, result) =>{
        if (err) {
            console.log(err);
        } else {
            res.send(result);
        }
    });
});
  • Update function, will update the price on database.
app.put('/update', (req, res) => {
    const id = req.body.id;
    const price = req.body.price;
    database.query("UPDATE SET produtos price = ? WHERE id = ?", [price, id], (err, result) => {
        if (err) {
            console.log(err);
        } else {
            res.send(result);
        }
    });
});
  • Delete function.
app.delete('/delete/:id', (req, res) => {  //ID será acessível
    const id = req.params.id;
    database.query("DELETE FROM produtos WHERE id = ?", id, (err, result) => { // ? => recebe id
        if (err) {
            console.log(err);
        } else {
            res.send(result);
        }
    }); 
});

NOTICE after add a product, for a better usage of update & delete function, refresh page are require (F5).

Screenshot

Author

Átila de Freitas

                   

js-crud's People

Contributors

atiladefreitas avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.