Skip to content

Backend for Eldafriend app, A pal for the elder community! Track your medication, along with reminders and many showstopper features that ensure completely homely care.

Notifications You must be signed in to change notification settings

Zeref101/EldaFriend-backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Eldafriend-backend

  • Backend for Eldafriend app, A pal for the elder community! Track your medication, along with reminders and many showstopper features that ensure completely homely care.

End-Points:

To install dependencies:

bun install

To run:

bun run dev

User Authentication

GET /api/auth

Returns a greeting message.

POST /api/auth/sign-up/getOtp

Creates a new user and sends an OTP to their email.

Headers:

  • Content-Type: application/json

Request Body:

{
  "fullname": "John Doe",
  "email": "[email protected]",
  "password": "password123"
}

Sample Response:

  • If Phone number is not valid
{
  "message": "Phone number is not valid"
}
  • If Email already Exists
{
  "message": "Email already exists"
}
  • If Phone number already exists
{
  "message": "Phone number already exists"
}
  • If User is not added to the database due to internal server error
{
  "message": "User not created due to an Internal server error"
}
  • If OTP generated successfully
{
  "userId": "ufiabifahbigubapigbiua",
  "message": "An OTP has been successfully sent to your registered email address"
}
  • HTTP status codes: 201 for success, 400 for bad request, 404 for not found, 500 for internal server error.

POST /api/auth/sign-up/verify-otp

Verifies the OTP sent to the user's email.

Headers:

  • Content-Type: application/json

Request Body:

{
  "userId": "123",
  "otp": 459819
}

Sample Response:

  • Successful creation
{
  "message": "User created successfully"
}
  • Error while verifying the OTP
{
  "message": "User not created"
}
  • User enters wrong OTP
{
  "message": "Invalid OTP"
}
  • User enters the correct OTP
{
  "message": "User verified!"
}
  • HTTP status codes: 201 for success, 400 for bad request, 404 for not found, 500 for internal server error.

POST /api/auth/login

Logs in a user.

Headers:

  • Content-Type: application/json

Request Body:

{
  "email": "[email protected]",
  "password": "password123"
}

Sample Response:

  • Email doesn't exists in database
{
  "message": "User not found"
}
  • User types invalid password
{
  "message": "Invalid password"
}
  • If Email and password matches and the user exists in database
{
  "_id": "65e5e402368294524c92cc00"
}

GET /api/auth/user-details

Gets user details

Headers:

  • Content-Type: application/json
  • user-id: "dummyUserid123456789"

Response:

{
  "_id": "65e5e402368294524c92cc00",
  "fullname": "John",
  "phone": "+919999999999",
  "email": "[email protected]",
  "picture": null,
  "globalPin": 1234,
  "communities": [],
  "medicines": [],
  "expenses": [],
  "verified": true
}

Response status codes: 200: Successful retrieval of user details 404: User not found 422: Check headers/request body 500: Internal Server Error

Medicines

POST /api/user/create-med

Creates a new medicine for a user.

Headers:

  • Content-Type: application/json

Request Body:

{
  "userId": "123",
  "dosageType": "Syrup",
  "medAmount": "2",
  "medName": "cough syrup",
  "duration": "1",
  "scheduledTime": "08:00 AM"
}

Sample Response:

  • If medicine is not created
{
  "message": "Failed to create Medicine"
}
  • If medicine is created
{
  "message": "Medicine created successfully"
}
  • HTTP status codes: 201 for success, 400 for bad request , 404 for not found, 500 for internal server error.

PATCH /api/user/med-taken

Updates the status of a medicine as taken.

Headers:

  • Content-Type: application/json

Request Body:

{
"userId": "123",
"medicineId": "456",
"setTrueForDate": 2024-03-05T15:11:24.451+00:00,
"setTrue": true
}

Sample Response:

  • If Server error while updating medicine taken status
{
  "message": "Internal Server error while updating the medicine taken status"
}
  • HTTP Status Code: 204 No Content

