@bluedot-innovation/models 10.12.0 → 10.12.2
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 +7 -1
- package/__tests__/account/account.data.json +3 -0
- package/__tests__/account/account.spec.js +27 -0
- package/__tests__/project/project.data.json +29 -0
- package/__tests__/project/project.spec.js +276 -0
- package/models/Project.js +5 -1
- package/package.json +1 -1
- package/schemas/AccountFeatures.js +2 -1
- package/schemas/ApnsConfiguration.js +28 -0
- package/schemas/Campaign.js +47 -0
- package/schemas/CampaignNotification.js +18 -0
- package/schemas/CampaignZone.js +25 -0
- package/schemas/FcmConfiguration.js +12 -0
- package/schemas/PushConfiguration.js +18 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
## 10.12.
|
|
1
|
+
## 10.12.2
|
|
2
|
+
- Fix APNs environment enum: change 'sandbox' to 'development' to match Apple's APNs environment values
|
|
3
|
+
|
|
4
|
+
## 10.12.1
|
|
2
5
|
- Add Push Notification Campaign schemas (Campaign, CampaignNotification, CampaignZone)
|
|
3
6
|
- Add Push Configuration schemas (PushConfiguration, ApnsConfiguration, FcmConfiguration)
|
|
4
7
|
- Add pushConfiguration to Project model
|
|
5
8
|
- Add pushNotifications to AccountFeatures
|
|
6
9
|
|
|
10
|
+
## 10.12.0
|
|
11
|
+
- Version bump (no schema changes)
|
|
12
|
+
|
|
7
13
|
## 10.11.0
|
|
8
14
|
- Add a feature to select Hello Stack
|
|
9
15
|
|
|
@@ -156,4 +156,31 @@ testCase('Account', () => {
|
|
|
156
156
|
})
|
|
157
157
|
})
|
|
158
158
|
})
|
|
159
|
+
|
|
160
|
+
testCase('Push Notifications Feature', () => {
|
|
161
|
+
assertions('should validate account with pushNotifications feature enabled', async () => {
|
|
162
|
+
let Account = new AccountModel(account)
|
|
163
|
+
const res = await Account.validate()
|
|
164
|
+
assert.notExists(res)
|
|
165
|
+
assert.exists(Account.features.pushNotifications)
|
|
166
|
+
assert.equal(Account.features.pushNotifications.enabled, true)
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
assertions('should validate account with pushNotifications feature disabled', async () => {
|
|
170
|
+
account = JSON.parse(JSON.stringify(account))
|
|
171
|
+
account.features.pushNotifications.enabled = false
|
|
172
|
+
let Account = new AccountModel(account)
|
|
173
|
+
const res = await Account.validate()
|
|
174
|
+
assert.notExists(res)
|
|
175
|
+
assert.equal(Account.features.pushNotifications.enabled, false)
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
assertions('should validate account without pushNotifications feature', async () => {
|
|
179
|
+
account = JSON.parse(JSON.stringify(account))
|
|
180
|
+
delete account.features.pushNotifications
|
|
181
|
+
let Account = new AccountModel(account)
|
|
182
|
+
const res = await Account.validate()
|
|
183
|
+
assert.notExists(res)
|
|
184
|
+
})
|
|
185
|
+
})
|
|
159
186
|
})
|
|
@@ -138,5 +138,34 @@
|
|
|
138
138
|
],
|
|
139
139
|
"insightsConfiguration": {
|
|
140
140
|
"volumeGroupByKeys": ["Operational State", "Store Number", "City"]
|
|
141
|
+
},
|
|
142
|
+
"campaigns": [
|
|
143
|
+
{
|
|
144
|
+
"_id": "550e8400-e29b-41d4-a716-446655440000",
|
|
145
|
+
"type": "entry",
|
|
146
|
+
"notification": {
|
|
147
|
+
"title": "Welcome offer - Downtown Stores",
|
|
148
|
+
"body": "Discover exclusive deals and offers at our downtown locations."
|
|
149
|
+
},
|
|
150
|
+
"zones": [
|
|
151
|
+
{
|
|
152
|
+
"id": "b0824b76-ce73-4fcf-81f8-1b63edb1114e",
|
|
153
|
+
"name": "Outdoor Seating Zone 1",
|
|
154
|
+
"destinationId": "airport"
|
|
155
|
+
}
|
|
156
|
+
],
|
|
157
|
+
"status": "active"
|
|
158
|
+
}
|
|
159
|
+
],
|
|
160
|
+
"push": {
|
|
161
|
+
"apns": {
|
|
162
|
+
"environment": "production",
|
|
163
|
+
"teamId": "9JA89QQLN7",
|
|
164
|
+
"keyId": "ABC123DEFG",
|
|
165
|
+
"bundleId": "com.client.app"
|
|
166
|
+
},
|
|
167
|
+
"fcm": {
|
|
168
|
+
"isConfigured": true
|
|
169
|
+
}
|
|
141
170
|
}
|
|
142
171
|
}
|
|
@@ -1150,4 +1150,280 @@ describe('Project', () => {
|
|
|
1150
1150
|
})
|
|
1151
1151
|
})
|
|
1152
1152
|
})
|
|
1153
|
+
|
|
1154
|
+
describe('Campaigns', () => {
|
|
1155
|
+
describe('Valid Campaigns', () => {
|
|
1156
|
+
it('should validate a project with valid campaigns', async () => {
|
|
1157
|
+
let Project = new ProjectModel(project)
|
|
1158
|
+
const res = await Project.validate()
|
|
1159
|
+
assert.notExists(res)
|
|
1160
|
+
assert.isArray(Project.campaigns)
|
|
1161
|
+
assert.equal(Project.campaigns.length, 1)
|
|
1162
|
+
})
|
|
1163
|
+
|
|
1164
|
+
it('should validate a project with empty campaigns array', async () => {
|
|
1165
|
+
project.campaigns = []
|
|
1166
|
+
let Project = new ProjectModel(project)
|
|
1167
|
+
const res = await Project.validate()
|
|
1168
|
+
assert.notExists(res)
|
|
1169
|
+
})
|
|
1170
|
+
|
|
1171
|
+
it('should validate a project without campaigns field', async () => {
|
|
1172
|
+
delete project.campaigns
|
|
1173
|
+
let Project = new ProjectModel(project)
|
|
1174
|
+
const res = await Project.validate()
|
|
1175
|
+
assert.notExists(res)
|
|
1176
|
+
assert.isArray(Project.campaigns)
|
|
1177
|
+
assert.equal(Project.campaigns.length, 0)
|
|
1178
|
+
})
|
|
1179
|
+
|
|
1180
|
+
it('should validate a campaign with all trigger types', async () => {
|
|
1181
|
+
const triggerTypes = ['entry', 'dwell', 'exit']
|
|
1182
|
+
for (const type of triggerTypes) {
|
|
1183
|
+
project.campaigns[0].type = type
|
|
1184
|
+
let Project = new ProjectModel(project)
|
|
1185
|
+
const res = await Project.validate()
|
|
1186
|
+
assert.notExists(res)
|
|
1187
|
+
}
|
|
1188
|
+
})
|
|
1189
|
+
|
|
1190
|
+
it('should validate a campaign with all status values', async () => {
|
|
1191
|
+
const statuses = ['active', 'draft', 'paused']
|
|
1192
|
+
for (const status of statuses) {
|
|
1193
|
+
project.campaigns[0].status = status
|
|
1194
|
+
let Project = new ProjectModel(project)
|
|
1195
|
+
const res = await Project.validate()
|
|
1196
|
+
assert.notExists(res)
|
|
1197
|
+
}
|
|
1198
|
+
})
|
|
1199
|
+
})
|
|
1200
|
+
|
|
1201
|
+
describe('Invalid Campaigns', () => {
|
|
1202
|
+
it('should throw an error when campaign type is missing', async () => {
|
|
1203
|
+
delete project.campaigns[0].type
|
|
1204
|
+
let Project = new ProjectModel(project)
|
|
1205
|
+
try {
|
|
1206
|
+
await Project.validate()
|
|
1207
|
+
} catch (err) {
|
|
1208
|
+
assert.exists(err, 'err object should exist')
|
|
1209
|
+
assert.match(err.message, /campaign type is required/)
|
|
1210
|
+
}
|
|
1211
|
+
})
|
|
1212
|
+
|
|
1213
|
+
it('should throw an error when campaign type is invalid', async () => {
|
|
1214
|
+
project.campaigns[0].type = 'invalid'
|
|
1215
|
+
let Project = new ProjectModel(project)
|
|
1216
|
+
try {
|
|
1217
|
+
await Project.validate()
|
|
1218
|
+
} catch (err) {
|
|
1219
|
+
assert.exists(err, 'err object should exist')
|
|
1220
|
+
assert.match(err.message, /`invalid` is not a valid enum value for path `type`/)
|
|
1221
|
+
}
|
|
1222
|
+
})
|
|
1223
|
+
|
|
1224
|
+
it('should throw an error when campaign notification is missing', async () => {
|
|
1225
|
+
delete project.campaigns[0].notification
|
|
1226
|
+
let Project = new ProjectModel(project)
|
|
1227
|
+
try {
|
|
1228
|
+
await Project.validate()
|
|
1229
|
+
} catch (err) {
|
|
1230
|
+
assert.exists(err, 'err object should exist')
|
|
1231
|
+
assert.match(err.message, /campaign notification is required/)
|
|
1232
|
+
}
|
|
1233
|
+
})
|
|
1234
|
+
|
|
1235
|
+
it('should throw an error when notification title is missing', async () => {
|
|
1236
|
+
delete project.campaigns[0].notification.title
|
|
1237
|
+
let Project = new ProjectModel(project)
|
|
1238
|
+
try {
|
|
1239
|
+
await Project.validate()
|
|
1240
|
+
} catch (err) {
|
|
1241
|
+
assert.exists(err, 'err object should exist')
|
|
1242
|
+
assert.match(err.message, /notification title is required/)
|
|
1243
|
+
}
|
|
1244
|
+
})
|
|
1245
|
+
|
|
1246
|
+
it('should throw an error when notification body is missing', async () => {
|
|
1247
|
+
delete project.campaigns[0].notification.body
|
|
1248
|
+
let Project = new ProjectModel(project)
|
|
1249
|
+
try {
|
|
1250
|
+
await Project.validate()
|
|
1251
|
+
} catch (err) {
|
|
1252
|
+
assert.exists(err, 'err object should exist')
|
|
1253
|
+
assert.match(err.message, /notification body is required/)
|
|
1254
|
+
}
|
|
1255
|
+
})
|
|
1256
|
+
|
|
1257
|
+
it('should throw an error when campaign zones is empty', async () => {
|
|
1258
|
+
project.campaigns[0].zones = []
|
|
1259
|
+
let Project = new ProjectModel(project)
|
|
1260
|
+
try {
|
|
1261
|
+
await Project.validate()
|
|
1262
|
+
} catch (err) {
|
|
1263
|
+
assert.exists(err, 'err object should exist')
|
|
1264
|
+
assert.match(err.message, /campaign must have at least one zone/)
|
|
1265
|
+
}
|
|
1266
|
+
})
|
|
1267
|
+
|
|
1268
|
+
it('should throw an error when zone id is missing', async () => {
|
|
1269
|
+
delete project.campaigns[0].zones[0].id
|
|
1270
|
+
let Project = new ProjectModel(project)
|
|
1271
|
+
try {
|
|
1272
|
+
await Project.validate()
|
|
1273
|
+
} catch (err) {
|
|
1274
|
+
assert.exists(err, 'err object should exist')
|
|
1275
|
+
assert.match(err.message, /zone id is required/)
|
|
1276
|
+
}
|
|
1277
|
+
})
|
|
1278
|
+
|
|
1279
|
+
it('should throw an error when zone id is not a valid UUID', async () => {
|
|
1280
|
+
project.campaigns[0].zones[0].id = 'invalid-uuid'
|
|
1281
|
+
let Project = new ProjectModel(project)
|
|
1282
|
+
try {
|
|
1283
|
+
await Project.validate()
|
|
1284
|
+
} catch (err) {
|
|
1285
|
+
assert.exists(err, 'err object should exist')
|
|
1286
|
+
assert.match(err.message, /zone id must be a valid UUID/)
|
|
1287
|
+
}
|
|
1288
|
+
})
|
|
1289
|
+
|
|
1290
|
+
it('should throw an error when zone name is missing', async () => {
|
|
1291
|
+
delete project.campaigns[0].zones[0].name
|
|
1292
|
+
let Project = new ProjectModel(project)
|
|
1293
|
+
try {
|
|
1294
|
+
await Project.validate()
|
|
1295
|
+
} catch (err) {
|
|
1296
|
+
assert.exists(err, 'err object should exist')
|
|
1297
|
+
assert.match(err.message, /zone name is required/)
|
|
1298
|
+
}
|
|
1299
|
+
})
|
|
1300
|
+
|
|
1301
|
+
it('should validate a campaign zone without destinationId', async () => {
|
|
1302
|
+
delete project.campaigns[0].zones[0].destinationId
|
|
1303
|
+
let Project = new ProjectModel(project)
|
|
1304
|
+
const res = await Project.validate()
|
|
1305
|
+
assert.notExists(res)
|
|
1306
|
+
})
|
|
1307
|
+
|
|
1308
|
+
it('should throw an error when campaign status is missing', async () => {
|
|
1309
|
+
delete project.campaigns[0].status
|
|
1310
|
+
let Project = new ProjectModel(project)
|
|
1311
|
+
try {
|
|
1312
|
+
await Project.validate()
|
|
1313
|
+
} catch (err) {
|
|
1314
|
+
assert.exists(err, 'err object should exist')
|
|
1315
|
+
assert.match(err.message, /campaign status is required/)
|
|
1316
|
+
}
|
|
1317
|
+
})
|
|
1318
|
+
|
|
1319
|
+
it('should throw an error when campaign status is invalid', async () => {
|
|
1320
|
+
project.campaigns[0].status = 'invalid'
|
|
1321
|
+
let Project = new ProjectModel(project)
|
|
1322
|
+
try {
|
|
1323
|
+
await Project.validate()
|
|
1324
|
+
} catch (err) {
|
|
1325
|
+
assert.exists(err, 'err object should exist')
|
|
1326
|
+
assert.match(err.message, /`invalid` is not a valid enum value for path `status`/)
|
|
1327
|
+
}
|
|
1328
|
+
})
|
|
1329
|
+
})
|
|
1330
|
+
})
|
|
1331
|
+
|
|
1332
|
+
describe('Push Notification Configuration', () => {
|
|
1333
|
+
describe('Valid Push Configuration', () => {
|
|
1334
|
+
it('should validate a project with valid push configuration', async () => {
|
|
1335
|
+
let Project = new ProjectModel(project)
|
|
1336
|
+
const res = await Project.validate()
|
|
1337
|
+
assert.notExists(res)
|
|
1338
|
+
assert.exists(Project.push)
|
|
1339
|
+
assert.exists(Project.push.apns)
|
|
1340
|
+
assert.exists(Project.push.fcm)
|
|
1341
|
+
})
|
|
1342
|
+
|
|
1343
|
+
it('should validate a project without push configuration', async () => {
|
|
1344
|
+
delete project.push
|
|
1345
|
+
let Project = new ProjectModel(project)
|
|
1346
|
+
const res = await Project.validate()
|
|
1347
|
+
assert.notExists(res)
|
|
1348
|
+
})
|
|
1349
|
+
|
|
1350
|
+
it('should validate a project with only APNs configuration', async () => {
|
|
1351
|
+
delete project.push.fcm
|
|
1352
|
+
let Project = new ProjectModel(project)
|
|
1353
|
+
const res = await Project.validate()
|
|
1354
|
+
assert.notExists(res)
|
|
1355
|
+
})
|
|
1356
|
+
|
|
1357
|
+
it('should validate a project with only FCM configuration', async () => {
|
|
1358
|
+
delete project.push.apns
|
|
1359
|
+
let Project = new ProjectModel(project)
|
|
1360
|
+
const res = await Project.validate()
|
|
1361
|
+
assert.notExists(res)
|
|
1362
|
+
})
|
|
1363
|
+
|
|
1364
|
+
it('should validate APNs with development environment', async () => {
|
|
1365
|
+
project.push.apns.environment = 'development'
|
|
1366
|
+
let Project = new ProjectModel(project)
|
|
1367
|
+
const res = await Project.validate()
|
|
1368
|
+
assert.notExists(res)
|
|
1369
|
+
})
|
|
1370
|
+
})
|
|
1371
|
+
|
|
1372
|
+
describe('Invalid Push Configuration', () => {
|
|
1373
|
+
it('should throw an error when APNs environment is invalid', async () => {
|
|
1374
|
+
project.push.apns.environment = 'invalid'
|
|
1375
|
+
let Project = new ProjectModel(project)
|
|
1376
|
+
try {
|
|
1377
|
+
await Project.validate()
|
|
1378
|
+
} catch (err) {
|
|
1379
|
+
assert.exists(err, 'err object should exist')
|
|
1380
|
+
assert.match(err.message, /`invalid` is not a valid enum value for path `environment`/)
|
|
1381
|
+
}
|
|
1382
|
+
})
|
|
1383
|
+
|
|
1384
|
+
it('should throw an error when APNs teamId is missing', async () => {
|
|
1385
|
+
delete project.push.apns.teamId
|
|
1386
|
+
let Project = new ProjectModel(project)
|
|
1387
|
+
try {
|
|
1388
|
+
await Project.validate()
|
|
1389
|
+
} catch (err) {
|
|
1390
|
+
assert.exists(err, 'err object should exist')
|
|
1391
|
+
assert.match(err.message, /APNs teamId is required/)
|
|
1392
|
+
}
|
|
1393
|
+
})
|
|
1394
|
+
|
|
1395
|
+
it('should throw an error when APNs keyId is missing', async () => {
|
|
1396
|
+
delete project.push.apns.keyId
|
|
1397
|
+
let Project = new ProjectModel(project)
|
|
1398
|
+
try {
|
|
1399
|
+
await Project.validate()
|
|
1400
|
+
} catch (err) {
|
|
1401
|
+
assert.exists(err, 'err object should exist')
|
|
1402
|
+
assert.match(err.message, /APNs keyId is required/)
|
|
1403
|
+
}
|
|
1404
|
+
})
|
|
1405
|
+
|
|
1406
|
+
it('should throw an error when APNs bundleId is missing', async () => {
|
|
1407
|
+
delete project.push.apns.bundleId
|
|
1408
|
+
let Project = new ProjectModel(project)
|
|
1409
|
+
try {
|
|
1410
|
+
await Project.validate()
|
|
1411
|
+
} catch (err) {
|
|
1412
|
+
assert.exists(err, 'err object should exist')
|
|
1413
|
+
assert.match(err.message, /APNs bundleId is required/)
|
|
1414
|
+
}
|
|
1415
|
+
})
|
|
1416
|
+
|
|
1417
|
+
it('should throw an error when FCM isConfigured is missing', async () => {
|
|
1418
|
+
delete project.push.fcm.isConfigured
|
|
1419
|
+
let Project = new ProjectModel(project)
|
|
1420
|
+
try {
|
|
1421
|
+
await Project.validate()
|
|
1422
|
+
} catch (err) {
|
|
1423
|
+
assert.exists(err, 'err object should exist')
|
|
1424
|
+
assert.match(err.message, /FCM isConfigured is required/)
|
|
1425
|
+
}
|
|
1426
|
+
})
|
|
1427
|
+
})
|
|
1428
|
+
})
|
|
1153
1429
|
})
|
package/models/Project.js
CHANGED
|
@@ -19,6 +19,8 @@ let projectTempoSchema = require('../schemas/ProjectTempo')
|
|
|
19
19
|
let projectHelloSchema = require('../schemas/ProjectHello')
|
|
20
20
|
let reportConfigurationSchema = require('../schemas/ReportConfiguration')
|
|
21
21
|
let insightsConfigurationSchema = require('../schemas/InsightsConfiguration')
|
|
22
|
+
let CampaignSchema = require('../schemas/Campaign')
|
|
23
|
+
let PushConfigurationSchema = require('../schemas/PushConfiguration')
|
|
22
24
|
|
|
23
25
|
let webhooksValidators = [
|
|
24
26
|
{validator: helpers.validateNotNull},
|
|
@@ -59,7 +61,9 @@ let ProjectSchema = new mongoose.Schema({
|
|
|
59
61
|
tempo: projectTempoSchema,
|
|
60
62
|
hello: projectHelloSchema,
|
|
61
63
|
reportConfigurations: {type: [reportConfigurationSchema], validate: reportConfigurationsValidators},
|
|
62
|
-
insightsConfiguration: insightsConfigurationSchema
|
|
64
|
+
insightsConfiguration: insightsConfigurationSchema,
|
|
65
|
+
campaigns: {type: [CampaignSchema]},
|
|
66
|
+
push: {type: PushConfigurationSchema, required: false}
|
|
63
67
|
},
|
|
64
68
|
{collection: 'project'})
|
|
65
69
|
|
package/package.json
CHANGED
|
@@ -27,7 +27,8 @@ let AccountFeaturesSchema = new mongoose.Schema({
|
|
|
27
27
|
helloSso: { type: HelloSsoSchema, validate: { validator: helloSsoValidator, msg: 'When the feature is enbaled, at leat one of provider need to be provided.' } },
|
|
28
28
|
canvasSso: CanvasSsoSchema,
|
|
29
29
|
helloStateTemplates: AccountBasicFeatureSchema,
|
|
30
|
-
helloStack: HelloStackSchema
|
|
30
|
+
helloStack: HelloStackSchema,
|
|
31
|
+
pushNotifications: AccountBasicFeatureSchema
|
|
31
32
|
}, {
|
|
32
33
|
_id: false
|
|
33
34
|
})
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
let mongoose = require('mongoose')
|
|
2
|
+
|
|
3
|
+
let ApnsConfigurationSchema = new mongoose.Schema({
|
|
4
|
+
environment: {
|
|
5
|
+
type: String,
|
|
6
|
+
required: [true, 'APNs environment is required'],
|
|
7
|
+
enum: ['production', 'development']
|
|
8
|
+
},
|
|
9
|
+
teamId: {
|
|
10
|
+
type: String,
|
|
11
|
+
required: [true, 'APNs teamId is required'],
|
|
12
|
+
maxlength: [20, 'APNs teamId cannot exceed 20 characters']
|
|
13
|
+
},
|
|
14
|
+
keyId: {
|
|
15
|
+
type: String,
|
|
16
|
+
required: [true, 'APNs keyId is required'],
|
|
17
|
+
maxlength: [20, 'APNs keyId cannot exceed 20 characters']
|
|
18
|
+
},
|
|
19
|
+
bundleId: {
|
|
20
|
+
type: String,
|
|
21
|
+
required: [true, 'APNs bundleId is required'],
|
|
22
|
+
maxlength: [200, 'APNs bundleId cannot exceed 200 characters']
|
|
23
|
+
}
|
|
24
|
+
}, {
|
|
25
|
+
_id: false
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
module.exports = ApnsConfigurationSchema
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
let mongoose = require('mongoose')
|
|
2
|
+
let uuidv4 = require('uuid/v4')
|
|
3
|
+
let CampaignNotificationSchema = require('./CampaignNotification')
|
|
4
|
+
let CampaignZoneSchema = require('./CampaignZone')
|
|
5
|
+
|
|
6
|
+
let CampaignSchema = new mongoose.Schema({
|
|
7
|
+
_id: {
|
|
8
|
+
type: String,
|
|
9
|
+
default: uuidv4
|
|
10
|
+
},
|
|
11
|
+
type: {
|
|
12
|
+
type: String,
|
|
13
|
+
required: [true, 'campaign type is required'],
|
|
14
|
+
enum: ['entry', 'dwell', 'exit']
|
|
15
|
+
},
|
|
16
|
+
notification: {
|
|
17
|
+
type: CampaignNotificationSchema,
|
|
18
|
+
required: [true, 'campaign notification is required']
|
|
19
|
+
},
|
|
20
|
+
zones: {
|
|
21
|
+
type: [CampaignZoneSchema],
|
|
22
|
+
required: [true, 'campaign zones are required'],
|
|
23
|
+
validate: {
|
|
24
|
+
validator: function(zones) {
|
|
25
|
+
return zones && zones.length > 0
|
|
26
|
+
},
|
|
27
|
+
msg: 'campaign must have at least one zone'
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
status: {
|
|
31
|
+
type: String,
|
|
32
|
+
required: [true, 'campaign status is required'],
|
|
33
|
+
enum: ['active', 'draft', 'paused']
|
|
34
|
+
},
|
|
35
|
+
createdAt: {
|
|
36
|
+
type: Date,
|
|
37
|
+
default: Date.now
|
|
38
|
+
},
|
|
39
|
+
updatedAt: {
|
|
40
|
+
type: Date,
|
|
41
|
+
default: Date.now
|
|
42
|
+
}
|
|
43
|
+
}, {
|
|
44
|
+
_id: false
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
module.exports = CampaignSchema
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
let mongoose = require('mongoose')
|
|
2
|
+
|
|
3
|
+
let CampaignNotificationSchema = new mongoose.Schema({
|
|
4
|
+
title: {
|
|
5
|
+
type: String,
|
|
6
|
+
required: [true, 'notification title is required'],
|
|
7
|
+
maxlength: [200, 'notification title cannot exceed 200 characters']
|
|
8
|
+
},
|
|
9
|
+
body: {
|
|
10
|
+
type: String,
|
|
11
|
+
required: [true, 'notification body is required'],
|
|
12
|
+
maxlength: [1000, 'notification body cannot exceed 1000 characters']
|
|
13
|
+
}
|
|
14
|
+
}, {
|
|
15
|
+
_id: false
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
module.exports = CampaignNotificationSchema
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
let mongoose = require('mongoose')
|
|
2
|
+
let helpers = require('../helpers')
|
|
3
|
+
|
|
4
|
+
let CampaignZoneSchema = new mongoose.Schema({
|
|
5
|
+
id: {
|
|
6
|
+
type: String,
|
|
7
|
+
required: [true, 'zone id is required'],
|
|
8
|
+
validate: {
|
|
9
|
+
validator: helpers.validateUUIDv4,
|
|
10
|
+
msg: 'zone id must be a valid UUID'
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
name: {
|
|
14
|
+
type: String,
|
|
15
|
+
required: [true, 'zone name is required']
|
|
16
|
+
},
|
|
17
|
+
destinationId: {
|
|
18
|
+
type: String,
|
|
19
|
+
required: false
|
|
20
|
+
}
|
|
21
|
+
}, {
|
|
22
|
+
_id: false
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
module.exports = CampaignZoneSchema
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
let mongoose = require('mongoose')
|
|
2
|
+
let ApnsConfigurationSchema = require('./ApnsConfiguration')
|
|
3
|
+
let FcmConfigurationSchema = require('./FcmConfiguration')
|
|
4
|
+
|
|
5
|
+
let PushConfigurationSchema = new mongoose.Schema({
|
|
6
|
+
apns: {
|
|
7
|
+
type: ApnsConfigurationSchema,
|
|
8
|
+
required: false
|
|
9
|
+
},
|
|
10
|
+
fcm: {
|
|
11
|
+
type: FcmConfigurationSchema,
|
|
12
|
+
required: false
|
|
13
|
+
}
|
|
14
|
+
}, {
|
|
15
|
+
_id: false
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
module.exports = PushConfigurationSchema
|