Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dist/constants.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
export declare const ROOT_ROUTE = "ROOT_ROUTE";
export declare const DATA_KEY = "DATA_KEY";
export declare const MODULE_PATH = "MODULE_PATH";
export declare const IGNORE_DATA_KEY = "IGNORE_DATA_KEY";
/**
* HTTP METHOD CONSTANTS
*/
Expand Down
2 changes: 1 addition & 1 deletion dist/constants.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion dist/constants.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.IS_POST_MIDDLEWARE = exports.IS_PRE_MIDDLEWARE = exports.MIDDLEWARE = exports.ROLES = exports.AUTH = exports.PRIVATE = exports.PATH_ROUTE = exports.MODULE_PATH = exports.DATA_KEY = exports.ROOT_ROUTE = void 0;
exports.IS_POST_MIDDLEWARE = exports.IS_PRE_MIDDLEWARE = exports.MIDDLEWARE = exports.ROLES = exports.AUTH = exports.PRIVATE = exports.PATH_ROUTE = exports.IGNORE_DATA_KEY = exports.MODULE_PATH = exports.DATA_KEY = exports.ROOT_ROUTE = void 0;
/**
* MODULE CONSTANTS
*/
exports.ROOT_ROUTE = 'ROOT_ROUTE';
exports.DATA_KEY = 'DATA_KEY';
exports.MODULE_PATH = 'MODULE_PATH';
exports.IGNORE_DATA_KEY = 'IGNORE_DATA_KEY';
/**
* HTTP METHOD CONSTANTS
*/
Expand Down
2 changes: 1 addition & 1 deletion dist/decorators/Module.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion dist/decorators/Module.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ function Module(settings) {
settings = {
prefix: settings || '/',
dataKey,
table: []
table: [],
responseAsBody: false,
};
}
else {
Expand All @@ -45,6 +46,7 @@ function Module(settings) {
}
target[constants_1.ROOT_ROUTE] = ((_a = settings === null || settings === void 0 ? void 0 : settings.prefix) === null || _a === void 0 ? void 0 : _a.startsWith('/')) ? settings.prefix : `/${settings.prefix}`;
target[constants_1.DATA_KEY] = settings.dataKey;
target[constants_1.IGNORE_DATA_KEY] = settings.responseAsBody;
target[constants_1.MODULE_PATH] = filePath;
};
}
Expand Down
2 changes: 1 addition & 1 deletion dist/decorators/helpers.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions dist/decorators/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ function bindControllers(server, controllers) {
// @ts-ignore
const dataKey = Clazz[constants_1.DATA_KEY];
// @ts-ignore
const ignoreDataKey = Clazz[constants_1.IGNORE_DATA_KEY];
// @ts-ignore
const modulePath = Clazz[constants_1.MODULE_PATH];
if (!rootRoute || !rootRoute.startsWith('/')) {
// TODO test it
Expand All @@ -44,7 +46,10 @@ function bindControllers(server, controllers) {
const result = await routingFunction(...params);
if (result) {
let body;
if (typeof result === 'object' && !Array.isArray(result) && result.hasOwnProperty(dataKey)) {
if (ignoreDataKey) {
body = result;
}
else if (typeof result === 'object' && !Array.isArray(result) && result.hasOwnProperty(dataKey)) {
body = result;
}
else if (result instanceof Error) {
Expand Down Expand Up @@ -99,7 +104,10 @@ function bindControllers(server, controllers) {
if (result === null || result === undefined) {
return next();
}
if (typeof result === 'object' && !Array.isArray(result) && result.hasOwnProperty(dataKey)) {
if (ignoreDataKey) {
body = result;
}
else if (typeof result === 'object' && !Array.isArray(result) && result.hasOwnProperty(dataKey)) {
body = result;
}
else if (result instanceof Error) {
Expand Down
1 change: 1 addition & 0 deletions dist/interfaces/ModuleDecoratorOptions.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export interface ModuleDecoratorOptions {
prefix?: string;
dataKey?: string;
responseAsBody?: boolean;
table?: string[];
entity?: any;
entities?: any[];
Expand Down
2 changes: 1 addition & 1 deletion dist/interfaces/ModuleDecoratorOptions.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@notores/core",
"version": "0.5.1",
"version": "0.6.0-beta.0",
"description": "Notores core module",
"main": "dist/index.js",
"repository": "git@github.com:notores/core.git",
Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
export const ROOT_ROUTE = 'ROOT_ROUTE';
export const DATA_KEY = 'DATA_KEY';
export const MODULE_PATH = 'MODULE_PATH';
export const IGNORE_DATA_KEY = 'IGNORE_DATA_KEY';

/**
* HTTP METHOD CONSTANTS
Expand Down
6 changes: 4 additions & 2 deletions src/decorators/Module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'reflect-metadata'
import {DATA_KEY, MODULE_PATH, ROOT_ROUTE} from "../constants";
import {DATA_KEY, IGNORE_DATA_KEY, MODULE_PATH, ROOT_ROUTE} from '../constants';
import {NotoresApplication} from "../Notores";
import {repositoryMetadataKey} from "../symbols";
import { ModuleDecoratorOptions } from '../interfaces/ModuleDecoratorOptions';
Expand All @@ -21,7 +21,8 @@ export function Module(settings?: ModuleDecoratorOptions | string): ClassDecorat
settings = {
prefix: settings || '/',
dataKey,
table: []
table: [],
responseAsBody: false,
}
} else {
settings = {
Expand All @@ -47,6 +48,7 @@ export function Module(settings?: ModuleDecoratorOptions | string): ClassDecorat

target[ROOT_ROUTE] = settings?.prefix?.startsWith('/') ? settings.prefix : `/${settings.prefix}`;
target[DATA_KEY] = settings.dataKey;
target[IGNORE_DATA_KEY] = settings.responseAsBody;
target[MODULE_PATH] = filePath;
}
}
Expand Down
12 changes: 9 additions & 3 deletions src/decorators/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {generateRoutingParameters, ParamTypes, routingParameterDecorators} from
import {getConfig} from "../lib/config";
import {SystemLogger} from "../Notores";
import {HttpMethod} from "../lib/ApiMetaData";
import {DATA_KEY, MODULE_PATH, ROOT_ROUTE} from "../constants";
import {DATA_KEY, IGNORE_DATA_KEY, MODULE_PATH, ROOT_ROUTE} from "../constants";
import MiddlewareMetaData from "../lib/MiddlewareMetaData";

export const paths: { [key: string]: any } = [];
Expand All @@ -31,6 +31,8 @@ export function bindControllers(server: IServer, controllers: Function[]) {
// @ts-ignore
const dataKey: string = Clazz[DATA_KEY];
// @ts-ignore
const ignoreDataKey: string = Clazz[IGNORE_DATA_KEY];
// @ts-ignore
const modulePath: string = Clazz[MODULE_PATH];

if (!rootRoute || !rootRoute.startsWith('/')) {
Expand All @@ -56,7 +58,9 @@ export function bindControllers(server: IServer, controllers: Function[]) {
if (result) {
let body;

if (typeof result === 'object' && !Array.isArray(result) && result.hasOwnProperty(dataKey)) {
if (ignoreDataKey) {
body = result;
} else if (typeof result === 'object' && !Array.isArray(result) && result.hasOwnProperty(dataKey)) {
body = result;
} else if (result instanceof Error) {
body = {error: result.message};
Expand Down Expand Up @@ -125,7 +129,9 @@ export function bindControllers(server: IServer, controllers: Function[]) {
return next();
}

if (typeof result === 'object' && !Array.isArray(result) && result.hasOwnProperty(dataKey)) {
if (ignoreDataKey) {
body = result;
} else if (typeof result === 'object' && !Array.isArray(result) && result.hasOwnProperty(dataKey)) {
body = result;
} else if (result instanceof Error) {
body = {error: result.message};
Expand Down
1 change: 1 addition & 0 deletions src/interfaces/ModuleDecoratorOptions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export interface ModuleDecoratorOptions {
prefix?: string;
dataKey?:string;
responseAsBody?: boolean;
table?: string[];
entity?: any;
entities?: any[];
Expand Down
Loading