@bluedot-innovation/models 7.11.1 → 7.11.3
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 +6 -0
- package/__tests__/destination/destination.data.json +1 -38
- package/__tests__/destination/destination.rules.json +2 -2
- package/__tests__/destination/destination.spec.js +12 -15
- package/models/Destination.js +1 -3
- package/models/Zone.js +0 -11
- package/package.json +1 -1
- package/schemas/AddressComponent.js +0 -11
package/CHANGELOG.md
CHANGED
|
@@ -10,42 +10,5 @@
|
|
|
10
10
|
"latitude": -37.8159544565362,
|
|
11
11
|
"longitude": 144.9723565578461
|
|
12
12
|
},
|
|
13
|
-
"address": "48 Pirrama Rd, Pyrmont NSW 2009, Australia"
|
|
14
|
-
"address_components": [
|
|
15
|
-
{
|
|
16
|
-
"long_name": "48",
|
|
17
|
-
"short_name": "48",
|
|
18
|
-
"types": ["street_number"]
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
"long_name": "Pirrama Road",
|
|
22
|
-
"short_name": "Pirrama Rd",
|
|
23
|
-
"types": ["route"]
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
"long_name": "Pyrmont",
|
|
27
|
-
"short_name": "Pyrmont",
|
|
28
|
-
"types": ["locality", "political"]
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
"long_name": "City of Sydney",
|
|
32
|
-
"short_name": "City of Sydney",
|
|
33
|
-
"types": ["administrative_area_level_2", "political"]
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
"long_name": "New South Wales",
|
|
37
|
-
"short_name": "NSW",
|
|
38
|
-
"types": ["administrative_area_level_1", "political"]
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
"long_name": "Australia",
|
|
42
|
-
"short_name": "AU",
|
|
43
|
-
"types": ["country", "political"]
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
"long_name": "2009",
|
|
47
|
-
"short_name": "2009",
|
|
48
|
-
"types": ["postal_code"]
|
|
49
|
-
}
|
|
50
|
-
]
|
|
13
|
+
"address": "48 Pirrama Rd, Pyrmont NSW 2009, Australia"
|
|
51
14
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
{
|
|
2
|
-
"requiredFields": ["name", "destinationId", "accountId", "location", "address", "
|
|
3
|
-
}
|
|
2
|
+
"requiredFields": ["name", "destinationId", "accountId", "location", "address", "projectId"]
|
|
3
|
+
}
|
|
@@ -117,21 +117,6 @@ describe('Invalid Destination ', () => {
|
|
|
117
117
|
})
|
|
118
118
|
})
|
|
119
119
|
|
|
120
|
-
it("should throw an error message if address_components is in the wrong format", (done) => {
|
|
121
|
-
const invalidTypeAddressComponents = {
|
|
122
|
-
long_name: "Wellington",
|
|
123
|
-
types: ["City"]
|
|
124
|
-
}
|
|
125
|
-
destination.address_components = [invalidTypeAddressComponents]
|
|
126
|
-
let Destination = new DestinationModel(destination)
|
|
127
|
-
Destination.validate((err, res) => {
|
|
128
|
-
assert.notExists(res)
|
|
129
|
-
assert.exists(err)
|
|
130
|
-
assert.match(err.message, /`short_name` is required/)
|
|
131
|
-
done()
|
|
132
|
-
})
|
|
133
|
-
})
|
|
134
|
-
|
|
135
120
|
it("should throw an error if destinationId is longer than 128 characters", (done) => {
|
|
136
121
|
let destinationId = ""
|
|
137
122
|
for(let i = 0; i < 129; i++){
|
|
@@ -157,4 +142,16 @@ describe('Invalid Destination ', () => {
|
|
|
157
142
|
done()
|
|
158
143
|
})
|
|
159
144
|
})
|
|
145
|
+
|
|
146
|
+
it("should throw an error if name is more than 128 characters long", (done) => {
|
|
147
|
+
destination.name = "ukhwwO8J9qSinhmNB3wA04O24MJgX5Ne04RRt9cJkoJryes8jlyv33H83YdCn8Vza6F8CKoL5Il574JHHs7LC94bC7APHEMZ7aW9Csw8GS6L2Mzo28R35ppxDE5kaVhya"
|
|
148
|
+
let Destination = new DestinationModel(destination)
|
|
149
|
+
Destination.validate((err, res) => {
|
|
150
|
+
assert.notExists(res)
|
|
151
|
+
assert.exists(err)
|
|
152
|
+
console.log(err.message)
|
|
153
|
+
assert.match(err.message, /is longer than the maximum allowed length \(128\)/)
|
|
154
|
+
done()
|
|
155
|
+
})
|
|
156
|
+
})
|
|
160
157
|
})
|
package/models/Destination.js
CHANGED
|
@@ -3,17 +3,15 @@ const uuidv4 = require('uuid/v4')
|
|
|
3
3
|
const patcher = require('@bluedot-innovation/mongoose-json-patch')
|
|
4
4
|
const Point = require('../schemas/Point')
|
|
5
5
|
const helpers = require('../helpers')
|
|
6
|
-
const AddressComponent = require('../schemas/AddressComponent')
|
|
7
6
|
|
|
8
7
|
const DestinationSchema = new mongoose.Schema({
|
|
9
8
|
_id: {type: String, default: uuidv4},
|
|
10
|
-
name: {type: String, required: true},
|
|
9
|
+
name: {type: String, required: true, maxlength: 128},
|
|
11
10
|
email: { type: String, validate: { validator: helpers.validateEmail, message: '{VALUE} is not a valid email'} },
|
|
12
11
|
destinationId: { type: String, required: true, validate: { validator: helpers.validateDestinationIdLength, msg: 'destinationId must be less than 129 characters long' } },
|
|
13
12
|
location: { type: Point, required: true},
|
|
14
13
|
geometry: {type: {}},
|
|
15
14
|
address: {type: String, required: true },
|
|
16
|
-
address_components: {type: [AddressComponent], required: true, default: undefined},
|
|
17
15
|
accountId: {type: String, required: true, validate: {validator: helpers.validateUUIDv4, msg: 'Invalid accountId'}},
|
|
18
16
|
projectId: {type: String, required: true, validate: {validator: helpers.validateUUIDv4, msg: 'Invalid projectId'}},
|
|
19
17
|
creationTime: {type: Date, default: Date.now},
|
package/models/Zone.js
CHANGED
|
@@ -121,17 +121,6 @@ let zoneSchema = new Schema({
|
|
|
121
121
|
destinationId: {type: String, validate: { validator: helpers.validateDestinationIdLength, msg: 'destinationId must be less than 129 characters long' }},
|
|
122
122
|
}, {collection: 'zone', autoIndex: false})
|
|
123
123
|
|
|
124
|
-
zoneSchema.index(
|
|
125
|
-
{
|
|
126
|
-
projectId: 1,
|
|
127
|
-
destinationId: 1
|
|
128
|
-
},
|
|
129
|
-
{
|
|
130
|
-
unique: true,
|
|
131
|
-
partialFilterExpression: { 'destinationId': { $exists:true, $type:"string" } },
|
|
132
|
-
name: "destinationUniqueWithinProject"
|
|
133
|
-
})
|
|
134
|
-
|
|
135
124
|
// Mongoose-json-patch
|
|
136
125
|
// https://www.npmjs.com/package/mongoose-json-patch
|
|
137
126
|
// plugin for PATCH operations
|
package/package.json
CHANGED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
let mongoose = require('mongoose')
|
|
2
|
-
|
|
3
|
-
const AddressComponent = new mongoose.Schema({
|
|
4
|
-
long_name: {type: String, required: true},
|
|
5
|
-
short_name: {type: String, required: true},
|
|
6
|
-
types: {type: [String], required: true, default: undefined}
|
|
7
|
-
}, {
|
|
8
|
-
_id: false
|
|
9
|
-
})
|
|
10
|
-
|
|
11
|
-
module.exports = AddressComponent;
|