Skip to content

Commit 744ddd8

Browse files
committed
feat: Core as request mapper v1.6.7
1 parent d2afe10 commit 744ddd8

15 files changed

Lines changed: 2769 additions & 2301 deletions

README.md

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Core 🧠
22

3-
> Core stuffs to any NodeJS project
3+
> Core stuffs to your NodeJS project
44
55
[![GitHub followers](https://img.shields.io/github/followers/jlenon7.svg?style=social&label=Follow&maxAge=2592000)](https://github.com/jlenon7?tab=followers)
66
[![GitHub stars](https://img.shields.io/github/stars/secjs/core.svg?style=social&label=Star&maxAge=2592000)](https://github.com/secjs/core/stargazers/)
@@ -13,73 +13,73 @@
1313
<img alt="License" src="https://img.shields.io/badge/license-MIT-brightgreen?style=for-the-badge&logo=appveyor">
1414
</p>
1515

16-
The intention behind this repository is to always maintain an `Core` project to any NodeJS project.
16+
The intention behind this repository is to concentrate all `SecJS` libraries to create an HTTP server to any NodeJS project.
1717

1818
<img src=".github/core.jpg" width="200px" align="right" hspace="30px" vspace="100px">
1919

20-
## Installation
21-
22-
```bash
23-
yarn add @secjs/core
24-
```
20+
## WARN 🛑⚠️
2521

26-
## Base
22+
> This project is under `development` do not use it until releases v2.0.0.
2723
28-
### GuardBaseService
29-
30-
```js
31-
import { User } from 'app/Models/User'
32-
import { GuardBaseService } from '@secjs/core/base'
24+
## Installation
3325

34-
class ContactService extends GuardBaseService<User> {
35-
// You new to write all you methods in here, GuardBaseService
36-
// just makes sure it's an authenticated request and save the
37-
// Guard/User in the context of the service.
26+
This project depends on [`@secjs/utils`]('https://github.com/SecJS/Utils')
3827

39-
async getOne(id) {
40-
const contact = // ... all the logic to get an Contact
28+
```bash
29+
yarn add @secjs/utils
30+
```
4131

42-
// If you use User as guard, you can access this.guard.user.id or this.guard.id
43-
if (contact.user_id !== this.guard.user.id) {
44-
throw new Error('Unauthorized')
45-
}
32+
Then install the project
4633

47-
return contact
48-
}
49-
}
34+
```bash
35+
yarn add @secjs/core
5036
```
5137

52-
---
38+
## Decorators
5339

54-
### LucidBaseRepository
40+
### Controller
5541

56-
> Use LucidBaseRepository to get nice methods based on ApiRequestContract
42+
> Use `Controller` decorator to map a controller to your application
5743
58-
```js
59-
import { User } from 'app/Models/User'
60-
import { LucidBaseRepository } from '@secjs/core/base'
44+
```ts
45+
import { Controller } from '@secjs/core'
6146

62-
class UserRepository extends LucidBaseRepository<User> { // Just for types
63-
protected Model = User // Give the Model value to Lucid, so he knows what to work with
64-
65-
// You can subscribe LucidBaseRepository methods in here if you want!
66-
}
47+
@Controller('/tests')
48+
class TestController {}
6749
```
6850

69-
---
51+
### Request Mappers - GET/POST/PUT/DELETE/ETC...
7052

71-
### TypeOrmBaseRepository
53+
> Use `GET, POST, PUT, DELETE, PATCH, ALL, OPTIONS, HEAD` decorators to map the real route for your application
7254
73-
> Use TypeOrmBaseRepository to get nice methods based on ApiRequestContract
55+
```ts
56+
import { Get, Post, Put, Delete } from '@secjs/core'
7457

75-
```js
76-
import { User } from 'app/Models/User'
77-
import { TypeOrmBaseRepository } from '@secjs/core/base'
58+
@Controller('/tests')
59+
class TestController {
60+
@Get()
61+
async getAll() {}
62+
63+
@Get('/:id')
64+
async getOne() {}
7865

79-
class UserRepository extends TypeOrmBaseRepository<User> { // Give the Model type to TypeOrm so he knows what to work with
66+
@Post()
67+
async create() {}
8068

81-
// You can subscribe TypeOrmBaseRepository methods in here if you want!
69+
@Put(':id')
70+
async update() {}
71+
72+
@Delete('/:id')
73+
async delete() {}
8274
}
75+
76+
// Routes created:
77+
//
78+
// /tests GET
79+
// /tests/:id GET
80+
// /tests POST
81+
// /tests/:id PUT
82+
// /tests/:id DELETE
8383
```
8484

8585
---

base/Repositories/LucidRepository.ts

Lines changed: 0 additions & 104 deletions
This file was deleted.

base/Repositories/MongooseRepository.ts

Lines changed: 0 additions & 159 deletions
This file was deleted.

0 commit comments

Comments
 (0)