@ -32,16 +32,16 @@ export const validateDocument = (collectionName: CollectionsEnum, documentToVali
export const validateOffer = ( documentToValidate ) : any = > {
export const validateOffer = ( documentToValidate ) : any = > {
if ( ! documentToValidate . hasOwnProperty ( CollectionFieldsEnum . BOLT12 ) ) {
if ( ! documentToValidate . hasOwnProperty ( CollectionFieldsEnum . BOLT12 ) ) {
return ( { isValid : false , error : CollectionFieldsEnum.BOLT12 + ' is mandatory.' } ) ;
return ( { isValid : false , error : 'Bolt12 is mandatory.' } ) ;
}
}
if ( ! documentToValidate . hasOwnProperty ( CollectionFieldsEnum . AMOUNTMSAT ) ) {
if ( ! documentToValidate . hasOwnProperty ( CollectionFieldsEnum . AMOUNTMSAT ) ) {
return ( { isValid : false , error : CollectionFieldsEnum.AMOUNTMSAT + ' is mandatory.' } ) ;
return ( { isValid : false , error : 'Amount mSat is mandatory.' } ) ;
}
}
if ( ! documentToValidate . hasOwnProperty ( CollectionFieldsEnum . TITLE ) ) {
if ( ! documentToValidate . hasOwnProperty ( CollectionFieldsEnum . TITLE ) ) {
return ( { isValid : false , error : CollectionFieldsEnum.TITLE + ' is mandatory.' } ) ;
return ( { isValid : false , error : 'Title is mandatory.' } ) ;
}
}
if ( ( typeof documentToValidate [ CollectionFieldsEnum . AMOUNTMSAT ] !== 'number' ) ) {
if ( ( typeof documentToValidate [ CollectionFieldsEnum . AMOUNTMSAT ] !== 'number' ) ) {
return ( { isValid : false , error : CollectionFieldsEnum.AMOUNTMSAT + ' should be a number.' } ) ;
return ( { isValid : false , error : 'Amount mSat should be a number.' } ) ;
}
}
return ( { isValid : true } ) ;
return ( { isValid : true } ) ;
} ;
} ;
@ -88,37 +88,37 @@ export class PageSettings {
export const validatePageSettings = ( documentToValidate ) : any = > {
export const validatePageSettings = ( documentToValidate ) : any = > {
let errorMessages = '' ;
let errorMessages = '' ;
if ( ! documentToValidate . hasOwnProperty ( CollectionFieldsEnum . PAGE_ID ) ) {
if ( ! documentToValidate . hasOwnProperty ( CollectionFieldsEnum . PAGE_ID ) ) {
errorMessages = errorMessages + CollectionFieldsEnum . PAGE_ID + ' is mandatory.';
errorMessages = errorMessages + 'Page ID is mandatory.';
}
}
if ( ! documentToValidate . hasOwnProperty ( CollectionFieldsEnum . TABLES ) ) {
if ( ! documentToValidate . hasOwnProperty ( CollectionFieldsEnum . TABLES ) ) {
errorMessages = errorMessages + CollectionFieldsEnum . TABLES + ' is mandatory.';
errorMessages = errorMessages + 'Tables is mandatory.';
}
}
const tablesMessages = documentToValidate . tables . reduce ( ( tableAcc , table : TableSetting , tableIdx ) = > {
const tablesMessages = documentToValidate . tables . reduce ( ( tableAcc , table : TableSetting , tableIdx ) = > {
let errMsg = '' ;
let errMsg = '' ;
if ( ! table . hasOwnProperty ( CollectionFieldsEnum . TABLE_ID ) ) {
if ( ! table . hasOwnProperty ( CollectionFieldsEnum . TABLE_ID ) ) {
errMsg = errMsg + CollectionFieldsEnum . TABLE_ID + ' is mandatory.';
errMsg = errMsg + 'Table ID is mandatory.';
}
}
if ( ! table . hasOwnProperty ( CollectionFieldsEnum . SORT_BY ) ) {
if ( ! table . hasOwnProperty ( CollectionFieldsEnum . SORT_BY ) ) {
errMsg = errMsg + CollectionFieldsEnum . SORT_BY + ' is mandatory.';
errMsg = errMsg + 'Sort By is mandatory.';
}
}
if ( ! table . hasOwnProperty ( CollectionFieldsEnum . SORT_ORDER ) ) {
if ( ! table . hasOwnProperty ( CollectionFieldsEnum . SORT_ORDER ) ) {
errMsg = errMsg + CollectionFieldsEnum . SORT_ORDER + ' is mandatory.';
errMsg = errMsg + 'Sort Order is mandatory.';
}
}
if ( ! table . hasOwnProperty ( CollectionFieldsEnum . RECORDS_PER_PAGE ) ) {
if ( ! table . hasOwnProperty ( CollectionFieldsEnum . RECORDS_PER_PAGE ) ) {
errMsg = errMsg + CollectionFieldsEnum . RECORDS_PER_PAGE + ' is mandatory.';
errMsg = errMsg + 'Records/Page is mandatory.';
}
}
if ( ! table . hasOwnProperty ( CollectionFieldsEnum . SHOW_COLUMNS ) ) {
if ( ! table . hasOwnProperty ( CollectionFieldsEnum . SHOW_COLUMNS ) ) {
errMsg = errMsg + CollectionFieldsEnum . SHOW_COLUMNS + ' is mandatory.';
errMsg = errMsg + 'Show Columns is mandatory.';
}
}
if ( table [ CollectionFieldsEnum . SHOW_COLUMNS ] . length < 2 ) {
if ( table [ CollectionFieldsEnum . SHOW_COLUMNS ] . length < 2 ) {
errMsg = errMsg + CollectionFieldsEnum . SHOW_COLUMNS + ' should have at least 2 fields.';
errMsg = errMsg + 'Show Columns should have at least 2 fields.';
}
}
if ( errMsg . trim ( ) !== '' ) {
if ( errMsg . trim ( ) !== '' ) {
tableAcc . push ( { table : ( table . hasOwnProperty ( CollectionFieldsEnum . TABLE_ID ) ? table [ CollectionFieldsEnum . TABLE_ID ] : ( tableIdx + 1 ) ) , message : errMsg } ) ;
tableAcc . push ( { table : ( table . hasOwnProperty ( CollectionFieldsEnum . TABLE_ID ) ? table [ CollectionFieldsEnum . TABLE_ID ] : ( tableIdx + 1 ) ) , message : errMsg } ) ;
}
}
return tableAcc ;
return tableAcc ;
} , [ ] ) ;
} , [ ] ) ;
if ( errorMessages . trim ( ) === '' && tablesMessages . length && tablesMessages . length === 0 ) {
if ( errorMessages . trim ( ) === '' && tablesMessages . length === 0 ) {
return ( { isValid : true } ) ;
return ( { isValid : true } ) ;
} else {
} else {
const errObj = { page : ( documentToValidate . hasOwnProperty ( CollectionFieldsEnum . PAGE_ID ) ? documentToValidate [ CollectionFieldsEnum . PAGE_ID ] : 'Unknown' ) } ;
const errObj = { page : ( documentToValidate . hasOwnProperty ( CollectionFieldsEnum . PAGE_ID ) ? documentToValidate [ CollectionFieldsEnum . PAGE_ID ] : 'Unknown' ) } ;