1+ import { SimpleSchema } from 'meteor/aldeed:simple-schema' ;
2+ import { TAPi18n } from 'meteor/tap:i18n' ;
13import { ApiMetadata } from '/metadata/collection' ;
24
35ApiMetadata . schema = new SimpleSchema ( {
46 // TODO: migrate to use 'apiId' instead of 'apiBackendId'
5- ' apiBackendId' : {
7+ apiBackendId : {
68 type : String ,
79 regEx : SimpleSchema . RegEx . Id ,
810 } ,
9- ' organization' : {
11+ organization : {
1012 type : Object ,
1113 optional : true ,
1214 } ,
@@ -18,7 +20,7 @@ ApiMetadata.schema = new SimpleSchema({
1820 type : String ,
1921 optional : true ,
2022 } ,
21- ' contact' : {
23+ contact : {
2224 type : Object ,
2325 optional : true ,
2426 } ,
@@ -34,7 +36,7 @@ ApiMetadata.schema = new SimpleSchema({
3436 type : String ,
3537 optional : true ,
3638 } ,
37- ' service' : {
39+ service : {
3840 type : Object ,
3941 optional : true ,
4042 } ,
@@ -49,17 +51,46 @@ ApiMetadata.schema = new SimpleSchema({
4951 'service.validSince' : {
5052 type : Date ,
5153 optional : true ,
54+ autoform : {
55+ type : 'bootstrap-datepicker' ,
56+ } ,
5257 } ,
5358 'service.validUntil' : {
5459 type : Date ,
5560 optional : true ,
61+ autoform : {
62+ type : 'bootstrap-datepicker' ,
63+ } ,
64+ custom ( ) {
65+ let validation ;
66+ const validSince = this . field ( 'service.validSince' ) . value ;
67+ const validUntil = this . value ;
68+
69+ // validUntil must be after validSince
70+ if (
71+ ( validSince instanceof Date ) &&
72+ ( validUntil instanceof Date ) &&
73+ validUntil < validSince
74+ ) {
75+ validation = 'dateError' ;
76+ }
77+ return validation ;
78+ } ,
5679 } ,
5780 'service.serviceLevelAgreement' : {
5881 type : String ,
5982 optional : true ,
6083 } ,
6184} ) ;
6285
86+ // Fetch dateInvalid message
87+ const dateInvalid = TAPi18n . __ ( 'apiMetadata_dateInvalid' ) ;
88+
89+ // Define custom validation error messages
90+ ApiMetadata . schema . messages ( {
91+ dateError : dateInvalid ,
92+ } ) ;
93+
6394// Enable translations (i18n)
6495ApiMetadata . schema . i18n ( 'schemas.apiMetadata' ) ;
6596
0 commit comments