result-tsk
Advanced tools
Comparing version 2.1.1 to 2.1.2
@@ -94,1 +94,7 @@ # Changelog | ||
- Fix function name | ||
## [2.1.2] — 2022-04-29 | ||
### Feature | ||
- Function to validate if error was added |
@@ -18,4 +18,5 @@ import { Metadata } from "../Result.interface"; | ||
setError(error: string, statusCode: number | string): void; | ||
hasError(): boolean; | ||
setData(data: string | T, statusCode: number | string, message?: string): void; | ||
toResultDto(): ResultDto; | ||
} |
@@ -49,2 +49,5 @@ "use strict"; | ||
} | ||
hasError() { | ||
return !!this.error; | ||
} | ||
setData(data, statusCode, message) { | ||
@@ -51,0 +54,0 @@ this.data = data; |
@@ -16,3 +16,4 @@ import { Metadata, IResult } from "./Result.interface"; | ||
setError(error: string, statusCode: number | string): void; | ||
hasError(): boolean; | ||
toResultDto(): ResultDto; | ||
} |
@@ -11,2 +11,3 @@ import { ResultDto } from "./ResultDto"; | ||
setError(error: string, statusCode: number | string): void; | ||
hasError(): boolean; | ||
toResultDto(): ResultDto; | ||
@@ -13,0 +14,0 @@ setMetadata(headers: Metadata): void; |
@@ -49,2 +49,5 @@ "use strict"; | ||
} | ||
hasError() { | ||
return !!this.error; | ||
} | ||
toResultDto() { | ||
@@ -51,0 +54,0 @@ const result = new ResultDto_1.ResultDto(); |
export declare class ResultDto { | ||
message: string; | ||
error: string; | ||
data: any; | ||
data: unknown; | ||
} |
{ | ||
"name": "result-tsk", | ||
"version": "2.1.1", | ||
"version": "2.1.2", | ||
"description": "result tool for use with or without NodeTskeleton template project", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -37,2 +37,5 @@ # Result tool 🧰 | ||
} | ||
// Or | ||
if (result.hasError()) return result; | ||
const productDto = this.mapper.mapObject<Product, ProductDto>(product, new ProductDto()); | ||
@@ -68,2 +71,4 @@ // The result object also helps you with the response data. | ||
expect(result.statusCode).toBe(resultCodes.BAD_REQUEST); | ||
// Or you can create a ResultMock builder to do the following | ||
expect(result).toEqual(resultBuilder); | ||
}); | ||
@@ -70,0 +75,0 @@ ``` |
19368
253
154