Skip to content

Commit b844938

Browse files
Alexander Kharkoveyklerick
authored andcommitted
fix(json-api-nestjs): allow extends inner methode
1 parent 18acefc commit b844938

File tree

19 files changed

+565
-268
lines changed

19 files changed

+565
-268
lines changed

README.md

Lines changed: 41 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,55 @@
1+
<p align='center'>
2+
<a href="https://www.npmjs.com/package/json-api-nestjs" target="_blank"><img src="https://img.shields.io/npm/v/json-api-nestjs.svg" alt="NPM Version" /></a>
3+
<a href="https://www.npmjs.com/package/json-api-nestjs" target="_blank"><img src="https://img.shields.io/npm/l/json-api-nestjs.svg" alt="Package License" /></a>
4+
<a href="https://www.npmjs.com/package/json-api-nestjs" target="_blank"><img src="https://img.shields.io/npm/dm/json-api-nestjs.svg" alt="NPM Downloads" /></a>
5+
<a href="http://commitizen.github.io/cz-cli/" target="_blank"><img src="https://img.shields.io/badge/commitizen-friendly-brightgreen.svg" alt="Commitizen friendly" /></a>
6+
<img src="https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/klerick/397d521f54660656f2fd6195ec482581/raw/coverage-json-api.json" alt="Coverage Badge" />
7+
</p>
18

9+
<p align="center">
10+
Json API plugin for
11+
<a href="http://nestjs.com/" target="blank">NestJS</a>
12+
framework
13+
</p>
14+
<p>
15+
Tools to implement JSON API, such as, end point, query params, body params, validation and transformation response.
16+
</p>
217

3-
# NestjsJsonApi
18+
## Description
419

