Welcome to Magic Transporters, a Node.js application built with NestJS for managing magical transporters and items. This repository contains the backend API service.
- Introduction
- Features
- Description
- Prerequisites
- Getting Started
- Installation
- Configuration
- Usage
- Endpoints
- Testing
- Deployment
Magic Transporters is a REST API service designed to manage magical transporters and their associated items. It provides endpoints for CRUD operations on transporters and items, leveraging NestJS with TypeScript.
- Create, Read, Update, and Delete operations for magic transporters and items.
- Swagger API documentation.
- Testing with Jest.
Description: Adds a new magical mover to the system.
POST /api/movers Creates a new mover with specified details. Example Request Body:{ "energy": 50, "weightLimit": 100 }
Example Response:{ "id": 123, "energy": 50, "weightLimit": 100, }
Description: Adds a new magic item to the system.
POST /api/items Creates a new item with specified details. Example Request Body:{ "name": "Magic Wand", "weight": 10, }
Example Response:{ "id": 1, "name": "Magic Wand", "weight": 10, }
Description: Loads items onto a specific magic mover, creating a log of this activity.
POST /api/movers/:id/load Loads items onto the mover specified by:id
. Example Request Body:{ "items": [1, 2, 3] // Array of item IDs to load onto the mover }
Example Response:{ "id": 1, "weightLimit": 100, "energy": 50, "questState": "loading" }
Description: Updates the state of a magic mover to indicate it's on a mission, stopping further loading and creating a log of this activity.
PUT /api/movers/:id/start-mission Updates the state of the mover specified by:id
to "on a mission". Example Response:{ "id": 1, "weightLimit": 100, "energy": 50, "questState": "onMission" }
Description: Unloads all items from a magic mover, creating a log of this activity indicating mission completion.
PUT /api/movers/:id/end-mission Unloads all items from the mover specified by:id
, marking the mission as complete. Example Response:{ "id": 1, "weightLimit": 100, "energy": 50, "questState": "done" }
Description: Make a simple list to show completed the most missions (ordered descending).
GET /api/mission-logs/most-completed
Example Response:
[
{
"moverId": 1,
"missionCount": "4"
},
{
"moverId": 2,
"missionCount": "2"
}
]
Before you begin, ensure you have the following installed on your development machine:
- Node.js (v14 or higher)
- npm (or yarn)
- MySql (or another compatible relational database)
To get the project up and running on your local machine, follow these steps:
git clone https://github.com/afehid/magic-transport.git cd magic-transport npm install
Set up your environment variables:
Create a .env file in the root directory based on .env.example.
PORT= USERNAME= PASSWORD= DATABASE= HOST= DATABASE_PORT=
Start the application in development mode:
npm run start:dev
The server will start running at http://localhost:3000.
For detailed API documentation, visit the Swagger UI at:
Run tests using Jest:
npm test
For deployment to production, ensure to set appropriate environment variables and configure your server environment accordingly.