@@ -331,8 +331,8 @@ module.exports = function() {
331
331
}
332
332
if ( tables . length > 0 ) {
333
333
// filtering out private '_Tables'
334
- tables = tables . filter ( function ( table ) {
335
- return table . name [ 0 ] !== '_' ;
334
+ tables = tables . filter ( function ( table ) {
335
+ return table . name [ 0 ] !== '_' ;
336
336
} ) ;
337
337
console . log ( "Tables found..." ) ;
338
338
deferred . resolve ( tables ) ;
@@ -525,11 +525,13 @@ module.exports = function() {
525
525
tableType = "device" ;
526
526
} else if ( tableName === "_File" ) {
527
527
tableType = "file" ;
528
+ } else if ( tableName === "_Event" ) {
529
+ tableType = "event" ;
528
530
} else {
529
531
tableType = "custom" ;
530
532
}
531
533
532
- if ( tableType === 'user' || tableType === 'role' || tableType === 'device' || tableType === 'file' ) {
534
+ if ( tableType === 'user' || tableType === 'role' || tableType === 'device' || tableType === 'file' || tableType === 'event' ) {
533
535
maxCount = 1 ;
534
536
} else {
535
537
maxCount = 99999 ;
@@ -543,7 +545,7 @@ module.exports = function() {
543
545
544
546
//dataType check.
545
547
var defaultDataType = _getDefaultColumnWithDataType ( tableType ) ;
546
- var valid = _checkValidDataType ( schema , defaultDataType ) ;
548
+ var valid = _checkValidDataType ( schema , defaultDataType , tableType ) ;
547
549
if ( ! valid ) {
548
550
deferred . reject ( "Error : Invalid DataType Found." ) ;
549
551
return deferred . promise ;
@@ -731,7 +733,8 @@ module.exports = function() {
731
733
global . appService . upsertTable ( appId , 'Role' , tablesData . Role ) ,
732
734
global . appService . upsertTable ( appId , 'Device' , tablesData . Device ) ,
733
735
global . appService . upsertTable ( appId , 'User' , tablesData . User ) ,
734
- global . appService . upsertTable ( appId , '_File' , tablesData . _File )
736
+ global . appService . upsertTable ( appId , '_File' , tablesData . _File ) ,
737
+ global . appService . upsertTable ( appId , '_Event' , tablesData . _Event )
735
738
] ) ;
736
739
} ,
737
740
@@ -880,7 +883,7 @@ module.exports = function() {
880
883
var validated = false ;
881
884
882
885
try {
883
- fileData = JSON . parse ( file . toString ( ) ) ;
886
+ fileData = JSON . parse ( file . toString ( ) ) ;
884
887
for ( var k in fileData ) {
885
888
if ( fileData [ k ] . name == '_Schema' ) {
886
889
validated = true ;
@@ -916,9 +919,11 @@ module.exports = function() {
916
919
for ( var i in fileData ) {
917
920
( function ( i ) {
918
921
global . mongoClient . db ( appId ) . createCollection ( fileData [ i ] . name , function ( err , col ) {
919
- if ( err ) deferred . reject ( 'Error creating Collections/Tables' ) ;
922
+ if ( err )
923
+ deferred . reject ( 'Error creating Collections/Tables' ) ;
920
924
global . mongoClient . db ( appId ) . collection ( fileData [ i ] . name , function ( err , col ) {
921
- if ( err ) deferred . reject ( 'Error getting Collections/Tables' ) ;
925
+ if ( err )
926
+ deferred . reject ( 'Error getting Collections/Tables' ) ;
922
927
for ( var j in fileData [ i ] . documents [ 0 ] ) {
923
928
( function ( j ) {
924
929
col . insert ( fileData [ i ] . documents [ 0 ] [ j ] , function ( err ) {
@@ -957,7 +962,8 @@ module.exports = function() {
957
962
deferred . reject ( err ) ;
958
963
else
959
964
deferred . resolve ( { username : username , password : password } ) ;
960
- } ) ;
965
+ }
966
+ ) ;
961
967
return deferred . promise ;
962
968
}
963
969
@@ -1033,6 +1039,8 @@ function _getDefaultColumnList(type) {
1033
1039
defaultColumn . concat ( [ 'channels' , 'deviceToken' , 'deviceOS' , 'timezone' , 'metadata' ] ) ;
1034
1040
} else if ( type == 'file' ) {
1035
1041
defaultColumn . concat ( [ 'name' , 'contentType' , 'path' , 'url' , 'size' ] ) ;
1042
+ } else if ( type == 'event' ) {
1043
+ defaultColumn . concat ( [ 'user' , 'type' , 'name' , 'data' ] ) ;
1036
1044
}
1037
1045
return defaultColumn ;
1038
1046
@@ -1045,7 +1053,7 @@ function _getDefaultColumnList(type) {
1045
1053
}
1046
1054
}
1047
1055
1048
- function _checkValidDataType ( columns , deafultDataType ) {
1056
+ function _checkValidDataType ( columns , deafultDataType , tableType ) {
1049
1057
1050
1058
try {
1051
1059
var index ;
@@ -1128,11 +1136,22 @@ function _checkValidDataType(columns, deafultDataType) {
1128
1136
}
1129
1137
1130
1138
//name for role table
1131
- if ( key === 'name' ) {
1139
+ if ( key === 'name' && tableType === 'role' ) {
1132
1140
if ( columns [ index ] . relationType != null || columns [ index ] . required != true || columns [ index ] . unique != true || columns [ index ] . dataType != 'Text' )
1133
1141
return false ;
1134
1142
}
1135
1143
1144
+ //name for file table
1145
+ if ( key === 'name' && tableType === 'file' ) {
1146
+ if ( columns [ index ] . relationType != null || columns [ index ] . required != true || columns [ index ] . unique != false || columns [ index ] . dataType != 'Text' )
1147
+ return false ;
1148
+ }
1149
+ //name for event table
1150
+ if ( key === 'name' && tableType === 'event' ) {
1151
+ if ( columns [ index ] . relationType != null || columns [ index ] . required != true || columns [ index ] . unique != false || columns [ index ] . dataType != 'Text' )
1152
+ return false ;
1153
+ }
1154
+
1136
1155
//channels for device table
1137
1156
if ( key === 'channels' ) {
1138
1157
if ( columns [ index ] . relationType != null || columns [ index ] . required != false || columns [ index ] . unique != false || columns [ index ] . dataType != 'List' )
@@ -1184,9 +1203,34 @@ function _checkValidDataType(columns, deafultDataType) {
1184
1203
return false ;
1185
1204
}
1186
1205
1206
+ //user for event table
1207
+ if ( key === 'user' ) {
1208
+ if ( columns [ index ] . relationType != null || columns [ index ] . required != true || columns [ index ] . unique != false || columns [ index ] . dataType != 'Relation' )
1209
+ return false ;
1210
+ }
1211
+
1212
+ //type for event table
1213
+ if ( key === 'type' ) {
1214
+ if ( columns [ index ] . relationType != null || columns [ index ] . required != true || columns [ index ] . unique != false || columns [ index ] . dataType != 'Text' )
1215
+ return false ;
1216
+ }
1217
+
1218
+ //type for event table
1219
+ if ( key === 'type' ) {
1220
+ if ( columns [ index ] . relationType != null || columns [ index ] . required != true || columns [ index ] . unique != false || columns [ index ] . dataType != 'Text' )
1221
+ return false ;
1222
+ }
1223
+
1224
+ //data for event table
1225
+ if ( key === 'data' ) {
1226
+ if ( columns [ index ] . relationType != null || columns [ index ] . required != true || columns [ index ] . unique != false || columns [ index ] . dataType != 'Object' )
1227
+ return false ;
1228
+ }
1229
+
1187
1230
if ( columns [ index ] . isRenamable !== false || columns [ index ] . isEditable !== false || columns [ index ] . isDeletable !== false ) {
1188
1231
return false ;
1189
1232
}
1233
+
1190
1234
defaultColumns . push ( key ) ;
1191
1235
1192
1236
} //end of for-loop
@@ -1332,6 +1376,11 @@ function _getDefaultColumnWithDataType(type) {
1332
1376
defaultColumn [ 'url' ] = 'URL' ;
1333
1377
defaultColumn [ 'path' ] = 'Text' ;
1334
1378
defaultColumn [ 'contentType' ] = 'Text' ;
1379
+ } else if ( type == 'event' ) {
1380
+ defaultColumn [ 'user' ] = 'Relation' ;
1381
+ defaultColumn [ 'type' ] = 'Text' ;
1382
+ defaultColumn [ 'name' ] = 'Text' ;
1383
+ defaultColumn [ 'data' ] = 'Object' ;
1335
1384
}
1336
1385
return defaultColumn ;
1337
1386
0 commit comments