5-
This project was generated using [Nx](https://nx.dev).
20+
<p>
21+
This is the plugin that works upon TypeOrm library as a main database abstraction layer tool. Module automaticly generates API according to JSON API specificaton from the database structure (TypeORM entities). It support such features as requests validation based on database fields types, request filtering, endpoints exdending, data relations control and much more. Our module significantly reduces the development time of REST services by removing the need to negotiate the mechanism of client-server interaction and implementing automatic API generation without the need to write any code.
22+
</p>
623

7-
<p style="text-align: center;"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-logo.png" width="450"></p>
24+
## Installation
825

9-
🔎 **Smart, Fast and Extensible Build System**
26+
```bash
27+
$ npm install
28+
$ npm run typeorm:run
29+
$ npm run seed:run
30+
```
1031

11-
## Quick Start & Documentation
32+
## Running the example app
1233

13-
[Nx Documentation](https://nx.dev/getting-started/intro)
34+
```bash
35+
# build plugin
36+
$ npm run json-api-nestjs:build
1437

15-
[Mental model is a good starting point for those who like to understand things theoretically first.](https://nx.dev/concepts/mental-model)
38+
# dev server
39+
$ npm run example:serve
1640

17-
[Interactive Tutorial](https://nx.dev/getting-started/angular-tutorial)
41+
```
1842

19-
## Adding capabilities to your workspace
43+
## Test
2044

21-
Nx supports many plugins which add capabilities for developing different types of applications and different tools.
45+
```bash
46+
# unit tests
47+
$ nx test json-api-nestjs
2248

23-
These capabilities include generating applications, libraries, etc as well as the devtools to test, and build projects as well.
49+
# test coverage
50+
$ nx test json-api-nestjs --coverage
51+
```
2452

25-
Below are our core plugins:
53+
## License
2654

27-
- [Angular](https://angular.io)
28-
- `ng add @nrwl/angular`
29-
- [React](https://reactjs.org)
30-
- `ng add @nrwl/react`
31-
- Web (no framework frontends)
32-
- `ng add @nrwl/web`
33-
- [Nest](https://nestjs.com)
34-
- `ng add @nrwl/nest`
35-
- [Express](https://expressjs.com)
36-
- `ng add @nrwl/express`
37-
- [Node](https://nodejs.org)
38-
- `ng add @nrwl/node`
39-
40-
There are also many [community plugins](https://nx.dev/community) you could add.
41-
42-
## Generate an application
43-
44-
Run `ng g @nrwl/angular:app my-app` to generate an application.
45-
46-
> You can use any of the plugins above to generate applications as well.
47-
48-
When using Nx, you can create multiple applications and libraries in the same workspace.
49-
50-
## Generate a library
51-
52-
Run `ng g @nrwl/angular:lib my-lib` to generate a library.
53-
54-
> You can also use any of the plugins above to generate libraries as well.
55-
56-
Libraries are shareable across libraries and applications. They can be imported from `@nestjs-json-api/mylib`.
57-
58-
## Development server
59-
60-
Run `ng serve my-app` for a dev server. Navigate to http://localhost:4200/. The app will automatically reload if you change any of the source files.
61-
62-
## Code scaffolding
63-
64-
Run `ng g component my-component --project=my-app` to generate a new component.
65-
66-
## Build
67-
68-
Run `ng build my-app` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `--prod` flag for a production build.
69-
70-
## Running unit tests
71-
72-
Run `ng test my-app` to execute the unit tests via [Jest](https://jestjs.io).
73-
74-
Run `nx affected:test` to execute the unit tests affected by a change.
75-
76-
## Running end-to-end tests
77-
78-
Run `ng e2e my-app` to execute the end-to-end tests via [Cypress](https://www.cypress.io).
79-
80-
Run `nx affected:e2e` to execute the end-to-end tests affected by a change.
81-
82-
## Understand your workspace
83-
84-
Run `nx graph` to see a diagram of the dependencies of your projects.
85-
86-
## Further help
87-
88-
Visit the [Nx Documentation](https://nx.dev/angular) to learn more.
89-
90-
91-
92-
93-
94-
95-
## ☁ Nx Cloud
96-
97-
### Distributed Computation Caching & Distributed Task Execution
98-
99-
<p style="text-align: center;"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-cloud-card.png"></p>
100-
101-
Nx Cloud pairs with Nx in order to enable you to build and test code more rapidly, by up to 10 times. Even teams that are new to Nx can connect to Nx Cloud and start saving time instantly.
102-
103-
Teams using Nx gain the advantage of building full-stack applications with their preferred framework alongside Nx’s advanced code generation and project dependency graph, plus a unified experience for both frontend and backend developers.
104-
105-
Visit [Nx Cloud](https://nx.app/) to learn more.
55+
The plugin is [MIT licensed](LICENSE).

apps/example/src/app/app.module.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Module } from '@nestjs/common';
2+
import { LoggerModule } from 'nestjs-pino';
23

34
import {DatabaseModule} from 'database';
45
import {ResourcesModule} from './resources/resources.module';
@@ -7,7 +8,12 @@ import {ResourcesModule} from './resources/resources.module';
78
@Module({
89
imports: [
910
DatabaseModule,
10-
ResourcesModule
11+
ResourcesModule,
12+
LoggerModule.forRoot({
13+
pinoHttp: {
14+
level: 'debug'
15+
}
16+
})
1117
],
1218
controllers: [],
1319
providers: [],
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
1+
import {Get, Param, Inject} from '@nestjs/common';
2+
13
import {Users} from 'database';
24
import {JsonApi, excludeMethod, JsonBaseController, InjectService, JsonApiService, QueryParams} from 'json-api-nestjs';
3-
import {Get, Param} from '@nestjs/common';
5+
import {ExampleService} from '../../service/example/example.service';
46

57

68

79
@JsonApi(Users, {
810
allowMethod: excludeMethod(['deleteRelationship']),
911
requiredSelectField: true
1012
})
11-
export class ExtendUserController extends JsonBaseController<Users>
12-
{
13+
export class ExtendUserController extends JsonBaseController<Users>{
1314
@InjectService() public service: JsonApiService<Users>;
15+
@Inject(ExampleService) protected exampleService: ExampleService
1416

1517
public override getAll(query: QueryParams<Users>){
1618
return this.service.getAll({query})
1719
}
1820

1921
@Get(':id/example')
20-
testOne(@Param('id') id) {
21-
return id;
22+
testOne(@Param('id') id: string): string {
23+
return this.exampleService.testMethode(id);
2224
}
2325
}

apps/example/src/app/resources/resources.module.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,23 @@ import {JsonApiModule} from 'json-api-nestjs';
33
import {Users, Addresses, Comments, Roles} from 'database';
44

55
import {ExtendUserController} from './controllers/extend-user/extend-user.controller';
6+
import {ExampleService} from './service/example/example.service';
67

78
@Module({
89
imports: [
910
JsonApiModule.forRoot({
1011
entities: [
1112
Users,
12-
// Addresses,
13-
// Comments,
14-
// Roles
13+
Addresses,
14+
Comments,
15+
Roles
1516
],
1617
controllers: [
1718
ExtendUserController
1819
],
20+
providers: [
21+
ExampleService
22+
],
1923
options: {
2024
debug: true,
2125
maxExecutionTime: 3000,
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export class ExampleService{
2+
testMethode(id: string): string {
3+
return id;
4+
}
5+
}

apps/example/src/main.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,19 @@
33
* This is only a minimal backend to get started.
44
*/
55

6-
import {Logger, VersioningType} from '@nestjs/common';
7-
import { NestFactory } from '@nestjs/core';
8-
9-
import { AppModule } from './app/app.module';
6+
import {VersioningType} from '@nestjs/common';
7+
import {NestFactory} from '@nestjs/core';
108
import {DocumentBuilder, SwaggerModule} from '@nestjs/swagger';
9+
import {Logger} from 'nestjs-pino';
10+
11+
import {AppModule} from './app/app.module';
12+
1113

1214
async function bootstrap() {
13-
const app = await NestFactory.create(AppModule);
15+
const app = await NestFactory.create(AppModule, {bufferLogs: true});
16+
const ligerInst = app.get(Logger)
17+
app.useLogger(ligerInst);
18+
app.flushLogs();
1419
const globalPrefix = 'api';
1520
app.setGlobalPrefix(globalPrefix);
1621

@@ -29,7 +34,7 @@ async function bootstrap() {
2934

3035
const port = process.env.PORT || 3333;
3136
await app.listen(port);
32-
Logger.log(
37+
ligerInst.log(
3338
`🚀 Application is running on: http://localhost:${port}/${globalPrefix}`
3439
);
3540
}

libs/json-api-nestjs/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export * from './lib/json-api.module';
22
export * from './lib/decorators';
33
export { excludeMethod } from './lib/config/bindings'
44
export * from './lib/types'
5+
export * from './lib/mixin/controller'

0 commit comments

Comments
 (0)