soajs.multitenant 2.1.9 → 2.1.11
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/.travis.yml +2 -3
- package/_index.js +6 -0
- package/bl/tenant.js +14 -0
- package/config.js +20 -0
- package/model/mongo/tenant.js +101 -85
- package/package.json +10 -10
- package/test/integration/tenant/delete/deleteTenants.test.js +96 -0
- package/test/integration/tenant/tenant.test.js +1 -0
package/.travis.yml
CHANGED
package/_index.js
CHANGED
|
@@ -844,6 +844,12 @@ function run(serviceStartCb) {
|
|
|
844
844
|
});
|
|
845
845
|
//* DELETE
|
|
846
846
|
|
|
847
|
+
service.delete("/tenants", (req, res) => {
|
|
848
|
+
bl.tenant.deleteMany(req.soajs, req.soajs.inputmaskData, (error, data) => {
|
|
849
|
+
return res.json(req.soajs.buildResponse(error, data));
|
|
850
|
+
});
|
|
851
|
+
});
|
|
852
|
+
|
|
847
853
|
service.delete("/tenant", (req, res) => {
|
|
848
854
|
bl.tenant.delete(req.soajs, req.soajs.inputmaskData, (error, data) => {
|
|
849
855
|
return res.json(req.soajs.buildResponse(error, data));
|
package/bl/tenant.js
CHANGED
|
@@ -1425,6 +1425,20 @@ let bl = {
|
|
|
1425
1425
|
});
|
|
1426
1426
|
},
|
|
1427
1427
|
|
|
1428
|
+
"deleteMany": (soajs, inputmaskData, cb) => {
|
|
1429
|
+
if (!inputmaskData) {
|
|
1430
|
+
return cb(bl.handleError(soajs, 400, null));
|
|
1431
|
+
}
|
|
1432
|
+
let modelObj = bl.mp.getModel(soajs);
|
|
1433
|
+
modelObj.deleteTenants(inputmaskData, (err, result) => {
|
|
1434
|
+
bl.mp.closeModel(soajs, modelObj);
|
|
1435
|
+
if (err) {
|
|
1436
|
+
return cb(bl.handleError(soajs, 602, err));
|
|
1437
|
+
}
|
|
1438
|
+
return cb(null, result);
|
|
1439
|
+
});
|
|
1440
|
+
},
|
|
1441
|
+
|
|
1428
1442
|
"delete": (soajs, inputmaskData, cb) => {
|
|
1429
1443
|
if (!inputmaskData) {
|
|
1430
1444
|
return cb(bl.handleError(soajs, 400, null));
|
package/config.js
CHANGED
|
@@ -2145,6 +2145,26 @@ module.exports = {
|
|
|
2145
2145
|
}
|
|
2146
2146
|
},
|
|
2147
2147
|
|
|
2148
|
+
"/tenants": {
|
|
2149
|
+
_apiInfo: {
|
|
2150
|
+
"l": "Delete tenants",
|
|
2151
|
+
"group": "Tenant"
|
|
2152
|
+
},
|
|
2153
|
+
"ids": {
|
|
2154
|
+
"source": ['query.ids'],
|
|
2155
|
+
"validation": {
|
|
2156
|
+
"type": "array",
|
|
2157
|
+
"minItems": 1,
|
|
2158
|
+
"items": {
|
|
2159
|
+
"type": "string",
|
|
2160
|
+
"pattern": `^[a-f\\d]{24}$`,
|
|
2161
|
+
"errorMessage": {
|
|
2162
|
+
"pattern": "Tenant Id provided is not valid."
|
|
2163
|
+
}
|
|
2164
|
+
}
|
|
2165
|
+
}
|
|
2166
|
+
}
|
|
2167
|
+
},
|
|
2148
2168
|
"/tenant": {
|
|
2149
2169
|
_apiInfo: {
|
|
2150
2170
|
"l": "Delete tenant",
|
package/model/mongo/tenant.js
CHANGED
|
@@ -15,7 +15,7 @@ let indexing = {};
|
|
|
15
15
|
|
|
16
16
|
function Tenant(service, options, mongoCore) {
|
|
17
17
|
let __self = this;
|
|
18
|
-
|
|
18
|
+
|
|
19
19
|
if (mongoCore) {
|
|
20
20
|
__self.mongoCore = mongoCore;
|
|
21
21
|
}
|
|
@@ -26,23 +26,23 @@ function Tenant(service, options, mongoCore) {
|
|
|
26
26
|
let registry = service.registry.get();
|
|
27
27
|
__self.mongoCore = new Mongo(registry.coreDB.provision);
|
|
28
28
|
}
|
|
29
|
-
|
|
29
|
+
|
|
30
30
|
let index = "default";
|
|
31
31
|
if (options && options.index) {
|
|
32
32
|
index = options.index;
|
|
33
33
|
}
|
|
34
34
|
if (indexing && !indexing[index]) {
|
|
35
35
|
indexing[index] = true;
|
|
36
|
-
__self.mongoCore.createIndex(colName, {'code': 1}, {unique: true}, () => {
|
|
36
|
+
__self.mongoCore.createIndex(colName, { 'code': 1 }, { unique: true }, () => {
|
|
37
37
|
});
|
|
38
|
-
__self.mongoCore.createIndex(colName, {'_id': 1, 'locked': 1}, {}, () => {
|
|
38
|
+
__self.mongoCore.createIndex(colName, { '_id': 1, 'locked': 1 }, {}, () => {
|
|
39
39
|
});
|
|
40
|
-
__self.mongoCore.createIndex(colName, {'name': 1}, {}, () => {
|
|
40
|
+
__self.mongoCore.createIndex(colName, { 'name': 1 }, {}, () => {
|
|
41
41
|
});
|
|
42
|
-
__self.mongoCore.createIndex(colName, {'type': 1}, {}, () => {
|
|
42
|
+
__self.mongoCore.createIndex(colName, { 'type': 1 }, {}, () => {
|
|
43
43
|
});
|
|
44
|
-
|
|
45
|
-
__self.mongoCore.createIndex(colName, {'console': 1, 'type': 1, 'tenant.code': 1, 'name': 1, 'code': 1}, {
|
|
44
|
+
|
|
45
|
+
__self.mongoCore.createIndex(colName, { 'console': 1, 'type': 1, 'tenant.code': 1, 'name': 1, 'code': 1 }, {
|
|
46
46
|
partialFilterExpression: {
|
|
47
47
|
"tenant.code": {
|
|
48
48
|
"$exists": true
|
|
@@ -50,16 +50,16 @@ function Tenant(service, options, mongoCore) {
|
|
|
50
50
|
}
|
|
51
51
|
}, () => {
|
|
52
52
|
});
|
|
53
|
-
|
|
54
|
-
__self.mongoCore.createIndex(colName, {'console': 1, 'type': 1, 'name': 1, 'code': 1}, {}, () => {
|
|
53
|
+
|
|
54
|
+
__self.mongoCore.createIndex(colName, { 'console': 1, 'type': 1, 'name': 1, 'code': 1 }, {}, () => {
|
|
55
55
|
});
|
|
56
|
-
__self.mongoCore.createIndex(colName, {'_id': 1, 'console': 1}, {}, () => {
|
|
56
|
+
__self.mongoCore.createIndex(colName, { '_id': 1, 'console': 1 }, {}, () => {
|
|
57
57
|
});
|
|
58
|
-
__self.mongoCore.createIndex(colName, {'applications.keys.extKeys.env': 1}, {}, () => {
|
|
58
|
+
__self.mongoCore.createIndex(colName, { 'applications.keys.extKeys.env': 1 }, {}, () => {
|
|
59
59
|
});
|
|
60
|
-
__self.mongoCore.createIndex(colName, {'applications.keys.key': 1}, {}, () => {
|
|
60
|
+
__self.mongoCore.createIndex(colName, { 'applications.keys.key': 1 }, {}, () => {
|
|
61
61
|
});
|
|
62
|
-
|
|
62
|
+
|
|
63
63
|
service.log.debug("Tenant: Indexes for " + index + " Updated!");
|
|
64
64
|
}
|
|
65
65
|
}
|
|
@@ -67,12 +67,12 @@ function Tenant(service, options, mongoCore) {
|
|
|
67
67
|
|
|
68
68
|
Tenant.prototype.validateId = function (id, cb) {
|
|
69
69
|
let __self = this;
|
|
70
|
-
|
|
70
|
+
|
|
71
71
|
if (!id) {
|
|
72
72
|
let error = new Error("id is required.");
|
|
73
73
|
return cb(error, null);
|
|
74
74
|
}
|
|
75
|
-
|
|
75
|
+
|
|
76
76
|
try {
|
|
77
77
|
id = __self.mongoCore.ObjectId(id);
|
|
78
78
|
return cb(null, id);
|
|
@@ -87,23 +87,23 @@ Tenant.prototype.getTenants = function (data, cb) {
|
|
|
87
87
|
let error = new Error("Array of codes is required.");
|
|
88
88
|
return cb(error, null);
|
|
89
89
|
}
|
|
90
|
-
|
|
90
|
+
|
|
91
91
|
let partial = [
|
|
92
92
|
{
|
|
93
93
|
console: !!data.soajs
|
|
94
94
|
}
|
|
95
95
|
];
|
|
96
96
|
if (!data.soajs) {
|
|
97
|
-
partial.push({console: null});
|
|
97
|
+
partial.push({ console: null });
|
|
98
98
|
}
|
|
99
99
|
let condition = {
|
|
100
100
|
'$and': [{
|
|
101
101
|
"$or": partial
|
|
102
102
|
}]
|
|
103
103
|
};
|
|
104
|
-
|
|
105
|
-
condition.$and.push({'code': {'$in': data.codes}});
|
|
106
|
-
|
|
104
|
+
|
|
105
|
+
condition.$and.push({ 'code': { '$in': data.codes } });
|
|
106
|
+
|
|
107
107
|
__self.mongoCore.find(colName, condition, null, cb);
|
|
108
108
|
};
|
|
109
109
|
|
|
@@ -113,37 +113,37 @@ Tenant.prototype.getTenant = function (data, cb) {
|
|
|
113
113
|
let error = new Error("id, code, or name is required.");
|
|
114
114
|
return cb(error, null);
|
|
115
115
|
}
|
|
116
|
-
|
|
116
|
+
|
|
117
117
|
let partial = [
|
|
118
118
|
{
|
|
119
119
|
console: !!data.soajs
|
|
120
120
|
}
|
|
121
121
|
];
|
|
122
122
|
if (!data.soajs) {
|
|
123
|
-
partial.push({console: null});
|
|
123
|
+
partial.push({ console: null });
|
|
124
124
|
}
|
|
125
125
|
let condition = {
|
|
126
126
|
'$and': [{
|
|
127
127
|
"$or": partial
|
|
128
128
|
}]
|
|
129
129
|
};
|
|
130
|
-
|
|
130
|
+
|
|
131
131
|
if (data.id) {
|
|
132
132
|
__self.validateId(data.id, (err, id) => {
|
|
133
133
|
if (err) {
|
|
134
134
|
return cb(err, null);
|
|
135
135
|
}
|
|
136
|
-
condition.$and.push({'_id': id});
|
|
136
|
+
condition.$and.push({ '_id': id });
|
|
137
137
|
__self.mongoCore.findOne(colName, condition, null, cb);
|
|
138
138
|
});
|
|
139
139
|
} else if (data.code) {
|
|
140
|
-
condition.$and.push({'code': data.code});
|
|
140
|
+
condition.$and.push({ 'code': data.code });
|
|
141
141
|
__self.mongoCore.findOne(colName, condition, null, cb);
|
|
142
142
|
} else {
|
|
143
143
|
if (data.name) {
|
|
144
144
|
data.name = data.name.trim();
|
|
145
145
|
// data.name = data.name.toLowerCase();
|
|
146
|
-
condition.$and.push({'name': data.name});
|
|
146
|
+
condition.$and.push({ 'name': data.name });
|
|
147
147
|
}
|
|
148
148
|
__self.mongoCore.findOne(colName, condition, null, cb);
|
|
149
149
|
}
|
|
@@ -157,17 +157,17 @@ Tenant.prototype.listTenantSubTenants = function (data, cb) {
|
|
|
157
157
|
}
|
|
158
158
|
let condition = {
|
|
159
159
|
"$or": [
|
|
160
|
-
{console: false},
|
|
161
|
-
{console: null}
|
|
160
|
+
{ console: false },
|
|
161
|
+
{ console: null }
|
|
162
162
|
]
|
|
163
163
|
};
|
|
164
164
|
let andCond = [];
|
|
165
|
-
andCond.push({'type': "client"});
|
|
166
|
-
andCond.push({'tenant.code': data.code});
|
|
167
|
-
|
|
165
|
+
andCond.push({ 'type': "client" });
|
|
166
|
+
andCond.push({ 'tenant.code': data.code });
|
|
167
|
+
|
|
168
168
|
if (data.keywords) {
|
|
169
169
|
let rePattern = new RegExp(data.keywords, 'i');
|
|
170
|
-
andCond.push({"$or": [{"name": {"$regex": rePattern}}, {"code": {"$regex": rePattern}}]});
|
|
170
|
+
andCond.push({ "$or": [{ "name": { "$regex": rePattern } }, { "code": { "$regex": rePattern } }] });
|
|
171
171
|
}
|
|
172
172
|
if (andCond.length > 0) {
|
|
173
173
|
condition.$and = andCond;
|
|
@@ -175,7 +175,7 @@ Tenant.prototype.listTenantSubTenants = function (data, cb) {
|
|
|
175
175
|
let options = {
|
|
176
176
|
"skip": 0,
|
|
177
177
|
"limit": 50,
|
|
178
|
-
"sort": {"name": 1}
|
|
178
|
+
"sort": { "name": 1 }
|
|
179
179
|
};
|
|
180
180
|
if (data && data.limit) {
|
|
181
181
|
options.limit = data.limit;
|
|
@@ -218,31 +218,31 @@ Tenant.prototype.listTenantSubTenants = function (data, cb) {
|
|
|
218
218
|
|
|
219
219
|
Tenant.prototype.listTenants = function (data, cb) {
|
|
220
220
|
let __self = this;
|
|
221
|
-
|
|
221
|
+
|
|
222
222
|
let condition = {
|
|
223
223
|
"$or": [
|
|
224
|
-
{"console": false},
|
|
225
|
-
{"console": null}
|
|
224
|
+
{ "console": false },
|
|
225
|
+
{ "console": null }
|
|
226
226
|
]
|
|
227
227
|
};
|
|
228
228
|
let andCond = [];
|
|
229
229
|
if (data && data.type) {
|
|
230
|
-
andCond.push({"type": data.type});
|
|
230
|
+
andCond.push({ "type": data.type });
|
|
231
231
|
}
|
|
232
232
|
if (data.keywords) {
|
|
233
233
|
let rePattern = new RegExp(data.keywords, 'i');
|
|
234
|
-
andCond.push({"$or": [{"name": {"$regex": rePattern}}, {"code": {"$regex": rePattern}}]});
|
|
234
|
+
andCond.push({ "$or": [{ "name": { "$regex": rePattern } }, { "code": { "$regex": rePattern } }] });
|
|
235
235
|
}
|
|
236
236
|
if (data.category) {
|
|
237
237
|
if (data.category === "tenant") {
|
|
238
238
|
andCond.push({
|
|
239
239
|
"$or": [
|
|
240
|
-
{"category": data.category},
|
|
241
|
-
{"category": null}
|
|
240
|
+
{ "category": data.category },
|
|
241
|
+
{ "category": null }
|
|
242
242
|
]
|
|
243
243
|
});
|
|
244
244
|
} else {
|
|
245
|
-
andCond.push({"category": data.category});
|
|
245
|
+
andCond.push({ "category": data.category });
|
|
246
246
|
}
|
|
247
247
|
}
|
|
248
248
|
if (andCond.length > 0) {
|
|
@@ -251,7 +251,7 @@ Tenant.prototype.listTenants = function (data, cb) {
|
|
|
251
251
|
let options = {
|
|
252
252
|
"skip": 0,
|
|
253
253
|
"limit": 500,
|
|
254
|
-
"sort": {"name": 1}
|
|
254
|
+
"sort": { "name": 1 }
|
|
255
255
|
};
|
|
256
256
|
if (data && data.limit) {
|
|
257
257
|
options.limit = data.limit;
|
|
@@ -294,19 +294,19 @@ Tenant.prototype.listTenants = function (data, cb) {
|
|
|
294
294
|
|
|
295
295
|
Tenant.prototype.count = function (data, condition, cb) {
|
|
296
296
|
let __self = this;
|
|
297
|
-
|
|
297
|
+
|
|
298
298
|
let options = {};
|
|
299
299
|
__self.mongoCore.countDocuments(colName, condition, options, cb);
|
|
300
|
-
|
|
300
|
+
|
|
301
301
|
};
|
|
302
302
|
|
|
303
303
|
Tenant.prototype.listConsoleTenants = function (data, cb) {
|
|
304
304
|
let __self = this;
|
|
305
|
-
|
|
305
|
+
|
|
306
306
|
let options = {
|
|
307
307
|
"skip": 0,
|
|
308
308
|
"limit": 500,
|
|
309
|
-
"sort": {"name": 1}
|
|
309
|
+
"sort": { "name": 1 }
|
|
310
310
|
};
|
|
311
311
|
if (data && data.limit) {
|
|
312
312
|
options.limit = data.limit;
|
|
@@ -315,28 +315,28 @@ Tenant.prototype.listConsoleTenants = function (data, cb) {
|
|
|
315
315
|
options.skip = data.start;
|
|
316
316
|
}
|
|
317
317
|
let condition = {
|
|
318
|
-
'$and': [{console: true}]
|
|
318
|
+
'$and': [{ console: true }]
|
|
319
319
|
};
|
|
320
320
|
if (data.keywords) {
|
|
321
321
|
let rePattern = new RegExp(data.keywords, 'i');
|
|
322
|
-
condition.$and.push({"$or": [{"name": {"$regex": rePattern}}, {"code": {"$regex": rePattern}}]});
|
|
322
|
+
condition.$and.push({ "$or": [{ "name": { "$regex": rePattern } }, { "code": { "$regex": rePattern } }] });
|
|
323
323
|
}
|
|
324
324
|
if (data && data.type) {
|
|
325
|
-
condition.$and.push({'type': data.type});
|
|
325
|
+
condition.$and.push({ 'type': data.type });
|
|
326
326
|
}
|
|
327
327
|
if (data.category) {
|
|
328
328
|
if (data.category === "tenant") {
|
|
329
329
|
condition.$and.push({
|
|
330
330
|
"$or": [
|
|
331
|
-
{"category": data.category},
|
|
332
|
-
{"category": null}
|
|
331
|
+
{ "category": data.category },
|
|
332
|
+
{ "category": null }
|
|
333
333
|
]
|
|
334
334
|
});
|
|
335
335
|
} else {
|
|
336
|
-
condition.$and.push({"category": data.category});
|
|
336
|
+
condition.$and.push({ "category": data.category });
|
|
337
337
|
}
|
|
338
338
|
}
|
|
339
|
-
|
|
339
|
+
|
|
340
340
|
let find = (condition) => {
|
|
341
341
|
__self.mongoCore.find(colName, condition, options, (error, response) => {
|
|
342
342
|
if (error) {
|
|
@@ -370,13 +370,13 @@ Tenant.prototype.listConsoleTenants = function (data, cb) {
|
|
|
370
370
|
}
|
|
371
371
|
});
|
|
372
372
|
};
|
|
373
|
-
|
|
373
|
+
|
|
374
374
|
if (data.scope === "other") {
|
|
375
375
|
__self.validateId(data.id, (err, id) => {
|
|
376
376
|
if (err) {
|
|
377
377
|
return cb(err, null);
|
|
378
378
|
}
|
|
379
|
-
condition.$and.push({"_id": {"$ne": id}});
|
|
379
|
+
condition.$and.push({ "_id": { "$ne": id } });
|
|
380
380
|
find(condition);
|
|
381
381
|
});
|
|
382
382
|
} else {
|
|
@@ -386,7 +386,7 @@ Tenant.prototype.listConsoleTenants = function (data, cb) {
|
|
|
386
386
|
|
|
387
387
|
Tenant.prototype.listAllTenants = function (data, cb) {
|
|
388
388
|
let __self = this;
|
|
389
|
-
|
|
389
|
+
|
|
390
390
|
let fields = null;
|
|
391
391
|
if (data) {
|
|
392
392
|
if (data.fields && Array.isArray(data.fields) && data.fields.length > 0) {
|
|
@@ -396,8 +396,8 @@ Tenant.prototype.listAllTenants = function (data, cb) {
|
|
|
396
396
|
});
|
|
397
397
|
}
|
|
398
398
|
}
|
|
399
|
-
|
|
400
|
-
__self.mongoCore.find(colName, {}, {"fields": fields}, cb);
|
|
399
|
+
|
|
400
|
+
__self.mongoCore.find(colName, {}, { "fields": fields }, cb);
|
|
401
401
|
};
|
|
402
402
|
|
|
403
403
|
Tenant.prototype.countTenants = function (data, cb) {
|
|
@@ -406,13 +406,13 @@ Tenant.prototype.countTenants = function (data, cb) {
|
|
|
406
406
|
let error = new Error("name is required.");
|
|
407
407
|
return cb(error, null);
|
|
408
408
|
}
|
|
409
|
-
|
|
409
|
+
|
|
410
410
|
data.name = data.name.trim();
|
|
411
411
|
// data.name = data.name.toLowerCase();
|
|
412
412
|
let condition = {
|
|
413
413
|
name: data.name
|
|
414
414
|
};
|
|
415
|
-
|
|
415
|
+
|
|
416
416
|
if (data.code) {
|
|
417
417
|
condition.code = data.code;
|
|
418
418
|
}
|
|
@@ -427,7 +427,7 @@ Tenant.prototype.generateId = function () {
|
|
|
427
427
|
|
|
428
428
|
Tenant.prototype.addTenant = function (data, cb) {
|
|
429
429
|
let __self = this;
|
|
430
|
-
|
|
430
|
+
|
|
431
431
|
if (!data || !data.code || !data.name) {
|
|
432
432
|
let error = new Error("name and code are required.");
|
|
433
433
|
return cb(error, null);
|
|
@@ -436,22 +436,38 @@ Tenant.prototype.addTenant = function (data, cb) {
|
|
|
436
436
|
// data.name = data.name.toLowerCase();
|
|
437
437
|
__self.mongoCore.insertOne(colName, data, {}, (err, record) => {
|
|
438
438
|
if (record && Array.isArray(record)) {
|
|
439
|
-
record = record
|
|
439
|
+
record = record[0];
|
|
440
440
|
}
|
|
441
441
|
return cb(err, record);
|
|
442
442
|
});
|
|
443
443
|
};
|
|
444
444
|
|
|
445
|
+
Tenant.prototype.deleteTenants = function (data, cb) {
|
|
446
|
+
let __self = this;
|
|
447
|
+
|
|
448
|
+
if (!data || !data.ids) {
|
|
449
|
+
let error = new Error("ids is required.");
|
|
450
|
+
return cb(error, null);
|
|
451
|
+
}
|
|
452
|
+
const objectIdsArray = data.ids.map((id) => __self.mongoCore.ObjectId(id));
|
|
453
|
+
let condition = {
|
|
454
|
+
"_id": { "$in": objectIdsArray }
|
|
455
|
+
};
|
|
456
|
+
__self.mongoCore.deleteMany(colName, condition, {}, (err, result) => {
|
|
457
|
+
return cb(err, result);
|
|
458
|
+
});
|
|
459
|
+
};
|
|
460
|
+
|
|
445
461
|
Tenant.prototype.deleteTenant = function (data, cb) {
|
|
446
462
|
let __self = this;
|
|
447
|
-
|
|
463
|
+
|
|
448
464
|
if (!data || !(data._id || data.code)) {
|
|
449
465
|
let error = new Error("id or code is required.");
|
|
450
466
|
return cb(error, null);
|
|
451
467
|
}
|
|
452
|
-
|
|
468
|
+
|
|
453
469
|
let condition = {};
|
|
454
|
-
|
|
470
|
+
|
|
455
471
|
if (data._id) {
|
|
456
472
|
condition._id = data._id;
|
|
457
473
|
} else {
|
|
@@ -468,42 +484,42 @@ Tenant.prototype.updateTenant = function (data, cb) {
|
|
|
468
484
|
let error = new Error("_id is required.");
|
|
469
485
|
return cb(error, null);
|
|
470
486
|
}
|
|
471
|
-
|
|
472
|
-
let condition = {'_id': data._id};
|
|
473
|
-
let options = {'upsert': false, 'safe': true};
|
|
487
|
+
|
|
488
|
+
let condition = { '_id': data._id };
|
|
489
|
+
let options = { 'upsert': false, 'safe': true };
|
|
474
490
|
let fields = {
|
|
475
491
|
'$set': {}
|
|
476
492
|
};
|
|
477
493
|
if (data.description) {
|
|
478
494
|
fields.$set.description = data.description;
|
|
479
495
|
}
|
|
480
|
-
|
|
496
|
+
|
|
481
497
|
if (data.name) {
|
|
482
498
|
data.name = data.name.trim();
|
|
483
499
|
// data.name = data.name.toLowerCase();
|
|
484
500
|
fields.$set.name = data.name;
|
|
485
501
|
}
|
|
486
|
-
|
|
502
|
+
|
|
487
503
|
if (data.tag) {
|
|
488
504
|
fields.$set.tag = data.tag;
|
|
489
505
|
}
|
|
490
|
-
|
|
506
|
+
|
|
491
507
|
if (data.category) {
|
|
492
508
|
fields.$set.category = data.category;
|
|
493
509
|
}
|
|
494
|
-
|
|
510
|
+
|
|
495
511
|
if (data.profile) {
|
|
496
512
|
fields.$set.profile = data.profile;
|
|
497
513
|
}
|
|
498
|
-
|
|
514
|
+
|
|
499
515
|
if (data.applications) {
|
|
500
516
|
fields.$set.applications = data.applications;
|
|
501
517
|
}
|
|
502
|
-
|
|
518
|
+
|
|
503
519
|
if (data.oauth) {
|
|
504
520
|
fields.$set.oauth = data.oauth;
|
|
505
521
|
}
|
|
506
|
-
|
|
522
|
+
|
|
507
523
|
if (Object.keys(fields.$set).length === 0) {
|
|
508
524
|
//nothing to update
|
|
509
525
|
return cb(null, 0);
|
|
@@ -524,7 +540,7 @@ Tenant.prototype.updateTenant = function (data, cb) {
|
|
|
524
540
|
return cb(err, result);
|
|
525
541
|
}
|
|
526
542
|
});
|
|
527
|
-
|
|
543
|
+
|
|
528
544
|
};
|
|
529
545
|
|
|
530
546
|
Tenant.prototype.removeApplication = function (data, cb) {
|
|
@@ -533,10 +549,10 @@ Tenant.prototype.removeApplication = function (data, cb) {
|
|
|
533
549
|
let error = new Error("_id and appId are required.");
|
|
534
550
|
return cb(error, null);
|
|
535
551
|
}
|
|
536
|
-
|
|
537
|
-
let condition = {'_id': data._id};
|
|
538
|
-
let options = {'upsert': false, 'safe': true};
|
|
539
|
-
|
|
552
|
+
|
|
553
|
+
let condition = { '_id': data._id };
|
|
554
|
+
let options = { 'upsert': false, 'safe': true };
|
|
555
|
+
|
|
540
556
|
try {
|
|
541
557
|
data.appId = __self.mongoCore.ObjectId(data.appId);
|
|
542
558
|
} catch (e) {
|
|
@@ -549,7 +565,7 @@ Tenant.prototype.removeApplication = function (data, cb) {
|
|
|
549
565
|
}
|
|
550
566
|
}
|
|
551
567
|
};
|
|
552
|
-
|
|
568
|
+
|
|
553
569
|
__self.mongoCore.updateOne(colName, condition, fields, options, (err, result) => {
|
|
554
570
|
if (err) {
|
|
555
571
|
return cb(err);
|
|
@@ -583,8 +599,8 @@ Tenant.prototype.removeApplicationKey = function (data, cb) {
|
|
|
583
599
|
'_id': data._id,
|
|
584
600
|
'applications.appId': data.appId
|
|
585
601
|
};
|
|
586
|
-
let options = {'upsert': false, 'safe': true};
|
|
587
|
-
|
|
602
|
+
let options = { 'upsert': false, 'safe': true };
|
|
603
|
+
|
|
588
604
|
let fields = {
|
|
589
605
|
'$pull': {
|
|
590
606
|
'applications.$.keys': {
|
|
@@ -592,7 +608,7 @@ Tenant.prototype.removeApplicationKey = function (data, cb) {
|
|
|
592
608
|
}
|
|
593
609
|
}
|
|
594
610
|
};
|
|
595
|
-
|
|
611
|
+
|
|
596
612
|
__self.mongoCore.updateOne(colName, condition, fields, options, (err, result) => {
|
|
597
613
|
if (err) {
|
|
598
614
|
return cb(err);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "soajs.multitenant",
|
|
3
3
|
"description": "soajs multitenant service",
|
|
4
|
-
"version": "2.1.
|
|
4
|
+
"version": "2.1.11",
|
|
5
5
|
"author": "soajs team <team@soajs.org>",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -19,24 +19,24 @@
|
|
|
19
19
|
"test": "grunt test"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"grunt": "1.
|
|
23
|
-
"grunt-contrib-clean": "2.0.
|
|
22
|
+
"grunt": "1.6.1",
|
|
23
|
+
"grunt-contrib-clean": "2.0.1",
|
|
24
24
|
"grunt-contrib-copy": "1.0.0",
|
|
25
|
-
"grunt-contrib-jshint": "2.
|
|
25
|
+
"grunt-contrib-jshint": "3.2.0",
|
|
26
26
|
"grunt-coveralls": "2.0.0",
|
|
27
27
|
"grunt-env": "1.0.1",
|
|
28
28
|
"grunt-istanbul": "0.8.0",
|
|
29
|
-
"grunt-jsdoc": "2.4.
|
|
29
|
+
"grunt-jsdoc": "2.4.1",
|
|
30
30
|
"grunt-mocha-test": "0.13.3",
|
|
31
|
-
"mocha": "
|
|
32
|
-
"nock": "13.
|
|
31
|
+
"mocha": "10.7.3",
|
|
32
|
+
"nock": "13.5.4",
|
|
33
33
|
"request": "2.88.2",
|
|
34
|
-
"soajs.controller": "4.2.
|
|
34
|
+
"soajs.controller": "4.2.15"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"async": "3.2.5",
|
|
38
|
-
"soajs": "4.1.
|
|
38
|
+
"soajs": "4.1.10",
|
|
39
39
|
"soajs.core.libs": "1.2.0",
|
|
40
|
-
"uuid": "
|
|
40
|
+
"uuid": "10.0.0"
|
|
41
41
|
}
|
|
42
42
|
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright SOAJS All Rights Reserved.
|
|
5
|
+
*
|
|
6
|
+
* Use of this source code is governed by an Apache license that can be
|
|
7
|
+
* found in the LICENSE file at the root of this repository
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
"use strict";
|
|
11
|
+
const assert = require('assert');
|
|
12
|
+
const requester = require('../../requester');
|
|
13
|
+
|
|
14
|
+
let params = {
|
|
15
|
+
body: {
|
|
16
|
+
"name": "tenant ddd1",
|
|
17
|
+
"code": "ddd1",
|
|
18
|
+
"description": "tenant delete",
|
|
19
|
+
"type": "product",
|
|
20
|
+
"profile": {},
|
|
21
|
+
"tag": "tag",
|
|
22
|
+
"oauth": {
|
|
23
|
+
"secret": "this is a secret test",
|
|
24
|
+
"redirectURI": "http://domain.com",
|
|
25
|
+
"grants": [
|
|
26
|
+
"password",
|
|
27
|
+
"refresh_token"
|
|
28
|
+
],
|
|
29
|
+
"disabled": 0,
|
|
30
|
+
"type": 1,
|
|
31
|
+
"loginMode": "urac"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
let ids = [];
|
|
36
|
+
|
|
37
|
+
describe("Testing delete tenants API", () => {
|
|
38
|
+
|
|
39
|
+
before(function (done) {
|
|
40
|
+
done();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
afterEach((done) => {
|
|
44
|
+
console.log("=======================================");
|
|
45
|
+
done();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("Success - will add ddd1 ", (done) => {
|
|
49
|
+
params.body.name = "tenant ddd1";
|
|
50
|
+
params.body.code = "ddd1";
|
|
51
|
+
|
|
52
|
+
requester('/tenant', 'post', params, (error, body) => {
|
|
53
|
+
assert.ifError(error);
|
|
54
|
+
assert.ok(body);
|
|
55
|
+
assert.ok(body.data);
|
|
56
|
+
ids.push(body.data._id);
|
|
57
|
+
done();
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
it("Success - will add ddd2 ", (done) => {
|
|
61
|
+
params.body.name = "tenant ddd2";
|
|
62
|
+
params.body.code = "ddd2";
|
|
63
|
+
|
|
64
|
+
requester('/tenant', 'post', params, (error, body) => {
|
|
65
|
+
assert.ifError(error);
|
|
66
|
+
assert.ok(body);
|
|
67
|
+
assert.ok(body.data);
|
|
68
|
+
ids.push(body.data._id);
|
|
69
|
+
done();
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
it("Success - will add ddd3 ", (done) => {
|
|
73
|
+
params.body.name = "tenant ddd3";
|
|
74
|
+
params.body.code = "ddd3";
|
|
75
|
+
|
|
76
|
+
requester('/tenant', 'post', params, (error, body) => {
|
|
77
|
+
assert.ifError(error);
|
|
78
|
+
assert.ok(body);
|
|
79
|
+
assert.ok(body.data);
|
|
80
|
+
ids.push(body.data._id);
|
|
81
|
+
done();
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("Success - delete tenants ", (done) => {
|
|
86
|
+
let params1 = { "qs": { "ids": ids } };
|
|
87
|
+
requester('/tenants', 'delete', params1, (error, body) => {
|
|
88
|
+
assert.ifError(error);
|
|
89
|
+
assert.ok(body);
|
|
90
|
+
assert.ok(body.data);
|
|
91
|
+
assert.strictEqual(body.data.deletedCount, 3);
|
|
92
|
+
done();
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
});
|