Code Monkey home page Code Monkey logo

embeddedsystem_backend's Introduction

Backend For Embedded System

Backend Server made with express and mongoose for use in Embedded System.

How to Use

To use this repository, clone this repo into your machine

git clone https://github.com/ando-hunterz/EmbeddedSystem_Backend.git

then use your default npm install to install the required modules

npm install

after installing check the env required by find which process use .env, then make the .env file by using command

touch .env
vi .env
or
nano .env

use command to start the server

npm start

API Function

Auth Endpoint

Used for user related usage

Login

login the user

  • URL /api/auth/login

  • Method POST

  • Data Params

    {
      username: username,
      password: password
    }
  • Success Response
    Status Code : 200
    Content:

    {
      db_id: database_id, 
      jwtToken: jwtToken
    }
  • Error Response
    Status Code: 400
    Content:

    { 
      messages: [message], 
      fields: [error_fields] 
    }

Logging User Endpoint

Used for logging user from NodeMCU

Log User

Logging User to database

  • URL /api/userlog/:db_id

  • Method POST

  • URL Params db_id=database_name

  • Data Params

    {
      uid: uid,
      temperature: temperature,
      status: "Ok"/"Warning"
    }
  • Success Response
    Status Code : 200
    Content:

    {
      message: "User Submitted", 
      user: {
        _id: id,
        uid: uid,
        temperature: temperature,
        status: "Ok"/"Warning",
        createdAt: createDate,
        updatedAt: updateDate,
        __v: 0,
        id: id
      }
    }
  • Error Response
    Status Code: 400
    Content:

    { 
      messages: [message], 
      fields: [error_fields] 
    }

User Endpoint

User endpoint to access database

Get Records

Get all records of users who has logged.

  • URL /api/user/records

  • Method GET

  • URL Params None

  • Cookie Params db_id

  • Success Response
    Status Code : 200
    Content:

    [
      {
        _id: id,
        uid: uid,
        temperature: temperature,
        status: "Ok"/"Warning",
        createdAt: CreatedDate,
        userData: {
            _id: id,
            uid: uid,
            name: name,
            id: id
        },
        id: id
      },
    ]

Get User Record

Get record of user who has logged.

  • URL /api/user/records/:id

  • Method GET

  • URL Params id=[user_id]

  • Cookie Params db_id

  • Success Response
    Status Code : 200
    Content:

    {
      _id: id,
      uid: uid,
      temperature: temperature,
      status: "Ok"/"Warning",
      createdAt: CreatedDate,
      userData: {
          _id: id,
          uid: uid,
          name: name,
          id: id
          },
      id: id
      },
    • Error Response
      Status Code: 400
      Content:
    { 
      messages: [message], 
      fields: [error_fields] 
    }

Update Record

Update selected record of user who has logged.

  • URL /api/user/record/:id

  • Method PATCH

  • URL Params id=[user_id]

  • Data Params

    {
      uid: uid
    }

    OR

    {
      temperature: temperature
    } 

    OR

    {
      uid: uid,
      temperature: temperature
    }
  • Cookie Params db_id

  • Success Response
    Status Code : 200
    Content:

    { 
      _id: id,
      uid: uid,
      temperature: temperature,
      status: "OK"/"Warning",
      createdAt: CreatedDate,
      updatedAt: UpdatedDate,
      __v: 0,
      id: id
    }
  • Error Response
    Status Code: 400
    Content:

    { 
      messages: [message], 
      fields: [error_fields] 
    }

Delete Record

Delete records of user who has logged.

  • URL /api/user/record/:id

  • Method DELETE

  • URL Params id=[user_id]

  • Cookie Params db_id

  • Success Response
    Status Code : 200
    Content:

    {
      message: "Record with id user_id has been deleted"
    }
  • Error Response
    Status Code: 400
    Content:

    { 
      messages: [message], 
      fields: [error_fields] 
    }

UserData Endpoint

User endpoint to access userData database collection

Get UserData

Get userData which has been uploaded to database via csv file

  • URL /api/user/userData

  • Method GET

  • Cookie Params db_id

  • Success Response
    Status Code : 200
    Content:

    [
      {
      _id: id,
      uid: uid,
      name: name,
      __v: 0,
      createdAt: CreatedDate,
      updatedAt: UpdatedDate,
      id: id
      }
    ]
  • Error Response
    Status Code: 400
    Content:

    { 
      messages: [message], 
      fields: [error_fields] 
    }

Post UserData

Post userData with CSV files

  • URL /api/user/userData

  • Method POST

  • Data Params .csv file with structure as following

    uid name
    user_uid user_name
  • Cookie Params db_id

  • Success Response
    Status Code : 200
    Content:

    [
      {
      _id: id,
      uid: uid,
      name: name,
      __v: 0,
      createdAt: CreatedDate,
      updatedAt: UpdatedDate,
      id: id
      }
    ]
  • Error Response
    Status Code: 400
    Content:

    { 
      messages: [message], 
      fields: [error_fields] 
    }

Update UserData

Update userData which has been uploaded to database via csv file

  • URL /api/user/userData/:id

  • Method PATCH

  • Cookie Params db_id

  • Data params

    {
      uid: uid
    }

    OR

    {
      name: name
    }

    OR

    {
      uid: uid,
      name: name
    }
  • Success Response
    Status Code : 200
    Content:

    {
      _id: id,
      uid: uid,
      name: name,
      __v: 0,
      createdAt: CreatedDate,
      updatedAt: UpdatedDate,
      id: id
    }
  • Error Response
    Status Code: 400
    Content:

    { 
      messages: [message], 
      fields: [error_fields] 
    }

Delete UserData

Delete userData which has been uploaded to database via csv file

  • URL /api/user/userData/:id

  • Method DELETE

  • Cookie Params db_id

  • Success Response
    Status Code : 200
    Content:

    { 
      message: `User with id ${userId} deleted`
    }
  • Error Response
    Status Code: 400
    Content:

    { 
      messages: [message], 
      fields: [error_fields] 
    }

-- Endpoint is WIP --

TODO

  • Error Endpoint for Delete Record

  • User Data return message and code

  • Delete user JSON response

  • Search Endpoint

  • JWT Verification

  • Function and Route documentation

  • Websocket Emit Event message

  • POST userData Error

embeddedsystem_backend's People

Contributors

ando-hunterz avatar axelpat avatar minorvafalk 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.