GET /api/user/getMedicines

Gets all the medicines of a user.

Headers:

  • Content-Type: application/json

Request Body:

{
  "userId": "123"
}

Sample Response:

  • If Server error while getting all meds
{
  "message": "Internal Server error while getting the Medicines"
}
  • Successful response
[
  {
    "_id": "65e5e49c368294524c92cc06",
    "name": "Cough Syrup",
    "scheduledTime": "8:00"
  },
  {
    "_id": "65e5e4ea368294524c92cc09",
    "name": "Dolo",
    "scheduledTime": "14:00"
  },
  {
    "_id": "6623ce293e907121089af226",
    "name": "DummyMed",
    "scheduledTime": "20:00"
  },
  {
    "_id": "6623cf8f14b66b366c40a877",
    "name": "DummyMed",
    "scheduledTime": "19:50"
  },
  {
    "_id": "6623d11aba798dad2b403fef",
    "name": "DummyMed",
    "scheduledTime": "19:00"
  }
]
  • HTTP Status Code: 200 (success),204(medicine not found), 500(internal server failure), 422(request body error)

User Community

POST /api/community/create

Creates a new community.

Headers:

  • Content-Type: application/json

Request Body:

{
  "adminUserId": "123",
  "name": "Community Name",
  "description": "Community Description",
  "picture": "http://example.com/picture.jpg",
  "banner": "http://example.com/banner.jpg"
}

Sample Response:

  • If the community is created successfully:
{
  "message": `Community created and Admin status is updated`
}
  • If the input data is incorrect:
{
  "message": "Failed to create community. Please check your input data."
}
  • If there's an internal server error:
{
  "message": "Internal Server Error while creating community"
}
  • HTTP status codes: 201 for success, 400 for bad request, 500 for internal server error.

GET /api/community/get-community

Fetches all communities.

Headers:

None required

Response:

[
  {
    "_id": "123",
    "adminUserId": "123",
    "name": "Community Name",
    "description": "Community Description",
    "picture": "http://example.com/picture.jpg",
    "banner": "http://example.com/banner.jpg"
  },
  ...
]

Expense

POST /api/user/add-expense

Adds a new expense for a user.

Headers:

Content-Type: application/json

Request Body:

{
  "userId": "123",
  "itemName": "Groceries",
  "itemPrice": 50.0
}

Responses

  • If the request body validation fails:
{
  "message": "Validation error messages"
}
  • If the user ID is not found:
{
  "message": "User ID not found"
}
  • If there's an error while adding the expense:
{
  "message": "Error message from addExpense service"
}
  • If the expense is added successfully but there's an error while updating the user:
{
  "message": "Failed to update user with new expense"
}
  • If the expense is added and the user is updated successfully:
{
  "message": "Expense Updated successfully"
}
  • HTTP status codes: 201 for success, 400 for bad request, 404 for not found, 500 for internal server error.

User Functionalities

GET /api/user/get-similar-users/:medicine_name

Fetches a list of users who are associated with a specific medicine.

Parameters

  • medicine_name: The name of the medicine. This is a path parameter.

Responses

  • 200 OK: The request was successful. The response body contains an array of users who are associated with the specified medicine. Each user object includes the user's full name, phone number, and email address.

  • 400 Bad Request: The request was unsuccessful because the medicine_name parameter was not provided. The response body contains a message explaining the error.

  • 500 Internal Server Error: The request was unsuccessful due to an unexpected error on the server. The response body contains a message explaining the error.

Request:

Empty

Response:

[
  {
    "fullname": "John Doe",
    "phone": "123-456-7890",
    "email": "[email protected]"
  },
  {
    "fullname": "Jane Doe",
    "phone": "098-765-4321",
    "email": "[email protected]"
  }
]

About

Backend for Eldafriend app, A pal for the elder community! Track your medication, along with reminders and many showstopper features that ensure completely homely care.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published