@openbox/shared-types 0.1.16 → 0.1.18

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 ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "parser": "@typescript-eslint/parser",
3
+ "parserOptions": {
4
+ "project": "./tsconfig.json"
5
+ },
6
+ "extends": [
7
+ "plugin:@typescript-eslint/recommended",
8
+ "eslint-config-prettier",
9
+ "plugin:prettier/recommended"
10
+ ],
11
+ "rules": {}
12
+ }
package/.prettierrc ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "singleQuote": true,
3
+ "semi": false
4
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "[vue][javascript][typescript][json][jsonc]": {
3
+ "editor.codeActionsOnSave": {
4
+ "source.fixAll.eslint": true,
5
+ "source.organizeImports": true
6
+ },
7
+ }
8
+ }
package/package.json CHANGED
@@ -1,11 +1,25 @@
1
1
  {
2
2
  "name": "@openbox/shared-types",
3
- "version": "0.1.16",
3
+ "version": "0.1.18",
4
4
  "description": "Shared Types for Openbox Cloud. ",
5
- "main": "index.ts",
5
+ "main": "src/index.ts",
6
6
  "author": "Openbox Development Team",
7
7
  "license": "ISC",
8
+ "scripts": {
9
+ "lint": "eslint --ext .ts,.tsx --ignore-path .gitignore .",
10
+ "lint:fix": "npm run lint -- --fix"
11
+ },
8
12
  "dependencies": {
9
- "class-transformer": "^0.5.1"
13
+ "@nestjs/common": "^9.2.1",
14
+ "class-transformer": "^0.5.1",
15
+ "class-validator": "^0.14.0"
16
+ },
17
+ "devDependencies": {
18
+ "@typescript-eslint/eslint-plugin": "^5.46.1",
19
+ "@typescript-eslint/parser": "^5.46.1",
20
+ "eslint": "^8.30.0",
21
+ "eslint-config-prettier": "^8.5.0",
22
+ "eslint-plugin-prettier": "^4.2.1",
23
+ "prettier": "^2.8.1"
10
24
  }
11
25
  }
package/src/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { GetServicesRequest, GetServicesResponse } from './services'
2
+
3
+ export { GetServicesRequest, GetServicesResponse }
@@ -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
+ }
@@ -0,0 +1,4 @@
1
+ import { GetServicesRequest } from './Request'
2
+ import { GetServicesResponse } from './Response'
3
+
4
+ export { GetServicesRequest, GetServicesResponse }
@@ -0,0 +1,3 @@
1
+ import { GetServicesRequest, GetServicesResponse } from './GetMany'
2
+
3
+ export { GetServicesRequest, GetServicesResponse }
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
@@ -1,2 +0,0 @@
1
- import { DTOGetServicesResponse } from './modules/services';
2
- export { DTOGetServicesResponse };
@@ -1,13 +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
- }