-
-
Notifications
You must be signed in to change notification settings - Fork 281
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mvc): Improve the Required decorator
- Loading branch information
Showing
37 changed files
with
962 additions
and
449 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,12 @@ | ||
import {Storable} from "../../core/class/Storable"; | ||
import {NotEnumerable} from "../../core/decorators"; | ||
/** | ||
* @module common/converters | ||
*/ | ||
/** */ | ||
import {IPropertyOptions} from "../interfaces/IPropertyOptions"; | ||
|
||
export class PropertyMetadata extends Storable implements IPropertyOptions { | ||
/** | ||
* | ||
*/ | ||
@NotEnumerable() | ||
protected _required: boolean = false; | ||
|
||
constructor(target: any, propertyKey: any) { | ||
super(target, propertyKey); | ||
} | ||
|
||
/** | ||
* | ||
* @returns {boolean} | ||
*/ | ||
public get required(): boolean { | ||
return this._required; | ||
} | ||
|
||
/** | ||
* | ||
* @param value | ||
*/ | ||
public set required(value: boolean) { | ||
this._required = value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* @module common/mvc | ||
*/ | ||
/** */ | ||
|
||
import {BadRequest} from "ts-httpexceptions"; | ||
import {Type} from "../../core/interfaces"; | ||
import {nameOf} from "../../core/utils"; | ||
|
||
/** | ||
* @private | ||
*/ | ||
export class RequiredPropertyError extends BadRequest { | ||
|
||
constructor(target: Type<any>, propertyName: string | symbol) { | ||
super(RequiredPropertyError.buildMessage(target, propertyName)); | ||
} | ||
|
||
/** | ||
* | ||
* @returns {string} | ||
* @param target | ||
* @param propertyName | ||
*/ | ||
static buildMessage(target: Type<any>, propertyName: string | symbol) { | ||
return `Property ${propertyName} on class ${nameOf(target)} is required.`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* @module common/mvc | ||
*/ | ||
/** */ | ||
|
||
import {BadRequest} from "ts-httpexceptions"; | ||
import {Type} from "../../core/interfaces"; | ||
import {nameOf} from "../../core/utils"; | ||
|
||
/** | ||
* @private | ||
*/ | ||
export class UnknowPropertyError extends BadRequest { | ||
|
||
constructor(target: Type<any>, propertyName: string) { | ||
super(UnknowPropertyError.buildMessage(target, propertyName)); | ||
} | ||
|
||
/** | ||
* | ||
* @returns {string} | ||
* @param target | ||
* @param propertyName | ||
*/ | ||
static buildMessage(target: Type<any>, propertyName: string) { | ||
return `Property ${propertyName} on class ${nameOf(target)} is not allowed.`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.