@openbox/shared-types 0.1.17 → 0.1.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +12 -0
- package/.prettierrc +4 -0
- package/.vscode/settings.json +8 -0
- package/package.json +18 -3
- package/src/index.ts +3 -0
- package/src/interfaces.ts +17 -0
- package/src/services/GetMany/Request.ts +75 -0
- package/src/services/GetMany/Response.ts +14 -0
- package/src/services/GetMany/index.ts +4 -0
- package/src/services/index.ts +3 -0
- package/src/tools.ts +32 -0
- package/index.ts +0 -2
- package/modules/services.ts +0 -17
package/.eslintrc.json
ADDED
package/.prettierrc
ADDED
package/package.json
CHANGED
|
@@ -1,11 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openbox/shared-types",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.19",
|
|
4
4
|
"description": "Shared Types for Openbox Cloud. ",
|
|
5
|
-
"
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "src/index.ts",
|
|
6
7
|
"author": "Openbox Development Team",
|
|
7
8
|
"license": "ISC",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"lint": "eslint --ext .ts,.tsx --ignore-path .gitignore .",
|
|
11
|
+
"lint:fix": "npm run lint -- --fix"
|
|
12
|
+
},
|
|
8
13
|
"dependencies": {
|
|
9
|
-
"
|
|
14
|
+
"@nestjs/common": "^9.2.1",
|
|
15
|
+
"class-transformer": "^0.5.1",
|
|
16
|
+
"class-validator": "^0.14.0"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@typescript-eslint/eslint-plugin": "^5.46.1",
|
|
20
|
+
"@typescript-eslint/parser": "^5.46.1",
|
|
21
|
+
"eslint": "^8.30.0",
|
|
22
|
+
"eslint-config-prettier": "^8.5.0",
|
|
23
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
24
|
+
"prettier": "^2.8.1"
|
|
10
25
|
}
|
|
11
26
|
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export class IFilter {
|
|
2
|
+
limit?: number
|
|
3
|
+
page?: number
|
|
4
|
+
search?: string
|
|
5
|
+
prop?: string
|
|
6
|
+
order?: string
|
|
7
|
+
active?: boolean
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface IResponse {
|
|
11
|
+
id?: string | number
|
|
12
|
+
data?: Record<string, any> | Record<string, any>[]
|
|
13
|
+
message?: string
|
|
14
|
+
count?: number
|
|
15
|
+
page?: number
|
|
16
|
+
limit?: number
|
|
17
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { BadRequestException } from '@nestjs/common'
|
|
2
|
+
import { Transform } from 'class-transformer'
|
|
3
|
+
import {
|
|
4
|
+
ArrayNotEmpty,
|
|
5
|
+
IsArray,
|
|
6
|
+
IsBoolean,
|
|
7
|
+
IsDecimal,
|
|
8
|
+
IsInt,
|
|
9
|
+
IsOptional,
|
|
10
|
+
} from 'class-validator'
|
|
11
|
+
import { IFilter } from '../../interfaces'
|
|
12
|
+
import { validationMessage } from '../../tools'
|
|
13
|
+
|
|
14
|
+
export class GetServicesRequest extends IFilter {
|
|
15
|
+
@IsOptional()
|
|
16
|
+
@IsInt()
|
|
17
|
+
@Transform(({ value }) => parseInt(value))
|
|
18
|
+
limit?: number
|
|
19
|
+
|
|
20
|
+
@IsOptional()
|
|
21
|
+
@IsInt()
|
|
22
|
+
@Transform(({ value }) => parseInt(value))
|
|
23
|
+
page?: number
|
|
24
|
+
|
|
25
|
+
@IsOptional()
|
|
26
|
+
search?: string
|
|
27
|
+
|
|
28
|
+
@IsOptional()
|
|
29
|
+
prop?: string
|
|
30
|
+
|
|
31
|
+
@IsOptional()
|
|
32
|
+
order?: string
|
|
33
|
+
|
|
34
|
+
@IsOptional()
|
|
35
|
+
@Transform(({ value }) =>
|
|
36
|
+
value.toLowerCase() === 'true'
|
|
37
|
+
? true
|
|
38
|
+
: value.toLowerCase() == 'false'
|
|
39
|
+
? false
|
|
40
|
+
: 1
|
|
41
|
+
)
|
|
42
|
+
@IsBoolean({ message: validationMessage('active', 'IsBoolean') })
|
|
43
|
+
active?: boolean
|
|
44
|
+
|
|
45
|
+
@IsOptional()
|
|
46
|
+
@Transform(({ value }) => {
|
|
47
|
+
try {
|
|
48
|
+
return JSON.parse(value).map((v) => parseInt(v))
|
|
49
|
+
} catch (error) {
|
|
50
|
+
throw new BadRequestException(
|
|
51
|
+
'El elemento enviado no corresponde a un arreglo de numeros.'
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
})
|
|
55
|
+
@IsArray({ message: validationMessage('types', 'IsArray') })
|
|
56
|
+
@ArrayNotEmpty({ message: validationMessage('types', 'ArrayNotEmpty') })
|
|
57
|
+
@IsInt({ each: true, message: validationMessage('types', 'IsInt') })
|
|
58
|
+
types?: number[]
|
|
59
|
+
|
|
60
|
+
@IsOptional()
|
|
61
|
+
@Transform(({ value }) => parseFloat(value).toFixed(2))
|
|
62
|
+
@IsDecimal(
|
|
63
|
+
{ decimal_digits: '2' },
|
|
64
|
+
{ message: validationMessage('fromAmount', 'IsDecimal') }
|
|
65
|
+
)
|
|
66
|
+
fromAmount?: number
|
|
67
|
+
|
|
68
|
+
@IsOptional()
|
|
69
|
+
@Transform(({ value }) => parseFloat(value).toFixed(2))
|
|
70
|
+
@IsDecimal(
|
|
71
|
+
{ decimal_digits: '2' },
|
|
72
|
+
{ message: validationMessage('toAmount', 'IsDecimal') }
|
|
73
|
+
)
|
|
74
|
+
toAmount?: number
|
|
75
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Expose } from 'class-transformer'
|
|
2
|
+
import { IResponse } from '../../interfaces'
|
|
3
|
+
|
|
4
|
+
class IManyServicesResponse {
|
|
5
|
+
@Expose() id: string
|
|
6
|
+
@Expose() name: string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export class GetServicesResponse implements IResponse {
|
|
10
|
+
data: IManyServicesResponse[]
|
|
11
|
+
count: number
|
|
12
|
+
page: number
|
|
13
|
+
limit: number
|
|
14
|
+
}
|
package/src/tools.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export function validationMessage(fieldname: string, type: string): string {
|
|
2
|
+
switch (type) {
|
|
3
|
+
case 'IsBoolean':
|
|
4
|
+
return `El campo '${fieldname}' debe ser del valor true o false`
|
|
5
|
+
case 'IsInt':
|
|
6
|
+
return `El campo '${fieldname}' debe ser un numero entero.`
|
|
7
|
+
case 'IsNotEmpty':
|
|
8
|
+
return `El campo '${fieldname}' es requerido.`
|
|
9
|
+
case 'IsString':
|
|
10
|
+
return `El campo '${fieldname}' debe ser del tipo texto.`
|
|
11
|
+
case 'IsISO8601':
|
|
12
|
+
return `El campo '${fieldname}' debe ser una fecha en el formato yyyy-MM-dd.`
|
|
13
|
+
case 'IsUUID':
|
|
14
|
+
return `El campo '${fieldname}' debe ser del tipo uuid.`
|
|
15
|
+
case 'IsNumber':
|
|
16
|
+
return `El campo '${fieldname}' debe ser un numero y debe contener dos decimales.`
|
|
17
|
+
case 'IsArray':
|
|
18
|
+
return `El campo '${fieldname}' debe ser de tipo arreglo.`
|
|
19
|
+
case 'ArrayNotEmpty':
|
|
20
|
+
return `El arreglo '${fieldname}' debe contener minimo un elemento.`
|
|
21
|
+
case 'status':
|
|
22
|
+
return `La venta no puede ser ${fieldname} porque tiene un estado que no lo permite.`
|
|
23
|
+
case 'IsDecimal':
|
|
24
|
+
return `El campo '${fieldname}' debe ser un numero y debe contener dos decimales.`
|
|
25
|
+
case 'IsEnum':
|
|
26
|
+
return `El campo '${fieldname}' debe ser 'automatic' o 'manual'.`
|
|
27
|
+
case 'IsEmail':
|
|
28
|
+
return `El campo '${fieldname}' debe tener un formato de correo correcto.`
|
|
29
|
+
case 'IsNumberArray':
|
|
30
|
+
return `El campo '${fieldname}' debe ser un arreglo de numeros.`
|
|
31
|
+
}
|
|
32
|
+
}
|
package/index.ts
DELETED
package/modules/services.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Expose } from 'class-transformer';
|
|
2
|
-
|
|
3
|
-
class IManyServicesResponse {
|
|
4
|
-
@Expose() id: string;
|
|
5
|
-
@Expose() name: string;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export class DTOGetServicesResponse {
|
|
9
|
-
data: IManyServicesResponse[];
|
|
10
|
-
count: number;
|
|
11
|
-
page: number;
|
|
12
|
-
limit: number;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export default {
|
|
16
|
-
DTOGetManyResponse: DTOGetServicesResponse,
|
|
17
|
-
};
|