Skip to content

A repository containing the backend and server parts of a Software engineering project.

License

Notifications You must be signed in to change notification settings

Smart-House-Engineering/Backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Backend

The backend/server infrastructure ensures seamless communication between user interfaces and smart devices, utilizing Node.js with Express.js for server operations. It employs MongoDB for data storage, Socket.io for real-time updates, JWT for secure authentication, and thorough testing for reliability.

Run Locally

Clone the project

  git clone [email protected]:Smart-House-Engineering/Backend.git

Go to the project directory

  cd Backend

Install dependencies

  npm install

Create .env file in the root folder:

  • add PORT=5000
  • add database URI link
  • add secret key

Start the server

  npm run start

Running Tests

To run tests, run the following command

  npm run test

To run tests with coverage, run the following command

  npm run coverage

Tech Stack

Server:

  • Node.js
  • Express.js
  • Socket.io
  • MongoDB

Testing:

  • Jest
  • Supertest,
  • Mongodb-memory-server

License

MIT

API Reference

Set Up Routes

Smarthome Registration

Endpoint for adding the house/homeId to database. Done by the party that sets up the Smarthome.

  POST /api/smarthome/addhome
Parameter Type Description
homeId string Required. The smarthouse HomeId.git
Example Request Body:
{
  "homeId": "ExampleHomeId"
}

Owner Registration

Endpoint for adding the owner to homeId. Done by the party that sets up the Smarthome.

  POST /api/smarthome/registerOwner
Parameter Type Description
homeId string Required. The homeId of the registered house.
email string Required. The owner's email address.
password string Required. The owner's password.
Example Request Body:
{
  "email": "[email protected]",
  "password": "Example1",
  "homeId": "ExampleHomeId"
}

User Authentication Routes

Login

Endpoint for user login.

  POST /auth/login
Parameter Type Description
email string Required. The user's email address.
password string Required. The user's password.
Example Request Body:
{
  "email": "[email protected]",
  "password": "Example1"
}

Logout

Endpoint for user Logout.

  POST /auth/logout

No parameters are required for this endpoint.

Example Request Body:
// No request body required for logout

User Action Routes

Get Sensors

Endpoint for getting the sensor's data. Accessible for all users logged in.

  GET /api/modes/defaultMode

No parameters are required for this endpoint.

Example Request Body:
// No request body required for logout

Get Modes

Endpoint for getting the modes's data. Accessible for all users logged in.

  GET /api/modes/otherModes

No parameters are required for this endpoint.

Example Request Body:
// No request body required for logout

Update Sensors

Endpoint for updating the sensor data. Accessible for OWNER and TENANT. Only the sensors being updated need to be included in the request body.

  PUT /api/homeUser/defaultMode
Parameter Type Description
fan boolean Optional. Indicates the status of the smarthome fan.
RFan boolean Optional. Indicates the status of the smarthome RFan.
motion boolean Optional. Indicates the status of the motion sensor.
buzzer boolean Optional. Indicates the status of the buzzer.
relay boolean Optional. Indicates the status of the relay.
door number Optional. Indicates the status of the door sensor.
window number Optional. Indicates the status of the window sensor.
yellowLed number Optional. Indicates the status of the yellow LED.
gasSensor number Optional. Indicates the status of the gas sensor.
photocell number Optional. Indicates the status of the photocell sensor.
soilSensor number Optional. Indicates the status of the soil sensor.
steamSensor number Optional. Indicates the status of the steam sensor.
whiteLed boolean Optional. Indicates the status of the white LED.
button1 boolean Optional. Indicates the status of button 1.
button2 boolean Optional. Indicates the status of button 2.
lights boolean Optional. Indicates the status of the lights.
Example Request Body:
{
  "updatedDevices": {
    "fan": false,
    "door": 0,
    "window": 1,
    "yellowLed": 0
  }
}

Update Modes

Endpoint for updating the smarthouse modes. Accessible for OWNER and TENANT. Only the modes being updated need to be included in the request body.

  PUT /api/homeUser/otherModes
Parameter Type Description
emergency boolean Optional. Updates the status of the emergency mode.
Example Request Body:
{
  "updatedModes": {
    "emergency": true
  }
}

Add User

Endpoint for adding a new user to the smarthouse. Route is accessible only to the OWNER. Possible to add users with role: TENANT or EXTERNAL.

  POST /api/owner/addUser/
Parameter Type Description
newUserEmail string Required. The new user's email address.
newUserPassword string Required. The new user's password.
newUserRole string Required. The new user's password.
Example Request Body:
{
  "newUserEmail": "[email protected]",
  "newUserPassword": "Example1",
  "newUserRole": "TENANT"
}

Delete User

Endpoint for deleteing a user from the smarthouse. Route is accessible only to OWNER.

  DEL /api/owner/deleteUser/
Parameter Type Description
deleteUserEmail string Required. The to be deleted user's email address.
Example Request Body:
{
  "deleteUserEmail": "[email protected]"
}

Get User Data

Endpoint for getting the User's data. Accessible for all users logged in.

  GET /api/user/data

No parameters are required for this endpoint.

Example Request Body:
// No request body required for logout

Get All Members Data With HomeId

Endpoint for getting the users info, who have been added to a specific HomeId. Accessible for all users logged in.

  GET /api/user/allMembers

No parameters are required for this endpoint.

Example Request Body:
// No request body required for logout

Authors

About

A repository containing the backend and server parts of a Software engineering project.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published