Skip to content

Commit

Permalink
fix: make controller options optional
Browse files Browse the repository at this point in the history
  • Loading branch information
etienne-bechara committed Apr 21, 2021
1 parent 4cc80bb commit c425955
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions source/orm/orm.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export abstract class OrmController<Entity> {

public constructor(
public readonly entityService: OrmService<Entity>,
protected readonly controllerOptions: OrmControllerOptions,
protected readonly controllerOptions: OrmControllerOptions = { },
) { }

/**
Expand All @@ -26,7 +26,7 @@ export abstract class OrmController<Entity> {
*/
private async validateRequest(params: OrmRequestValidation): Promise<OrmValidationData> {
const options = this.controllerOptions;
let queryData, queryOptions;
options.methods ??= [ 'GET', 'GET:id', 'POST', 'PUT', 'PUT:id', 'PATCH:id', 'DELETE:id' ];
options.dto ??= { };

if (!options.methods.includes(params.method)) {
Expand All @@ -41,6 +41,8 @@ export abstract class OrmController<Entity> {
await this.plainToDto(params.update, options.dto.update);
}

let queryData, queryOptions;

if (params.read && options.dto.read) {
const paginationProperties = [ 'sort', 'order', 'limit', 'offset' ];
const parsedQuery = this.parseFilterOperators(params.read);
Expand Down
2 changes: 1 addition & 1 deletion source/orm/orm.interface/orm.controller.options.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { OrmControllerMethod } from '../orm.enum';

export interface OrmControllerOptions {
methods: OrmControllerMethod[];
methods?: OrmControllerMethod[];
dto?: OrmControllerDto;
}

Expand Down

0 comments on commit c425955

Please sign in to comment.