https://hng-task2-vc39.onrender.com
- Request
{
"first_name": "John",
"last_name": "Doe",
"email": "[email protected]",
"phone": "1234567890",
"password": "secretpassword"
}
Response
{
"success": true,
"message": "User registered successfully",
"data": {
"user": "userWithoutPassword"
}
}
- Request
Response
{
"message": "User authenticated successfully",
"statusCode": 200,
"data": {
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MiwiaWF0IjoxNjk0ODY1NDk4LCJleHAiOjE2OTQ5NTE4OTh9.gfaVNU1ffhauLWhPoiO3-1MJFzV26FmRlVGT_GqkfJo",
"email": "[email protected]",
"id": "user.id",
"is_admin": true
}
}
- Request
Content-Type: application/json
Authorization: Bearer <admin_token>
{
"firstname": "Jane",
"lastname": "Doe"
}
Response
{
"id": 1,
"firstname": "Jane",
"lastname": "Doe"
}
- Request
The getAllLunch function retrieves all available lunches for a user. It queries the lunch model to find lunches where the user is either the sender or receiver. Response
Content-Type: application/json
Authorization: Bearer <admin_token>
{
"success": true,
"message": "Lunches retrieved successfully",
"data": "allLunches"
}
-
Extracts the user's ID from the JWT token in the request header.
-
Queries the Lunch model to find available lunches for the user where the user is either the sender or receiver.
-
If no lunches are found, it responds with a success message indicating that no lunches were found for the user.
-
If lunches are found, it responds with a success message and the retrieved lunch data in JSON format.
The sendLunch function is responsible for sending a lunch from the current user to another user. It creates a new lunch entry in the database and updates the balances of both the sender and receiver.
Content-Type: application/json
Authorization: Bearer <admin_token>
{
"success": true,
"message": "Lunch sent successfully",
"data": "lunch"
}
- Extracts the receiver_id, quantity, and note from the request body.
- Creates a new lunch entry in the Lunch model with the sender's ID (obtained from the JWT token) and the provided receiver ID, quantity, and note.
- Retrieves the sender and receiver user records from the User model.
- Updates the sender's balance by subtracting the lunch quantity.
- Updates the receiver's balance by adding the lunch quantity. 6.Responds with a success message indicating that the lunch was sent successfully, along with the details of the created lunch entry.
- Request
Content-Type: application/json
Authorization: Bearer <admin_token>
{
"name": "Zuri",
"launch_price": 1000,
"currency_code": "NGN"
}
Response
{
"success" : true,
"message": "Organization and Lunch wallet created successfully",
"data": {
"user": "organization" {
"name": "Zuri",
"launch_price": "1000",
"currency_code": "NGN"
},
"launchWallet" {
"org_id": 2348,
"balance": 10000
}
}
}
- Request
Content-Type: application/json
Authorization: Bearer <admin_token>
{
"email": "[email protected]",
"organizationId": 234278
}
Response
{
"success": true,
"message": "Invitation sent successfully",
"data": null
}
- Request
Content-Type: application/json
Authorization: Bearer <admin_token>
{
"name": "HNG",
"lunch_price": 2000,
"currency": "NGN"
}
Response
{
"organization": {
"name": "HNG",
"lunch_price": 2000,
"currency": "NGN"
}
}
- Request
Content-Type: application/json
Authorization: Bearer <admin_token>
Response
{
"success": true,
"message": "User found",
"data": {
"user": "user"
}
}
- Request
Content-Type: application/json
Authorization: Bearer <admin_token>
Response
{
"success" : true,
"message": "List of all users",
"data": {
"users"
}
}
- Request
Content-Type: application/json
Authorization: Bearer <admin_token>
{
"name": "HNG",
"lunch_price": 2000,
"currency": "NGN"
}
Response
{
"organization": {
"name": "HNG",
"lunch_price": 2000,
"currency": "NGN"
}
}
To set up and deploy this API locally or on a server, follow these steps:
Clone the repository from GitHub.
Install Node.js and npm if not already installed.
Navigate to the project directory and run the following command to install dependencies:
npm install
Set up a database connection in the knex-db/knex.js file. Run the following command to migrate the database:
npm run knex migrate:latest
Start the API server with the following command: npm start
The API will be accessible at http://localhost:3000 by default.
This documentation outlines the usage, endpoints, and setup instructions for the My Developer API. If you have any questions or need further assistance, please contact our support team at [email protected].