Skip to content

Commit

Permalink
Make propertyClass mandatory in HasOne decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
safo6m committed Apr 24, 2023
1 parent f55b56b commit 7348ea0
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion projects/ngx-hal/src/lib/decorators/has-one.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { HasOneModelProperty } from '../interfaces/model-property.interface';
import { HalModel } from '../models/hal.model';
import { deepmergeWrapper } from '../utils/deepmerge-wrapper';

export function HasOne(options: HasOneOptions = {}) {
export function HasOne(options: HasOneOptions) {
return (model: HalModel, propertyName: string) => {
const hasOneOptions: HasOneOptions = deepmergeWrapper(DEFAULT_HAS_ONE_OPTIONS, options);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ModelConstructor, ModelConstructorFn } from '../types/model-constructor.type';

export interface AttributeOptions {
useClass?: boolean | string | ModelConstructor<any> | ModelConstructorFn<any>;
useClass?: string | ModelConstructor<any> | ModelConstructorFn<any>;
transformResponseValue?: (rawAttribute: any) => any;
transformBeforeSave?: (raw: any) => any;
externalName?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ModelConstructor, ModelConstructorFn } from '../types/model-constructor
export interface HasOneOptions {
externalName?: string;
includeInPayload?: boolean;
propertyClass?: string | ModelConstructor<any> | ModelConstructorFn<any>;
propertyClass: string | ModelConstructor<any> | ModelConstructorFn<any>;
}

export const DEFAULT_HAS_ONE_OPTIONS = {
Expand Down
1 change: 1 addition & 0 deletions projects/ngx-hal/src/lib/mocks/car.mock.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export class CarModel extends HalModel {
carName: string;

@HasOne({
propertyClass: MockModel2,
includeInPayload: true,
externalName: 'parentCompany',
})
Expand Down
1 change: 1 addition & 0 deletions projects/ngx-hal/src/lib/mocks/mock-model-templated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export class MockTemplatedModel extends HalModel {
prop1: string;

@HasOne({
propertyClass: MockModel2,
includeInPayload: true,
})
mockModel2Connection: MockModel2;
Expand Down

0 comments on commit 7348ea0

Please sign in to comment.