File tree Expand file tree Collapse file tree 4 files changed +26
-6
lines changed Expand file tree Collapse file tree 4 files changed +26
-6
lines changed Original file line number Diff line number Diff line change 1
- export const calendarEventsSchema = {
1
+ import { ValidationSchema } from './schema.model' ;
2
+
3
+ export const calendarEventsSchema : ValidationSchema = {
2
4
title : 'CalendarEvents' ,
3
5
type : 'array' ,
4
6
items : {
Original file line number Diff line number Diff line change 1
- export const contactsSchema = {
1
+ import { ValidationSchema } from './schema.model' ;
2
+
3
+ export const contactsSchema : ValidationSchema = {
2
4
title : 'Contacts' ,
3
5
type : 'array' ,
4
6
items : {
Original file line number Diff line number Diff line change
1
+ export type ValidationSchema = {
2
+ title : string ;
3
+ type : string ;
4
+ items : {
5
+ type : string ;
6
+ properties : unknown ;
7
+ required : string [ ] ;
8
+ } ;
9
+ } ;
Original file line number Diff line number Diff line change 1
1
import Ajv from 'ajv' ;
2
2
import { Config } from '../models' ;
3
3
import { errorLogger } from './logger.util' ;
4
+ import { ValidationSchema } from '../schemas/schema.model' ;
4
5
5
6
export function validate (
6
7
ajv : Ajv ,
7
- schemaKeyRef : object | string | boolean ,
8
+ schemaKeyRef : ValidationSchema ,
8
9
data : object ,
9
10
config : Config ,
10
11
) {
@@ -16,16 +17,22 @@ export function validate(
16
17
if ( ! valid ) {
17
18
errorLogger (
18
19
'validate' ,
19
- 'Validation failed' ,
20
- config ? .apiKey ,
20
+ ` ${ schemaKeyRef . type } : validation failed` ,
21
+ config . apiKey ,
21
22
ajv . errorsText ( ) ,
22
23
) ;
23
24
return false ;
24
25
}
25
26
26
27
return true ;
27
28
} catch ( e ) {
28
- console . error ( 'Error validating data' , e , ajv . errorsText ( ) ) ;
29
+ errorLogger (
30
+ 'validate' ,
31
+ 'Error validating data' ,
32
+ config . apiKey ,
33
+ e ,
34
+ ajv . errorsText ( ) ,
35
+ ) ;
29
36
// Ignore validation if validation is broken
30
37
return true ;
31
38
}
You can’t perform that action at this time.
0 commit comments