|
1 | 1 | # Core 🧠 |
2 | 2 |
|
3 | | -> Core stuffs to any NodeJS project |
| 3 | +> Core stuffs to your NodeJS project |
4 | 4 |
|
5 | 5 | [](https://github.com/jlenon7?tab=followers) |
6 | 6 | [](https://github.com/secjs/core/stargazers/) |
|
13 | 13 | <img alt="License" src="https://img.shields.io/badge/license-MIT-brightgreen?style=for-the-badge&logo=appveyor"> |
14 | 14 | </p> |
15 | 15 |
|
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. |
17 | 17 |
|
18 | 18 | <img src=".github/core.jpg" width="200px" align="right" hspace="30px" vspace="100px"> |
19 | 19 |
|
20 | | -## Installation |
21 | | - |
22 | | -```bash |
23 | | -yarn add @secjs/core |
24 | | -``` |
| 20 | +## WARN 🛑⚠️ |
25 | 21 |
|
26 | | -## Base |
| 22 | +> This project is under `development` do not use it until releases v2.0.0. |
27 | 23 |
|
28 | | -### GuardBaseService |
29 | | - |
30 | | -```js |
31 | | -import { User } from 'app/Models/User' |
32 | | -import { GuardBaseService } from '@secjs/core/base' |
| 24 | +## Installation |
33 | 25 |
|
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') |
38 | 27 |
|
39 | | - async getOne(id) { |
40 | | - const contact = // ... all the logic to get an Contact |
| 28 | +```bash |
| 29 | +yarn add @secjs/utils |
| 30 | +``` |
41 | 31 |
|
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 |
46 | 33 |
|
47 | | - return contact |
48 | | - } |
49 | | -} |
| 34 | +```bash |
| 35 | +yarn add @secjs/core |
50 | 36 | ``` |
51 | 37 |
|
52 | | ---- |
| 38 | +## Decorators |
53 | 39 |
|
54 | | -### LucidBaseRepository |
| 40 | +### Controller |
55 | 41 |
|
56 | | -> Use LucidBaseRepository to get nice methods based on ApiRequestContract |
| 42 | +> Use `Controller` decorator to map a controller to your application |
57 | 43 |
|
58 | | -```js |
59 | | -import { User } from 'app/Models/User' |
60 | | -import { LucidBaseRepository } from '@secjs/core/base' |
| 44 | +```ts |
| 45 | +import { Controller } from '@secjs/core' |
61 | 46 |
|
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 {} |
67 | 49 | ``` |
68 | 50 |
|
69 | | ---- |
| 51 | +### Request Mappers - GET/POST/PUT/DELETE/ETC... |
70 | 52 |
|
71 | | -### TypeOrmBaseRepository |
| 53 | +> Use `GET, POST, PUT, DELETE, PATCH, ALL, OPTIONS, HEAD` decorators to map the real route for your application |
72 | 54 |
|
73 | | -> Use TypeOrmBaseRepository to get nice methods based on ApiRequestContract |
| 55 | +```ts |
| 56 | +import { Get, Post, Put, Delete } from '@secjs/core' |
74 | 57 |
|
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() {} |
78 | 65 |
|
79 | | -class UserRepository extends TypeOrmBaseRepository<User> { // Give the Model type to TypeOrm so he knows what to work with |
| 66 | + @Post() |
| 67 | + async create() {} |
80 | 68 |
|
81 | | - // You can subscribe TypeOrmBaseRepository methods in here if you want! |
| 69 | + @Put(':id') |
| 70 | + async update() {} |
| 71 | + |
| 72 | + @Delete('/:id') |
| 73 | + async delete() {} |
82 | 74 | } |
| 75 | + |
| 76 | +// Routes created: |
| 77 | +// |
| 78 | +// /tests GET |
| 79 | +// /tests/:id GET |
| 80 | +// /tests POST |
| 81 | +// /tests/:id PUT |
| 82 | +// /tests/:id DELETE |
83 | 83 | ``` |
84 | 84 |
|
85 | 85 | --- |
0 commit comments