@bluedot-innovation/models 7.17.0-alpha → 7.18.0
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/CHANGELOG.md
CHANGED
|
@@ -48,6 +48,16 @@ describe('Valid Destination ', () => {
|
|
|
48
48
|
done()
|
|
49
49
|
})
|
|
50
50
|
})
|
|
51
|
+
|
|
52
|
+
it('should validate a valid destination without wait time goals', (done) => {
|
|
53
|
+
delete destination.waitTime
|
|
54
|
+
let Destination = new DestinationModel(destination)
|
|
55
|
+
Destination.validate((err, res) => {
|
|
56
|
+
assert.notExists(res)
|
|
57
|
+
assert(err === null, 'err equals null')
|
|
58
|
+
done()
|
|
59
|
+
})
|
|
60
|
+
})
|
|
51
61
|
})
|
|
52
62
|
|
|
53
63
|
describe('Invalid Destination ', () => {
|
|
@@ -154,4 +164,28 @@ describe('Invalid Destination ', () => {
|
|
|
154
164
|
done()
|
|
155
165
|
})
|
|
156
166
|
})
|
|
167
|
+
|
|
168
|
+
it("should throw an error if wait time alert is greater than goal", (done) => {
|
|
169
|
+
destination.waitTime.alert = 600
|
|
170
|
+
let Destination = new DestinationModel(destination)
|
|
171
|
+
Destination.validate((err, res) => {
|
|
172
|
+
assert.notExists(res)
|
|
173
|
+
assert.exists(err)
|
|
174
|
+
console.log(err.message)
|
|
175
|
+
assert.match(err.message, /alert must be less than the goal value/)
|
|
176
|
+
done()
|
|
177
|
+
})
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
it("should throw an error if alert is not a number", (done) => {
|
|
181
|
+
destination.waitTime.alert = "Twelve"
|
|
182
|
+
let Destination = new DestinationModel(destination)
|
|
183
|
+
Destination.validate((err, res) => {
|
|
184
|
+
assert.notExists(res)
|
|
185
|
+
assert.exists(err)
|
|
186
|
+
console.log(err.message)
|
|
187
|
+
assert.match(err.message, /Cast to Number failed for value "Twelve" \(type string\) at path "alert"/)
|
|
188
|
+
done()
|
|
189
|
+
})
|
|
190
|
+
})
|
|
157
191
|
})
|
package/models/Destination.js
CHANGED
|
@@ -2,6 +2,7 @@ const mongoose = require('mongoose')
|
|
|
2
2
|
const uuidv4 = require('uuid/v4')
|
|
3
3
|
const patcher = require('@bluedot-innovation/mongoose-json-patch')
|
|
4
4
|
const Point = require('../schemas/Point')
|
|
5
|
+
const WaitTime = require('../schemas/WaitTime')
|
|
5
6
|
const helpers = require('../helpers')
|
|
6
7
|
|
|
7
8
|
const DestinationSchema = new mongoose.Schema({
|
|
@@ -16,6 +17,7 @@ const DestinationSchema = new mongoose.Schema({
|
|
|
16
17
|
projectId: {type: String, required: true, validate: {validator: helpers.validateUUIDv4, msg: 'Invalid projectId'}},
|
|
17
18
|
creationTime: {type: Date, default: Date.now},
|
|
18
19
|
lastUpdateTime: {type: Date, default: Date.now},
|
|
20
|
+
waitTime: { type: WaitTime }
|
|
19
21
|
}, {collection: 'destination'})
|
|
20
22
|
|
|
21
23
|
DestinationSchema.plugin(patcher)
|
package/package.json
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const mongoose = require('mongoose');
|
|
2
|
+
|
|
3
|
+
function validateAlertLessThanGoal(alert){
|
|
4
|
+
return alert < this.goal
|
|
5
|
+
}
|
|
6
|
+
const WaitTimeSchema = new mongoose.Schema({
|
|
7
|
+
alert: { type: Number, required: true, validate: { validator: validateAlertLessThanGoal, msg: "alert must be less than the goal value" } },
|
|
8
|
+
goal: { type: Number, required: true }
|
|
9
|
+
}, {
|
|
10
|
+
_id: false
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
module.exports = WaitTimeSchema
|
|
@@ -8,23 +8,27 @@ const client = new MongoClient(MONGO_DB_URI)
|
|
|
8
8
|
|
|
9
9
|
console.log(`Using DB_NAME:${DB_NAME} in ENVIRONMENT:${ENVIRONMENT}`)
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
11
|
+
const dbInitialiser = async () => {
|
|
12
|
+
try {
|
|
13
|
+
await client.connect()
|
|
14
|
+
} catch (error) {
|
|
15
|
+
console.log("Failed to connect to Mongo DB", error)
|
|
16
|
+
process.exit(1)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
console.log("Connected to Mongo DB")
|
|
20
|
+
|
|
21
|
+
const db = client.db(DB_NAME)
|
|
22
|
+
|
|
23
|
+
try{
|
|
24
|
+
await createAllIndexesIfNotExists(db)
|
|
25
|
+
} catch(error) {
|
|
26
|
+
console.log(error)
|
|
27
|
+
await client.close()
|
|
28
|
+
process.exit(1)
|
|
29
|
+
}
|
|
30
|
+
|
|
26
31
|
await client.close()
|
|
27
|
-
process.exit(1)
|
|
28
32
|
}
|
|
29
33
|
|
|
30
|
-
|
|
34
|
+
dbInitialiser()
|