1
1
import { JoiValidationConstants } from './JoiValidationConstants' ;
2
- import { JoiValidationEntity } from './JoiValidationEntity ' ;
2
+ import { JoiValidationEntity_New } from '@shared/business/entities/joiValidationEntity/JoiValidationEntity_New ' ;
3
3
import { createISODateString } from '@shared/business/utilities/DateHandler' ;
4
4
import joi from 'joi' ;
5
5
6
- export class Batch extends JoiValidationEntity {
6
+ export class Batch extends JoiValidationEntity_New {
7
7
public batchId : string ;
8
8
public batchIndex : string ;
9
9
public createdAt : string ;
@@ -18,42 +18,33 @@ export class Batch extends JoiValidationEntity {
18
18
this . pages = rawBatch . pages || [ ] ;
19
19
}
20
20
21
- /**
22
- * adds a page to current Batch
23
- *
24
- * @param {object } page the page to add
25
- * @returns {Batch } the batch entity after the page is added
26
- */
27
- addPage ( page ) {
21
+ static VALIDATION_RULES = joi . object ( ) . keys ( {
22
+ batchId : JoiValidationConstants . UUID . required ( ) ,
23
+ batchIndex : joi
24
+ . number ( )
25
+ . integer ( )
26
+ . min ( 0 )
27
+ . required ( )
28
+ . messages ( { '*' : 'Invalid batch index' } ) ,
29
+ createdAt : JoiValidationConstants . ISO_DATE . required ( ) ,
30
+ pages : joi
31
+ . array ( )
32
+ . min ( 1 )
33
+ . required ( )
34
+ . messages ( { '*' : 'At least one page is required' } ) ,
35
+ } ) ;
36
+
37
+ addPage ( page ) : Batch {
28
38
this . pages . push ( page ) ;
29
39
return this ;
30
40
}
31
41
32
- /**
33
- * clears all pages within this Batch
34
- *
35
- * @returns {Batch } the batch entity after the pages are cleared
36
- */
37
- clear ( ) {
42
+ clear ( ) : Batch {
38
43
this . pages = [ ] ;
39
44
return this ;
40
45
}
41
46
42
- static VALIDATION_ERROR_MESSAGES = {
43
- batchIndex : 'Invalid batch index' ,
44
- pages : 'At least one page is required' ,
45
- } ;
46
-
47
47
getValidationRules ( ) {
48
- return joi . object ( ) . keys ( {
49
- batchId : JoiValidationConstants . UUID . required ( ) ,
50
- batchIndex : joi . number ( ) . integer ( ) . min ( 0 ) . required ( ) ,
51
- createdAt : JoiValidationConstants . ISO_DATE . required ( ) ,
52
- pages : joi . array ( ) . min ( 1 ) . required ( ) ,
53
- } ) ;
54
- }
55
-
56
- getErrorToMessageMap ( ) {
57
- return Batch . VALIDATION_ERROR_MESSAGES ;
48
+ return Batch . VALIDATION_RULES ;
58
49
}
59
50
}
0 commit comments