Skip to content

Jimmyganci/moncarnet-backend

Repository files navigation

moncarnet-backend

npm install

copy ".env.sample" file and add your mysql login

Don't forget to add port for localhost

import the reset-db

Restart your IDE

Use reset-data.sql to your console sql

make npm start to the console for launch the server.

npm start

Connection

ADMIN

email:[email protected] password: JimmyGanci

PARTICULIER

email: [email protected] password: BastienT

PROS

email:[email protected] password:autorepare24

Upload files

//Upload one files on route vehicule, users or pros//

.post("api/vehicules/upload")
.post("api/users/upload")
.post("api/pros/upload")

Result data : https://"your_host_minio"/"your_bucket_minio"//invoice//your_files_name.png

Example client:

const handleUpload = async (e) => {
    e.preventDefault();
    const formData = new FormData();
    formData.append("file", file);
    const upload = await axios.post(
      "http://localhost:8000/api/vehicules/upload",
      formData,
      { withCredentials: true }
    );
    console.log(upload);
    if (upload) {
      const postVehicule = await axios.post(
        "http://localhost:8000/api/vehicules/",
        {
          immat: immat,
          registration_date: "2015-10-21T00:00:00.000Z",
          url_vehiculeRegistration: upload.data,
          id_modelId: parseInt(model),
          id_typeId: parseInt(type),
          id_userId: parseInt(user),
        },
        {
          withCredentials: true,
        }
      );
      console.log(postVehicule.data);
    }
  };

Vehicule

// Get all vehicules //

.get("/api/vehicules/all")

Results

[
{
"immat": "CL-940-TE",
"registration_date": "2007-10-21T00:00:00.000Z",
"model_id_model": 5,
"user_id_user": 2,
"types_id_type": 2,
"url_vehiculeRegistration": ""
},
{
"immat": "CL-950-TE",
"registration_date": "2012-10-30T00:00:00.000Z",
"model_id_model": 1,
"user_id_user": 1,
"types_id_type": 1,
"url_vehiculeRegistration": ""
},
{
"immat": "CP-900-TE",
"registration_date": "2016-10-30T00:00:00.000Z",
"model_id_model": 2,
"user_id_user": 2,
"types_id_type": 1,
"url_vehiculeRegistration": ""
},
{
"immat": "ML-967-TT",
"registration_date": "2021-10-21T00:00:00.000Z",
"model_id_model": 300,
"user_id_user": 1,
"types_id_type": 1,
"url_vehiculeRegistration": ""
}
]

//Get one vehicule//

