pwi-plata-type 0.1.3 → 0.1.6

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.
Files changed (2) hide show
  1. package/libs/model.ts +10 -17
  2. package/package.json +1 -1
package/libs/model.ts CHANGED
@@ -92,7 +92,6 @@ export function _filtraModel(value: any, model: Model): any {
92
92
 
93
93
  export async function _validaModel(value: any, model: Model, name?: string): Promise<ErroValidacao[]> {
94
94
  let promises: any[] = []
95
- let errors: ErroValidacao[] = []
96
95
 
97
96
  for(const campo in model.template) {
98
97
  const t = model.template[campo]
@@ -100,7 +99,7 @@ export async function _validaModel(value: any, model: Model, name?: string): Pro
100
99
  if (t.length === undefined) {
101
100
  const m = new Model(t as ModelType)
102
101
 
103
- promises.push(_validaModel(value[campo], m, `${campo}.`))
102
+ promises.push(_validaModel(value[campo], m, `${name ?? ''}${campo}.`))
104
103
  continue
105
104
  }
106
105
 
@@ -140,15 +139,11 @@ export async function _validaModel(value: any, model: Model, name?: string): Pro
140
139
  )
141
140
 
142
141
  if ((Erros as any).errorID !== undefined) {
143
- errors.push(Erros as ErroValidacao)
144
-
145
- return errors
142
+ return Erros as ErroValidacao[]
146
143
  }
147
144
 
148
- errors = errors.concat(Erros)
149
-
150
- if (errors.length !== 0) {
151
- return errors
145
+ if ((Erros as any[]).length !== 0) {
146
+ return Erros as ErroValidacao[]
152
147
  }
153
148
 
154
149
  promises = []
@@ -158,7 +153,7 @@ export async function _validaModel(value: any, model: Model, name?: string): Pro
158
153
  }
159
154
 
160
155
  Erros = await Promise.all(promises).then(
161
- result => [].concat(...result),
156
+ result => [].concat(...result).filter(v => v !== null),
162
157
  err => {
163
158
  return {
164
159
  errorID: 'BPLM0003',
@@ -169,12 +164,10 @@ export async function _validaModel(value: any, model: Model, name?: string): Pro
169
164
  )
170
165
 
171
166
  if ((Erros as any).errorID !== undefined) {
172
- errors.push(Erros as ErroValidacao)
173
-
174
- return errors
167
+ return Erros as ErroValidacao[]
175
168
  }
176
169
 
177
- return errors.concat(Erros)
170
+ return Erros as ErroValidacao[]
178
171
  }
179
172
 
180
173
  export async function valida(value: any, model: Model): Promise<RetornoValicadaoModel> {
@@ -306,7 +299,7 @@ export function Int(): ModelValicacaoPrimitivo {
306
299
 
307
300
  export function isArray(tamanhoMaximo?: number): ModelValicacaoPrimitivo {
308
301
  return async (nome: string, valor: any) => {
309
- if (valor === undefined) {
302
+ if (valor === null) {
310
303
  return {
311
304
  error: {
312
305
  errorID: "BPCVARR001",
@@ -354,7 +347,7 @@ export function Optional(): ModelValicacaoPrimitivo {
354
347
 
355
348
  export function Required(): ModelValicacaoPrimitivo {
356
349
  return async (nome: string, valor: any) => {
357
- if (valor === undefined) {
350
+ if (valor === null) {
358
351
  return {
359
352
  error: {
360
353
  errorID: "BPCVREQ001",
@@ -463,7 +456,7 @@ export function VarChar(size: number): ModelValicacaoPrimitivo {
463
456
  return {
464
457
  error: {
465
458
  errorID: "BPVVARC001",
466
- msg: `O campo ${nome} tem que menos de ${nome} caracteres`
459
+ msg: `O campo ${nome} tem que menos de ${size} caracteres`
467
460
  },
468
461
  continua: false
469
462
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pwi-plata-type",
3
- "version": "0.1.3",
3
+ "version": "0.1.6",
4
4
  "type": "module",
5
5
  "main": "index.ts",
6
6
  "bin": {