https://github.com/mongark/nanoerp-api
Small API that communicates with a MongoDB database. Used in the NanoERP project.
https://github.com/mongark/nanoerp-api
api docker docker-compose express-js mongodb mongoose typescript
Last synced: 3 months ago
JSON representation
Small API that communicates with a MongoDB database. Used in the NanoERP project.
- Host: GitHub
- URL: https://github.com/mongark/nanoerp-api
- Owner: Mongark
- Created: 2022-08-14T08:17:09.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2023-04-09T19:06:25.000Z (about 3 years ago)
- Last Synced: 2025-03-29T09:14:07.364Z (over 1 year ago)
- Topics: api, docker, docker-compose, express-js, mongodb, mongoose, typescript
- Language: TypeScript
- Homepage:
- Size: 596 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# NanoERP API
   

Small API that communicates with a MongoDB database. Used in the NanoERP project.
It bases itself on the concept of generating code through specification.
## How to Use the Router Generator
### Schema and Model
First, you must create a Mongoose Model from a Schema that an endpoint can use. Example:
```typescript
const SampleSchema = new Schema({
name: {
required: true,
type: String,
},
});
const SampleModel = model('Sample', SampleSchema);
```
You can find more information about it [here](https://mongoosejs.com/docs/models.html).
### Router Generation
With a Model, you can generate an Express router based on an array of endpoints. Each endpoint must be defined according to the EndpointType interface, and endpoint queries can ben passed through the `uri` string.
```typescript
const router_config: Array = [
{
type: "GET",
uri: "/:id",
middleware: ControllerFactory.create("GET_BY_ID", SampleModel),
},
{
type: "POST",
uri: "/",
middleware: ControllerFactory.create("POST_ONE", SampleModel),
},
]
const sample_router = RouterFactory.createRoute(config);
```
### Adding to the API
Lastly, youd just have to use the created route in your Express API.
```typescript
const app = express();
app.use(sample_router);
```
## Project Structure
```
src
├── data
│ ├── models
│ └── schema
├── generators
│ ├── Actions
│ ├── CommonTypes
│ ├── Controllers
│ │ ├── ControllerMiddleware
│ ├── Factories
├── middleware
│ └── auth
└── routes
```
### Data
For Models and Schema.
### Generators
For API route generation.
### Middleware
For non-generator middleware, such as Auth.
### Routes
For defining and loading generated routes.
## Bussiness Rules
### API
Endpoint(or Router) Generator
- [ ] Each `Endpoint` should use a `EndpointConfig` specification.
- [ ] Each `Endpoint` should be test-able with a `TestGenerator`.
### Database
Inquire(when a guest is preparing to make a reservation).
- [ ] Each `Inquire` should have a creation date.
Accommodation
- [ ] Each `Accommodation` must have a unique name.
- [ ] Each `Accommodation` must have a `Location`.
Location
- [ ] Each `Location` must have a unique `location_name`.
Room
- [ ] Each `Room` must have a unique name.
- [ ] Each `Room` must belong to an `Accommodation`.
Company
- [ ] Each `Company` must have a name.
User
- [ ] Each `User` must belong to a `Company`.
- [ ] Each `User` has a set of `Role`s.
- [ ] The `User` that signs up a company automatically gains the `Admin` role.
Role
- [ ] Each `Role` gives a set of permissions to a `User`.
- [ ] A `Role` can be customized by a `User` with the `Admin` role.
- [ ] The `Admin` role can only be removed by a `User` with `Admin` role.
- [ ] The `Admin` role can't be removed by a `User` that is currently using it.