Skip to content

Commit

Permalink
Merge branch 'release/R.5.2-Docs-Builder'
Browse files Browse the repository at this point in the history
  • Loading branch information
John Livee Oroncillo committed Mar 24, 2022
2 parents f70fba6 + 662c7eb commit ca06429
Show file tree
Hide file tree
Showing 81 changed files with 3,345 additions and 577 deletions.
13 changes: 7 additions & 6 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
module.exports = {
parser: "@typescript-eslint/parser", // Specifies the ESLint parser
parser: '@typescript-eslint/parser', // Specifies the ESLint parser
parserOptions: {
ecmaVersion: 2020, // Allows for the parsing of modern ECMAScript features
sourceType: "module" // Allows for the use of imports
sourceType: 'module', // Allows for the use of imports
},
extends: [
"plugin:@typescript-eslint/recommended", // Uses the recommended rules from the @typescript-eslint/eslint-plugin
"prettier", // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier
'plugin:@typescript-eslint/recommended', // Uses the recommended rules from the @typescript-eslint/eslint-plugin
'prettier/@typescript-eslint',
'plugin:prettier/recommended', // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier
],
rules: {
// Place to specify ESLint rules. Can be used to overwrite rules specified from the extended configs
// e.g. "@typescript-eslint/explicit-function-return-type": "off",
}
}
},
};
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,16 @@ This will create model and repository
npm run make:event <event_name>
```
#### Create PlantUML Diagram
#### Create Documentation
```bash
npm run make:puml <name>
npm run make:doc <name>
```
#### Build Documentation
```bash
npm run build:doc
```
## Other API Reference
Expand Down
10 changes: 10 additions & 0 deletions apidoc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "tsnode-rest-api-boilerplate",
"version": "0.1.0",
"description": "API Documentation",
"title": "API Documentation - tsnode-rest-api-boilerplate",
"url" : "",
"template": {
"showRequiredLabels": true
}
}
9 changes: 4 additions & 5 deletions apis/event/action.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { EventRequest } from "./request";
import { invokeEvent, invokeEventWithResponse } from "../../core/libs/Events";
import { EVENTS } from "../../helpers/Enums";
import { EventRequest } from './request';
import { invokeEvent, invokeEventWithResponse } from '../../core/libs/Events';
import { EVENTS } from '../../helpers/Enums';

export class EventAction {

async execute(request: EventRequest): Promise<void> {
//OPTION 1 - Event with response
// const data = await invokeEventWithResponse(EVENTS.EVENT_TEST, { message: request.message });
Expand All @@ -12,4 +11,4 @@ export class EventAction {
//OPTION 2
await invokeEvent(EVENTS.EVENT_TEST, { message: request.message });
}
}
}
32 changes: 17 additions & 15 deletions apis/event/handler.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
import { API_RESPONSE } from "../../core";
import { HttpResponse, HttpRequest } from "../../core/libs/ApiEvent";
import { Response } from "express";
import { Database } from "../../core/databases/Mysql";
import { Connection } from "typeorm";
import { API_RESPONSE } from '../../core';
import { HttpResponse, HttpRequest } from '../../core/libs/ApiEvent';
import { Response } from 'express';
import { Database } from '../../core/databases/Mysql';
import { Connection } from 'typeorm';

import { Response200 } from "./response";
import { Validate } from "./validate";
import { EventAction } from "./action";
import { Response200 } from './response';
import { Validate } from './validate';
import { EventAction } from './action';

export async function execute(req: HttpRequest, res: Response): Promise<HttpResponse> {
try {
const request = Validate(req.body);
const action = new EventAction();
const data = await action.execute(request);

return API_RESPONSE({
...Response200.SUCCESS,
data,
}, res);
}
catch(e) {

return API_RESPONSE(
{
...Response200.SUCCESS,
data,
},
res,
);
} catch (e) {
return API_RESPONSE(e, res);
}
// finally {
Expand Down
13 changes: 4 additions & 9 deletions apis/event/handler_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,11 @@ test('200: SUCCESS', async () => {
const request = {
identity: {},
body: <EventRequest>{
key: 'value',
message: 'value',
},
params: {

},
query: {

}
} as HttpRequest

params: {},
query: {},
} as HttpRequest;

const result = await execute(request, TestReponse);

Expand Down
2 changes: 1 addition & 1 deletion apis/event/request.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export interface EventRequest {
message: string;
}
}
4 changes: 2 additions & 2 deletions apis/event/response.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { HttpResponse } from "../../core/libs/ApiEvent";
import { HttpResponse } from '../../core/libs/ApiEvent';

/*
Your Custom Response */
export class Response200 {
static SUCCESS: HttpResponse = {
code: 200,
message: 'Success',
}
};
}

export class NotFound {
Expand Down
4 changes: 2 additions & 2 deletions apis/event/validate.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EventRequest } from "./request";
import { Validation } from "../../core/libs/Validation";
import { EventRequest } from './request';
import { Validation } from '../../core/libs/Validation';
import joi from 'joi';

export const Validate = (request: EventRequest): EventRequest => {
Expand Down
21 changes: 10 additions & 11 deletions apis/login/action.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@

import { Connection } from "typeorm";
import { TokenReponse, TokenService } from "../../core/libs/TokenService";
import { UsersRepository } from "../../repository/UsersRepository";
import { LoginRequest } from "./request";
import { NotFound, PasswordError } from "./response";
import { Connection } from 'typeorm';
import { TokenReponse, TokenService } from '../../core/libs/TokenService';
import { UsersRepository } from '../../repository/UsersRepository';
import { LoginRequest } from './request';
import { NotFound, PasswordError } from './response';
import { Bcrypt } from '../../core/libs/Bcrypt';
import { USER_SCOPE } from "../../helpers/Enums";
import { USER_SCOPE } from '../../helpers/Enums';

export class LoginAction {
private userRepository: UsersRepository;
Expand All @@ -17,8 +16,8 @@ export class LoginAction {
async execute(request: LoginRequest): Promise<TokenReponse> {
const user = await this.userRepository.getByUsername(request.username, USER_SCOPE.CLIENT);
if (!user) throw new NotFound();
if (! await Bcrypt.compare(request.password, user.password)) throw new PasswordError();

if (!(await Bcrypt.compare(request.password, user.password))) throw new PasswordError();

const token = await TokenService.clientJWT({
id: user.id,
Expand All @@ -28,6 +27,6 @@ export class LoginAction {
return {
token,
data: user,
}
};
}
}
}
38 changes: 19 additions & 19 deletions apis/login/handler.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
import { API_RESPONSE } from '../../core';
import { HttpResponse, HttpRequest } from '../../core/libs/ApiEvent';
import { Response } from 'express';
import { Database } from '../../core/databases/Mysql';
import { Connection } from 'typeorm';

import { API_RESPONSE } from "../../core";
import { HttpResponse, HttpRequest } from "../../core/libs/ApiEvent";
import { Response } from "express";
import { Database } from "../../core/databases/Mysql";
import { Connection } from "typeorm";

import { Response200 } from "./response";
import { Validate } from "./validate";
import { LoginAction } from "./action";
import { Response200 } from './response';
import { Validate } from './validate';
import { LoginAction } from './action';

export async function execute(req: HttpRequest, res: Response): Promise<HttpResponse> {
try {
const request = Validate(req.body);
const connection: Connection = await Database.getConnection();
const connection: Connection = await Database.getConnection();
const action = new LoginAction(connection);
const data = await action.execute(request);

return API_RESPONSE({
...Response200.SUCCESS,
...data,
}, res);
}
catch(e) {

return API_RESPONSE(
{
...Response200.SUCCESS,
...data,
},
res,
);
} catch (e) {
return API_RESPONSE(e, res);
}
finally {
} finally {
await Database.closeConnection();
}
}
54 changes: 16 additions & 38 deletions apis/login/handler_test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import { execute } from './handler';
import { LoginRequest } from './request';
import { TestReponse, HttpRequest } from '../../core/libs/ApiEvent';
Expand All @@ -12,14 +11,9 @@ test('422: PARAMETER ERROR', async () => {
username: '',
password: '',
},
params: {

},
query: {

}
} as HttpRequest

params: {},
query: {},
} as HttpRequest;

const result = await execute(request, TestReponse);

Expand All @@ -34,17 +28,12 @@ test('404: USERNAME NOT FOUND', async () => {
const request = {
identity: {},
body: <LoginRequest>{
username: faker.internet.userName(),
username: faker.internet.userName(),
password: 'test',
},
params: {

},
query: {

}
} as HttpRequest

params: {},
query: {},
} as HttpRequest;

const result = await execute(request, TestReponse);

Expand All @@ -55,21 +44,16 @@ test('404: USERNAME NOT FOUND', async () => {
});

test('400: PASSWORD ERROR', async () => {
const user = await UserSeeder.create(1)
const user = await UserSeeder.create(1);
const request = {
identity: {},
body: <LoginRequest>{
username: user.username,
username: user.username,
password: faker.internet.password(),
},
params: {

},
query: {

}
} as HttpRequest

params: {},
query: {},
} as HttpRequest;

const result = await execute(request, TestReponse);

Expand All @@ -79,23 +63,17 @@ test('400: PASSWORD ERROR', async () => {
expect(result.code).toBe(400);
});


test('200: SUCCESS', async () => {
const user = await UserSeeder.create(2)
const user = await UserSeeder.create(2);
const request = {
identity: {},
body: <LoginRequest>{
username: user.username,
password: 'test',
},
params: {

},
query: {

}
} as HttpRequest

params: {},
query: {},
} as HttpRequest;

const result = await execute(request, TestReponse);

Expand Down
3 changes: 1 addition & 2 deletions apis/login/request.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

export interface LoginRequest {
username: string;
password: string;
}
}
5 changes: 2 additions & 3 deletions apis/login/response.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@

import { HttpResponse } from "../../core/libs/ApiEvent";
import { HttpResponse } from '../../core/libs/ApiEvent';

/*
Your Custom Response */
export class Response200 {
static SUCCESS: HttpResponse = {
code: 200,
message: 'Success',
}
};
}

export class NotFound {
Expand Down
5 changes: 2 additions & 3 deletions apis/login/validate.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

import { LoginRequest } from "./request";
import { Validation } from "../../core/libs/Validation";
import { LoginRequest } from './request';
import { Validation } from '../../core/libs/Validation';
import joi from 'joi';

export const Validate = (request: LoginRequest): LoginRequest => {
Expand Down
Loading

0 comments on commit ca06429

Please sign in to comment.