@bluedot-innovation/models 2.0.0-beta.3 → 2.0.0-beta.5
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 +5 -0
- 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__/filter/calendarDateRange/calendarDateRangeFilter.spec.js +1 -1
- package/__tests__/filter/percentageCrossed/percentageCrossedFilter.spec.js +1 -1
- package/__tests__/geofeature/beacon/beacon.spec.js +1 -1
- package/__tests__/geofeature/boundingBox/boundingBox.spec.js +1 -1
- package/__tests__/geofeature/circle/circle.spec.js +1 -1
- package/__tests__/geofeature/polygon/polygon.spec.js +1 -1
- package/__tests__/geofeature/polyline/polyline.spec.js +1 -1
- package/__tests__/monthlyStats/monthlyStats.spec.js +32 -4
- package/__tests__/project/project.rules.json +1 -1
- package/__tests__/project/project.spec.js +2 -1
- package/__tests__/ruleRequestAggregation/ruleRequestAggregation.data.json +8 -0
- package/__tests__/ruleRequestAggregation/ruleRequestAggregation.spec.js +69 -0
- package/__tests__/zone/zone.data.json +1 -1
- package/helpers.js +9 -0
- package/models/Account.js +47 -0
- package/models/MonthlyStats.js +7 -3
- package/models/Project.js +3 -8
- package/models/RuleRequestAggregation.js +29 -10
- package/package.json +1 -1
- package/yarn.lock +2796 -0
- package/.nyc_output/d08d4085968c722e0d4badb2cb6e7f77.json +0 -1
- /package/.nyc_output/{d7fc240e95720f6ec07fb83631e1206d.json → b3865a46e2cec635045d586cfc79e5c6.json} +0 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Created by Richard Tan on 27/02/18.
|
|
3
|
+
* Copyright : Bluedot Innovation.
|
|
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
|
+
const helpers = require('../helpers')
|
|
13
|
+
|
|
14
|
+
let AccountSchema = new mongoose.Schema({
|
|
15
|
+
_id: {type: String, default: uuidv4},
|
|
16
|
+
name: {type: String, required: true},
|
|
17
|
+
createdBy: {
|
|
18
|
+
// type: Schema.Types.ObjectId,
|
|
19
|
+
type: String,
|
|
20
|
+
validator: helpers.validateUUIDv4,
|
|
21
|
+
required: true
|
|
22
|
+
},
|
|
23
|
+
state: {type: String, default: StateEnum.active},
|
|
24
|
+
poiCredits: Number,
|
|
25
|
+
integrations: Object,
|
|
26
|
+
features: Object,
|
|
27
|
+
creationTime: {type: Date, required: [true, 'creationTime is required']},
|
|
28
|
+
lastUpdateTime: {type: Date, required: [true, 'creationTime is required']}
|
|
29
|
+
},
|
|
30
|
+
{collection: 'account'})
|
|
31
|
+
|
|
32
|
+
AccountSchema.plugin(patcher)
|
|
33
|
+
|
|
34
|
+
// optional mongoose
|
|
35
|
+
let model = (mongooseInstance) => {
|
|
36
|
+
let Account
|
|
37
|
+
if (mongooseInstance) {
|
|
38
|
+
Account = mongooseInstance.model('Account', AccountSchema)
|
|
39
|
+
} else {
|
|
40
|
+
Account = mongoose.model('Account', AccountSchema)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return Account
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Exports Mongoose Model, Mongoose Schema, JSON schema (required locally for discriminators)
|
|
47
|
+
module.exports = { Model: model, Schema: AccountSchema }
|
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
|
}
|
package/models/Project.js
CHANGED
|
@@ -9,6 +9,7 @@ let Schema = mongoose.Schema
|
|
|
9
9
|
let StateEnum = require('@bluedot-innovation/enums').StateEnum
|
|
10
10
|
let uuidv4 = require('uuid/v4')
|
|
11
11
|
let patcher = require('mongoose-json-patch')
|
|
12
|
+
let helpers = require('../helpers')
|
|
12
13
|
|
|
13
14
|
let WebhookSchema = require('../schemas/Webhook')
|
|
14
15
|
|
|
@@ -28,20 +29,14 @@ let ProjectSchema = new mongoose.Schema({
|
|
|
28
29
|
lastUpdateTime: {type: Date, required: [true, 'lastUpdateTime is required']},
|
|
29
30
|
creationTime: {type: Date, required: [true, 'creationTime is required']},
|
|
30
31
|
name: {type: String, required: [true, 'name is required']},
|
|
31
|
-
accountId: {type: String, required: true, validate: {isAsync: false, validator: validateUUIDv4, msg: 'default error message'}},
|
|
32
|
+
accountId: {type: String, required: true, validate: {isAsync: false, validator: helpers.validateUUIDv4, msg: 'default error message'}},
|
|
32
33
|
webhooks: [WebhookSchema],
|
|
33
34
|
configurationParameters: {type: Schema.Types.Mixed, default: null} // http://collab.bluedot.io/display/PD/Remote+configuration
|
|
34
35
|
},
|
|
35
|
-
{collection: '
|
|
36
|
+
{collection: 'project'})
|
|
36
37
|
|
|
37
38
|
ProjectSchema.plugin(patcher)
|
|
38
39
|
|
|
39
|
-
function validateUUIDv4 (id) {
|
|
40
|
-
const expression = '^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$'
|
|
41
|
-
const regex = new RegExp(expression, 'i')
|
|
42
|
-
return regex.test(id)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
40
|
// optional mongoose
|
|
46
41
|
let model = (mongooseInstance) => {
|
|
47
42
|
let Project
|
|
@@ -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 }
|