.get("/api/vehicules/:immat)
.get("/api/vehicules/CL-940-TE)

Results :

{
"immat": "CL-940-TE",
"registration_date": "2007-10-21T00:00:00.000Z",
"model_id_model": 5,
"user_id_user": 2,
"types_id_type": 2,
"url_vehiculeRegistration": ""
}

//Get user's vehicule//

.get("/api/vehicules/user/:idUser)
.get("/api/vehicules/user/2)

//Get model's vehicule//

.get("/api/vehicules/:immat/model)
.get("/api/vehicules/HY-567-HY/model)

Results :

{
"id_model": 5,
"code": "3.2CL",
"name": " - 3.2CL",
"id_brand": 1
}

//Get brand's vehicule//

.get("/api/vehicules/:immat/brand)
.get("/api/vehicules/HY-678-HY/brand)

Results:

{
"id_brand": 1,
"code": "ACURA",
"name": "Acura"
}

//Post vehicule//

.post("/api/vehicules")

//Put vehicules//

.put("api/vehicule/:id)

//Delete vehicules//

.delete("api/vehicule/:id)

Users

//Get all users//

get("api/users/all")

Results:

{
        "id_user": 1,
        "firstname": "Buddy",
        "lastname": "Cadet",
        "email": "[email protected]",
        "hashedPassword": "$argon2id$v=19$m=65536,t=5,p=1$IaW4RanaMVmzJt4tbipbBQ$LzRQanarVEivgJMXXJO2uhlNrhVe89rRLNlvyL0UDf4",
        "address": "Angresse",
        "phone": "06-78-76-78-76",
        "postal_code": 40000,
        "city": "Angresse"
    },
    {
        "id_user": 2,
        "firstname": "Buddy",
        "lastname": "Ganci",
        "email": "[email protected]",
        "hashedPassword": "$argon2id$v=19$m=65536,t=5,p=1$KcDNxFFRs2+0CQTCSCjalQ$7eEVEdmO0HZUWZPXzV5Zq5mRHAEhS/YkkZQxG0GphHg",
        "address": "rue de la croquette",
        "phone": "06-78-76-78-76",
        "postal_code": 40130,
        "city": "Capbreton"
    },
    {
        "id_user": 3,
        "firstname": "mika",
        "lastname": "dut",
        "email": "[email protected]",
        "hashedPassword": "$argon2id$v=19$m=65536,t=5,p=1$Sq9xsyQtq+xLrjR/vJIsnQ$KgSIEqAUA+ljIs8lbE8fklCVNWj1XLAIWJJMPhEDQ44",
        "address": "rue de la grotte",
        "phone": "06-78-76-78-76",
        "postal_code": 93000,
        "city": "Paris"
    },

//Get one user//

.get("api/users/:id")
.get("/api/users/2")

Results:

{
    "id_user": 2,
    "firstname": "Buddy",
    "lastname": "Ganci",
    "email": "[email protected]",
    "hashedPassword": "$argon2id$v=19$m=65536,t=5,p=1$KcDNxFFRs2+0CQTCSCjalQ$7eEVEdmO0HZUWZPXzV5Zq5mRHAEhS/YkkZQxG0GphHg",
    "address": "rue de la croquette",
    "phone": "06-78-76-78-76",
    "postal_code": 40130,
    "city": "Capbreton"
}

//Get vehicule's user//

.get("api/users/vehicule/:idBrand")
.get("/api/users/vehicules/1")

Results:

{
    {
        "immat": "MM-967-TT",
        "registration_date": "2021-10-21T00:00:00.000Z",
        "model_id_model": 100,
        "user_id_user": 1,
        "types_id_type": 1,
        "url_vehiculeRegistration": ""
    },
    {
        "immat": "MZ-877-UU",
        "registration_date": "2005-10-21T00:00:00.000Z",
        "model_id_model": 100,
        "user_id_user": 1,
        "types_id_type": 1,
        "url_vehiculeRegistration": ""
    }
}

//Get pro's user//

.get("api/users/pros/:idUser")
.get("/api/users/pros/1")

Results:

{
    []
}

//Delete users's pros//

.get("api/users/:idUser/prosDeleted/:idPros")
.get("/api/users/2/prosDeleted/1")

Results:

{
    []
}

//Get user by lastname//

.get("api/users/all?lastname=?")
.get("/api/users/all?lastname=cade")

Results:

{
     {
        "id_user": 1,
        "firstname": "Buddy",
        "lastname": "Cadet",
        "email": "[email protected]",
        "hashedPassword": "$argon2id$v=19$m=65536,t=5,p=1$BAySd1UMW6s38RbnPUjlgA$MQyZYxKXX1H379J9jbOKz7p0Lh43T1SbbWtLYPaAIVU",
        "address": "Angresse",
        "phone": "06-78-76-78-76",
        "postal_code": 40000,
        "city": "Angresse"
    }
}

//Get user by postal code//

.get("api/users/all?postal_code=?")
.get("/api/users/all?postal_code=40130")

Results:

     {
        "id_user": 2,
        "firstname": "Buddy",
        "lastname": "Ganci",
        "email": "[email protected]",
        "hashedPassword": "$argon2id$v=19$m=65536,t=5,p=1$KcDNxFFRs2+0CQTCSCjalQ$7eEVEdmO0HZUWZPXzV5Zq5mRHAEhS/YkkZQxG0GphHg",
        "address": "rue de la croquette",
        "phone": "06-78-76-78-76",
        "postal_code": 40130,
        "city": "Capbreton"
    }

//Get user by city//

.get("api/users/all?city=?")
.get("/api/users/all?city=cap")

Results:

     {
        "id_user": 2,
        "firstname": "Buddy",
        "lastname": "Ganci",
        "email": "[email protected]",
        "hashedPassword": "$argon2id$v=19$m=65536,t=5,p=1$KcDNxFFRs2+0CQTCSCjalQ$7eEVEdmO0HZUWZPXzV5Zq5mRHAEhS/YkkZQxG0GphHg",
        "address": "rue de la croquette",
        "phone": "06-78-76-78-76",
        "postal_code": 40130,
        "city": "Capbreton"
    }

//Post user//

.get("api/users/")
.get("/api/users/")

Results:

     {
        "id_user": 10,
    "firstname": "matthieu",
    "lastname": "dubo",
    "email": "[email protected]",
    "hashedPassword": "$argon2id$v=19$m=65536,t=5,p=1$cOJ+Ee/IHuVXjBdmf828bg$kqeTBkm/N/NIwgFJE38giaVaW3sB67L2brD6hSLUCck",
    "address": "rue de la benne",
    "phone": "06-78-76-78-76",
    "postal_code": 40100,
    "city": "Saubrigue"
    }

//Add user's pro//

.get("api/users/pro/:idUser")
.get("/api/users/pro/4")

Results:

     {
        "id_pros": 1,
        "name": "Bernadin auto",
        "email": "[email protected]",
        "hashedPassword": "bon",
        "adress": "78 avenue du temps",
        "postal_code": 33130,
        "city": "Bordeaux",
        "siret": 76549864,
        "phone": "06-56-57-57-76"
    },
    {
        "id_pros": 2,
        "name": "auto",
        "email": "[email protected]",
        "hashedPassword": "bon",
        "adress": "78 avenue du temps",
        "postal_code": 33130,
        "city": "Bordeaux",
        "siret": 76549864,
        "phone": "06-56-57-57-76"
    }

//Put user//

.get("api/users/:idUser")
.get("/api/users/1")

Results:

     {
     "id_user": 1,
    "firstname": "Buddy",
    "lastname": "Cadet",
    "email": "[email protected]",
    "hashedPassword": "$argon2id$v=19$m=65536,t=5,p=1$BAySd1UMW6s38RbnPUjlgA$MQyZYxKXX1H379J9jbOKz7p0Lh43T1SbbWtLYPaAIVU",
    "address": "Angresse",
    "phone": "06-78-76-78-76",
    "postal_code": 40000,
    "city": "Angresse"
    }

//Delete user//

.get("api/users/:idUser")
.get("/api/users/1")

Results:

     "Buddy deleted"

Appointment

//Get all appointment//

.get("/api/appointment")

Results:

     [
    {
        "userId": 1,
        "prosId": 2,
        "date": "2022-03-01T00:00:00.000Z",
        "comment": "entretien 10000"
    },
    {
        "userId": 1,
        "prosId": 4,
        "date": "2022-03-01T00:00:00.000Z",
        "comment": "entretien 10000"
    }
]

//Get one appointment//

.get("/api/appointment/user/:userId/pros/prosId")
.get("/api/appointment/user/1/pros/4")

Results:

     {
    "userId": 1,
    "prosId": 4,
    "date": "2022-03-01T00:00:00.000Z",
    "comment": "entretien 10000"
}

//Get all users's appointment//

.get("/api/appointment/user/userId")
.get("/api/appointment/user/1")

Results:

     [
    {
        "id_pros": 2,
        "name": "Pneu123",
        "email": "[email protected]",
        "hashedPassword": "$argon2id$v=19$m=65536,t=5,p=1$0OZViyOU5ZO2c23P2lNAew$3KqrgZwFerxgsH7xkC1NXvK3GukRJfUpvhTnV4Wru2E",
        "address": "78 avenue du pneu",
        "postal_code": 40130,
        "city": "Capbreton",
        "siret": "23456545432334",
        "phone": "06-90-76-57-76"
    },
    {
        "id_pros": 4,
        "name": "Garage des Pins",
        "email": "[email protected]",
        "hashedPassword": "$argon2id$v=19$m=65536,t=5,p=1$UD6EO+ouPfx7JQyJjRIvow$1joKcpBw9bCupaGiR4Ge7CGl2xBp9Q/jb37ZdGccKdg",
        "address": "78 avenue des pins",
        "postal_code": 40130,
        "city": "Capbreton",
        "siret": "23456545432334",
        "phone": "06-90-76-57-76"
    }
]

//Get all pros's appointment//

.get("/api/appointment/pros/prosId")
.get("/api/appointment/pros/4")

Results:

    [
    {
        "id_user": 1,
        "firstname": "Buddy",
        "lastname": "Cadet",
        "email": "[email protected]",
        "hashedPassword": "$argon2id$v=19$m=65536,t=5,p=1$wQyXp/JtaEONYdoAFu31sA$oC+59EHM3yybccAS9mqtsPVMRZBHd91SiNCf7EGtLno",
        "address": "Angresse",
        "phone": "06-78-76-78-76",
        "postal_code": 40000,
        "city": "Angresse"
    }
]

//Post appointment//

.get("/api/appointment/pros")
.get("/api/appointment/pros")

Results:

   {
    "userId": 1,
    "prosId": 4,
    "date": "2022-03-01T00:00:00.000Z",
    "comment": "entretien 10000"
}

//Post appointment//

.get("/api/appointment/pros")
.get("/api/appointment/pros")

Results:

   {
    "userId": 1,
    "prosId": 4,
    "date": "2022-03-01T00:00:00.000Z",
    "comment": "entretien 10000"
}

//Delete one appointment//

.get("/api/appointment/user/1/pros/1")
.get("/api/appointment/user/userId/pros/prosId")

Results:

   Appointment of Tue Mar 01 2022 01:00:00 GMT+0100 (heure normale d’Europe centrale) with pros Id 1 deleted

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •