@bluedot-innovation/models 2.0.0-beta.1 → 2.0.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.nyc_output/d9020767349457a911ef2b431e357310.json +1 -0
- package/Models.js +27 -15
- package/__tests__/account/account.data.json +12 -0
- package/__tests__/account/account.rules.js +8 -0
- package/__tests__/account/account.spec.js +83 -0
- package/__tests__/action/message/messageAction.spec.js +1 -1
- package/__tests__/action/url/urlAction.spec.js +13 -1
- package/__tests__/dailyStats/checkDailyStats.js +22 -21
- package/__tests__/filter/bearing/bearingFilter.spec.js +1 -1
- package/__tests__/filter/calendarDateRange/calendarDateRangeFilter.spec.js +2 -2
- package/__tests__/filter/percentageCrossed/percentageCrossedFilter.spec.js +2 -2
- package/__tests__/filter/speed/speedFilter.spec.js +1 -1
- package/__tests__/filter/timeOfDayRange/timeOfDayRange.spec.js +1 -1
- package/__tests__/geofeature/beacon/beacon.spec.js +2 -2
- package/__tests__/geofeature/boundingBox/boundingBox.spec.js +3 -2
- package/__tests__/geofeature/circle/circle.spec.js +11 -2
- package/__tests__/geofeature/polygon/polygon.spec.js +11 -2
- package/__tests__/geofeature/polyline/polyline.spec.js +11 -2
- package/__tests__/monthlyStats/monthlyStats.spec.js +36 -8
- package/__tests__/project/project.data.json +14 -0
- package/__tests__/project/project.rules.json +9 -0
- package/__tests__/project/project.spec.js +81 -0
- package/__tests__/ruleRequestAggregation/ruleRequestAggregation.data.json +8 -0
- package/__tests__/ruleRequestAggregation/ruleRequestAggregation.spec.js +69 -0
- package/__tests__/user/user.data.js +13 -0
- package/__tests__/user/user.rules.js +8 -0
- package/__tests__/user/user.spec.js +83 -0
- package/__tests__/zone/zone.action.spec.js +1 -1
- package/__tests__/zone/zone.data.json +4 -2
- package/__tests__/zone/zone.filter.spec.js +1 -1
- package/__tests__/zone/zone.geofeatures.spec.js +1 -1
- package/__tests__/zone/zone.spec.js +10 -1
- package/helpers.js +14 -0
- package/models/Account.js +49 -0
- package/models/Beacon.js +1 -1
- package/models/BeaconFilter.js +1 -1
- package/models/BearingFilter.js +1 -1
- package/models/BoundingBox.js +2 -1
- package/models/CalendarDateRangeFilter.js +1 -1
- package/models/Circle.js +2 -1
- package/models/MessageAction.js +1 -1
- package/models/MonthlyStats.js +12 -7
- package/models/PercentageCrossedFilter.js +1 -1
- package/models/Polygon.js +2 -1
- package/models/Polyline.js +1 -1
- package/models/Project.js +54 -0
- package/models/RuleRequestAggregation.js +29 -10
- package/models/SpeedFilter.js +1 -1
- package/models/TimeOfDayRangeFilter.js +1 -1
- package/models/UrlAction.js +1 -1
- package/models/User.js +59 -0
- package/models/Zone.js +4 -4
- package/package.json +2 -2
- package/schemas/Webhook.js +22 -0
- package/yarn.lock +2796 -0
- package/.npmignore +0 -3
- package/.nyc_output/295801a153bad60b994d5c6b5a8016d9.json +0 -1
- package/.nyc_output/5fc62324d665599db6649363a937708e.json +0 -1
- package/.nyc_output/95eec4b77e4566b36a6300f0cf8bea0b.json +0 -1
- package/models/AdminUser.js +0 -11
- package/models/Application.js +0 -39
- package/models/Customer.js +0 -38
- package/package-lock.json +0 -3503
- /package/.nyc_output/{2963e30f6030a94b16dd86e7b5594ebe.json → b3865a46e2cec635045d586cfc79e5c6.json} +0 -0
package/models/MonthlyStats.js
CHANGED
|
@@ -6,12 +6,16 @@
|
|
|
6
6
|
|
|
7
7
|
const mongoose = require('mongoose')
|
|
8
8
|
const uuidv4 = require('uuid/v4')
|
|
9
|
+
const helpers = require('../helpers')
|
|
9
10
|
|
|
10
11
|
const schema = {
|
|
11
12
|
_id: { type: String, default: uuidv4 },
|
|
12
|
-
customerId: String,
|
|
13
|
-
totalMonthlyUsers: Number,
|
|
14
|
-
applications: [
|
|
13
|
+
customerId: {type: String, required: [true, 'customerId is required'], validate: {isAsync: false, validator: helpers.validateUUIDv4, msg: 'invalid customerId'}},
|
|
14
|
+
totalMonthlyUsers: {type: Number, required: [true, 'totalMonthlyUsers is required'], min: 0},
|
|
15
|
+
applications: [{
|
|
16
|
+
applicationId: {type: String, required: [true, 'applicationId is required'], validate: {isAsync: false, validator: helpers.validateUUIDv4, msg: 'invalid applicationId'}},
|
|
17
|
+
monthlyUsers: {type: Number, required: [true, 'monthlyUsers is required'], min: 0}
|
|
18
|
+
}],
|
|
15
19
|
countMonth: { type: Date, default: Date.now },
|
|
16
20
|
creationDate: { type: Date, default: Date.now }
|
|
17
21
|
}
|
|
@@ -25,15 +29,16 @@ const MonthlyStatsSchema = new mongoose.Schema(
|
|
|
25
29
|
)
|
|
26
30
|
|
|
27
31
|
// optional mongoose
|
|
28
|
-
|
|
32
|
+
let model = (mongooseInstance) => {
|
|
29
33
|
let MonthlyStats
|
|
30
34
|
if (mongooseInstance) {
|
|
31
|
-
MonthlyStats = mongooseInstance.model('
|
|
35
|
+
MonthlyStats = mongooseInstance.model('MonthlyStat', MonthlyStatsSchema)
|
|
32
36
|
} else {
|
|
33
|
-
MonthlyStats = mongoose.model('
|
|
37
|
+
MonthlyStats = mongoose.model('MonthlyStat', MonthlyStats)
|
|
34
38
|
}
|
|
35
39
|
|
|
36
40
|
return MonthlyStats
|
|
37
41
|
}
|
|
38
42
|
|
|
39
|
-
|
|
43
|
+
// Exports Mongoose Model, Mongoose Schema, JSON schema (required locally for discriminators)
|
|
44
|
+
module.exports = { Model: model, Schema: MonthlyStatsSchema }
|
|
@@ -31,4 +31,4 @@ let model = (mongooseInstance) => {
|
|
|
31
31
|
return PercentageCrossedFilter
|
|
32
32
|
}
|
|
33
33
|
// Exports Mongoose Model, Mongoose Schema, JSON schema (required locally for discriminators)
|
|
34
|
-
module.exports = {
|
|
34
|
+
module.exports = { Model: model, Schema: PercentageCrossedFilterSchema, percentageCrossedFilterSchema: schema }
|
package/models/Polygon.js
CHANGED
|
@@ -6,6 +6,7 @@ let uuidv4 = require('uuid/v4')
|
|
|
6
6
|
const schema = {
|
|
7
7
|
guid: {type: String, default: uuidv4},
|
|
8
8
|
name: {type: String, required: [true, 'name is required. ']},
|
|
9
|
+
color: String,
|
|
9
10
|
vertices: {type: [Point], required: [true, 'vertices is required. ']},
|
|
10
11
|
creationTime: {type: Date, default: Date.now},
|
|
11
12
|
lastUpdateTime: {type: Date, default: Date.now},
|
|
@@ -35,4 +36,4 @@ let model = (mongooseInstance) => {
|
|
|
35
36
|
return Polygon
|
|
36
37
|
}
|
|
37
38
|
// Exports Mongoose Model, Mongoose Schema, JSON schema (required locally for discriminators)
|
|
38
|
-
module.exports = {
|
|
39
|
+
module.exports = { Model: model, Schema: PolygonSchema, polygonSchema: schema }
|
package/models/Polyline.js
CHANGED
|
@@ -36,4 +36,4 @@ let model = (mongooseInstance) => {
|
|
|
36
36
|
return Polyline
|
|
37
37
|
}
|
|
38
38
|
// Exports Mongoose Model, Mongoose Schema, JSON schema (required locally for discriminators)
|
|
39
|
-
module.exports = {
|
|
39
|
+
module.exports = { Model: model, Schema: PolylineSchema, polylineSchema: schema }
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Created by Ryan W. Kan on 14/02/2018.
|
|
3
|
+
* Copyright : Bluedot Innovations.
|
|
4
|
+
* Owner :
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
let mongoose = require('mongoose')
|
|
8
|
+
let Schema = mongoose.Schema
|
|
9
|
+
let StateEnum = require('@bluedot-innovation/enums').StateEnum
|
|
10
|
+
let uuidv4 = require('uuid/v4')
|
|
11
|
+
let patcher = require('mongoose-json-patch')
|
|
12
|
+
let helpers = require('../helpers')
|
|
13
|
+
|
|
14
|
+
let WebhookSchema = require('../schemas/Webhook')
|
|
15
|
+
|
|
16
|
+
let ProjectSchema = new mongoose.Schema({
|
|
17
|
+
_id: {type: String, default: uuidv4},
|
|
18
|
+
state: {type: String, default: StateEnum.active},
|
|
19
|
+
nextRuleUpdateInterval: {
|
|
20
|
+
type: Number,
|
|
21
|
+
required: [true, 'nextRuleUpdateInterval is required'],
|
|
22
|
+
min: 5,
|
|
23
|
+
max: 172800,
|
|
24
|
+
validate: {
|
|
25
|
+
validator: Number.isInteger,
|
|
26
|
+
message: '{VALUE} is not a number'
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
lastUpdateTime: {type: Date, required: [true, 'lastUpdateTime is required']},
|
|
30
|
+
creationTime: {type: Date, required: [true, 'creationTime is required']},
|
|
31
|
+
name: {type: String, required: [true, 'name is required']},
|
|
32
|
+
accountId: {type: String, required: true, validate: {isAsync: false, validator: helpers.validateUUIDv4, msg: 'default error message'}},
|
|
33
|
+
webhooks: [WebhookSchema],
|
|
34
|
+
configurationParameters: {type: Schema.Types.Mixed, default: null}, // http://collab.bluedot.io/display/PD/Remote+configuration
|
|
35
|
+
firebaseApiKey: {type: String} // BP-491
|
|
36
|
+
},
|
|
37
|
+
{collection: 'project'})
|
|
38
|
+
|
|
39
|
+
ProjectSchema.plugin(patcher)
|
|
40
|
+
|
|
41
|
+
// optional mongoose
|
|
42
|
+
let model = (mongooseInstance) => {
|
|
43
|
+
let Project
|
|
44
|
+
if (mongooseInstance) {
|
|
45
|
+
Project = mongooseInstance.model('Project', ProjectSchema)
|
|
46
|
+
} else {
|
|
47
|
+
Project = mongoose.model('Project', ProjectSchema)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return Project
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Exports Mongoose Model, Mongoose Schema, JSON schema (required locally for discriminators)
|
|
54
|
+
module.exports = { Model: model, Schema: ProjectSchema }
|
|
@@ -3,19 +3,38 @@
|
|
|
3
3
|
* Copyright : Bluedot Innovations.
|
|
4
4
|
* Owner :
|
|
5
5
|
*/
|
|
6
|
-
|
|
6
|
+
const mongoose = require('mongoose')
|
|
7
|
+
const uuidv4 = require('uuid/v4')
|
|
8
|
+
const helpers = require('../helpers')
|
|
7
9
|
|
|
8
|
-
|
|
9
|
-
{
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
10
|
+
const schema = {
|
|
11
|
+
_id: { type: String, default: uuidv4 },
|
|
12
|
+
appplicationId: {type: String, required: [true, 'applicationId is required'], validate: {isAsync: false, validator: helpers.validateUUIDv4, msg: 'invalid applicationId'}},
|
|
13
|
+
customerId: {type: String, required: [true, 'customerId is required'], validate: {isAsync: false, validator: helpers.validateUUIDv4, msg: 'invalid customerId'}},
|
|
14
|
+
iosCount: {type: Number, required: [true, 'iosCount is required'], min: 0},
|
|
15
|
+
androidCount: {type: Number, required: [true, 'androidCount is required'], min: 0},
|
|
16
|
+
creationDate: { type: Date, default: Date.now }
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const RuleRequestAggregationSchema = new mongoose.Schema(
|
|
20
|
+
schema,
|
|
15
21
|
{
|
|
16
22
|
collection: 'ruleRequestAggregation',
|
|
17
23
|
versionKey: false
|
|
18
|
-
}
|
|
24
|
+
}
|
|
19
25
|
)
|
|
20
26
|
|
|
21
|
-
|
|
27
|
+
// optional mongoose
|
|
28
|
+
let model = (mongooseInstance) => {
|
|
29
|
+
let RuleRequestAggregation
|
|
30
|
+
if (mongooseInstance) {
|
|
31
|
+
RuleRequestAggregation = mongooseInstance.model('RuleRequestAggregation', RuleRequestAggregationSchema)
|
|
32
|
+
} else {
|
|
33
|
+
RuleRequestAggregation = mongoose.model('RuleRequestAggregation', RuleRequestAggregationSchema)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return RuleRequestAggregation
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Exports Mongoose Model, Mongoose Schema, JSON schema (required locally for discriminators)
|
|
40
|
+
module.exports = { Model: model, Schema: RuleRequestAggregationSchema }
|
package/models/SpeedFilter.js
CHANGED
|
@@ -44,4 +44,4 @@ let model = (mongooseInstance) => {
|
|
|
44
44
|
return SpeedFilter
|
|
45
45
|
}
|
|
46
46
|
// Exports Mongoose Model, Mongoose Schema, JSON schema (required locally for discriminators)
|
|
47
|
-
module.exports = {
|
|
47
|
+
module.exports = { Model: model, Schema: SpeedFilterSchema, speedFilterSchema: schema }
|
|
@@ -41,4 +41,4 @@ let model = (mongooseInstance) => {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
// Exports Mongoose Model, Mongoose Schema, JSON schema (required locally for discriminators)
|
|
44
|
-
module.exports = {
|
|
44
|
+
module.exports = { Model: model, Schema: TimeOfDayRangeFilterSchema, timeOfDayRangeFilterSchema: schema }
|
package/models/UrlAction.js
CHANGED
|
@@ -51,4 +51,4 @@ const model = (mongooseInstance) => {
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
// Exports Mongoose Model, Mongoose Schema, JSON schema (required locally for discriminators)
|
|
54
|
-
module.exports = {
|
|
54
|
+
module.exports = { Model: model, Schema: URLActionSchema, urlActionSchema: schema }
|
package/models/User.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Created by Richard Tan on 27/02/18.
|
|
3
|
+
* Copyright : Bluedot Innovation.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
let StateEnum = require('@bluedot-innovation/enums').StateEnum
|
|
7
|
+
let mongoose = require('mongoose')
|
|
8
|
+
let patcher = require('mongoose-json-patch')
|
|
9
|
+
const helpers = require('../helpers')
|
|
10
|
+
|
|
11
|
+
let UserSchema = new mongoose.Schema({
|
|
12
|
+
username: {
|
|
13
|
+
type: String,
|
|
14
|
+
required: true,
|
|
15
|
+
maxlength: 100,
|
|
16
|
+
unique: true
|
|
17
|
+
},
|
|
18
|
+
emailAddress: {
|
|
19
|
+
type: String,
|
|
20
|
+
required: true,
|
|
21
|
+
validate: {
|
|
22
|
+
validator: helpers.validateEmail,
|
|
23
|
+
message: '{VALUE} is not a valid email'
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
password: {type: String, required: true},
|
|
27
|
+
firstName: {type: String, required: true},
|
|
28
|
+
lastName: {type: String, required: true},
|
|
29
|
+
phoneNumber: {type: String, maxlength: 20},
|
|
30
|
+
state: {type: String, default: StateEnum.active},
|
|
31
|
+
creationTime: {type: Date, default: Date.now},
|
|
32
|
+
lastUpdateTime: {type: Date, default: Date.now},
|
|
33
|
+
isAdmin: {type: Boolean, required: true},
|
|
34
|
+
secret: String,
|
|
35
|
+
projectPermissions: Array,
|
|
36
|
+
accountId: {
|
|
37
|
+
type: String,
|
|
38
|
+
required: true,
|
|
39
|
+
validator: helpers.validateUUIDv4
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
{collection: 'user'})
|
|
43
|
+
|
|
44
|
+
UserSchema.plugin(patcher)
|
|
45
|
+
|
|
46
|
+
// optional mongoose
|
|
47
|
+
let model = (mongooseInstance) => {
|
|
48
|
+
let User
|
|
49
|
+
if (mongooseInstance) {
|
|
50
|
+
User = mongooseInstance.model('User', UserSchema)
|
|
51
|
+
} else {
|
|
52
|
+
User = mongoose.model('User', UserSchema)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return User
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Exports Mongoose Model, Mongoose Schema, JSON schema (required locally for discriminators)
|
|
59
|
+
module.exports = { Model: model, Schema: UserSchema }
|
package/models/Zone.js
CHANGED
|
@@ -60,9 +60,9 @@ let ZoneSchema = new Schema({
|
|
|
60
60
|
},
|
|
61
61
|
customData: [{type: Schema.Types.Mixed}],
|
|
62
62
|
description: {type: String, default: ''},
|
|
63
|
-
creationTime: {type: Date,
|
|
64
|
-
lastUpdateTime: {type: Date,
|
|
65
|
-
|
|
63
|
+
creationTime: {type: Date, required: [true, 'creationTime is required'], select: false},
|
|
64
|
+
lastUpdateTime: {type: Date, required: [true, 'lastUpdateTime is required'], select: false},
|
|
65
|
+
projectId: {type: String, required: [true, 'projectId is required']},
|
|
66
66
|
state: {type: String, default: StateEnum.active, select: false}
|
|
67
67
|
}, {collection: 'zone'})
|
|
68
68
|
|
|
@@ -96,4 +96,4 @@ const model = (mongooseInstance) => {
|
|
|
96
96
|
return Zone
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
module.exports = {
|
|
99
|
+
module.exports = { Model: model, Schema: ZoneSchema }
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bluedot-innovation/models",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.10",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "Models.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"lint": "./node_modules/.bin/eslint -c .eslintrc.js ./models/*.js ./__tests__/**/**/*.js ./schemas/*.js",
|
|
7
|
+
"lint": "./node_modules/.bin/eslint -c .eslintrc.js ./models/*.js ./__tests__/**/*.js ./__tests__/**/**/*.js ./schemas/*.js",
|
|
8
8
|
"test": "mocha __tests__/**/*.spec.js __tests__/**/**/*.spec.js",
|
|
9
9
|
"test:coverage": "nyc mocha __tests__/**/*.spec.js __tests__/**/**/*.spec.js",
|
|
10
10
|
"test:coverage-check": "nyc check-coverage --lines 90 --functions 90 --branches 70",
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
let mongoose = require('mongoose')
|
|
2
|
+
|
|
3
|
+
let typeEnum = {
|
|
4
|
+
values: ['trigger', 'configurationChanged'],
|
|
5
|
+
message: 'enum validator failed for path `{PATH}` with value `{VALUE}`'
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
let WebhookSchema = new mongoose.Schema({
|
|
9
|
+
type: {type: String, enum: typeEnum, required: [true, 'webhook type is required']}, // configurationChanged, trigger
|
|
10
|
+
url: {type: String, required: true, validate: {isAsync: false, validator: validateUrl, msg: 'default error message'}},
|
|
11
|
+
enabled: {type: Boolean, required: [true, 'enabled is required']},
|
|
12
|
+
headers: {type: mongoose.Schema.Types.Mixed, default: null}
|
|
13
|
+
}, {
|
|
14
|
+
_id: false
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
function validateUrl (url) {
|
|
18
|
+
const expression = 'https?:\\/\\/(www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{2,256}\\.[a-z]{2,4}\\b([-a-zA-Z0-9@:%_\\+.~#?&//=]*)'
|
|
19
|
+
const regex = new RegExp(expression, 'i')
|
|
20
|
+
return regex.test(url)
|
|
21
|
+
}
|
|
22
|
+
module.exports = WebhookSchema
|