soajs.multitenant 2.1.18 → 2.1.19
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/Gruntfile.js +1 -1
- package/_index.js +7 -1
- package/bl/tenant.js +19 -2
- package/config.js +14 -0
- package/model/mongo/tenant.js +49 -0
- package/package.json +1 -1
package/Gruntfile.js
CHANGED
|
@@ -197,7 +197,7 @@ module.exports = function (grunt) {
|
|
|
197
197
|
// When true, grunt-coveralls will only print a warning rather than
|
|
198
198
|
// an error, to prevent CI builds from failing unnecessarily (e.g. if
|
|
199
199
|
// coveralls.io is down). Optional, defaults to false.
|
|
200
|
-
force:
|
|
200
|
+
force: true
|
|
201
201
|
},
|
|
202
202
|
your_target: {
|
|
203
203
|
// Target-specific LCOV coverage file
|
package/_index.js
CHANGED
|
@@ -514,7 +514,13 @@ function run(serviceStartCb) {
|
|
|
514
514
|
return res.json(req.soajs.buildResponse(error, data));
|
|
515
515
|
});
|
|
516
516
|
});
|
|
517
|
-
|
|
517
|
+
|
|
518
|
+
service.get("/admin/tenants", (req, res) => {
|
|
519
|
+
bl.tenant.getByIds(req.soajs, req.soajs.inputmaskData, (error, data) => {
|
|
520
|
+
return res.json(req.soajs.buildResponse(error, data));
|
|
521
|
+
});
|
|
522
|
+
});
|
|
523
|
+
|
|
518
524
|
service.get("/tenant/console", (req, res) => {
|
|
519
525
|
req.soajs.inputmaskData.soajs = true;
|
|
520
526
|
bl.tenant.get(req.soajs, req.soajs.inputmaskData, (error, data) => {
|
package/bl/tenant.js
CHANGED
|
@@ -218,7 +218,7 @@ let bl = {
|
|
|
218
218
|
data.id = inputmaskData.id;
|
|
219
219
|
data.code = inputmaskData.code;
|
|
220
220
|
data.name = inputmaskData.name;
|
|
221
|
-
|
|
221
|
+
|
|
222
222
|
if (!data.id && !data.code && !data.name) {
|
|
223
223
|
data.id = soajs.tenant.id;
|
|
224
224
|
}
|
|
@@ -234,7 +234,24 @@ let bl = {
|
|
|
234
234
|
return cb(null, record);
|
|
235
235
|
});
|
|
236
236
|
},
|
|
237
|
-
|
|
237
|
+
|
|
238
|
+
"getByIds": (soajs, inputmaskData, cb) => {
|
|
239
|
+
if (!inputmaskData || !inputmaskData.ids) {
|
|
240
|
+
return cb(bl.handleError(soajs, 400, null));
|
|
241
|
+
}
|
|
242
|
+
let modelObj = bl.mp.getModel(soajs);
|
|
243
|
+
let data = {
|
|
244
|
+
ids: inputmaskData.ids
|
|
245
|
+
};
|
|
246
|
+
modelObj.getTenantsById(data, (err, result) => {
|
|
247
|
+
bl.mp.closeModel(soajs, modelObj);
|
|
248
|
+
if (err) {
|
|
249
|
+
return cb(bl.handleError(soajs, 602, err));
|
|
250
|
+
}
|
|
251
|
+
return cb(null, result);
|
|
252
|
+
});
|
|
253
|
+
},
|
|
254
|
+
|
|
238
255
|
"list": (soajs, inputmaskData, cb) => {
|
|
239
256
|
if (!inputmaskData) {
|
|
240
257
|
return cb(bl.handleError(soajs, 400, null));
|
package/config.js
CHANGED
|
@@ -961,6 +961,20 @@ module.exports = {
|
|
|
961
961
|
"commonFields": ['appId', 'key']
|
|
962
962
|
},
|
|
963
963
|
|
|
964
|
+
"/admin/tenants": {
|
|
965
|
+
_apiInfo: {
|
|
966
|
+
"l": "Get admin tenants by ids",
|
|
967
|
+
"group": "Admin Tenant"
|
|
968
|
+
},
|
|
969
|
+
"ids": {
|
|
970
|
+
"source": ['query.ids'],
|
|
971
|
+
"required": true,
|
|
972
|
+
"validation": {
|
|
973
|
+
'type': 'array',
|
|
974
|
+
'items': { 'type': 'string' }
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
},
|
|
964
978
|
"/admin/tenant": {
|
|
965
979
|
_apiInfo: {
|
|
966
980
|
"l": "Get admin tenant",
|
package/model/mongo/tenant.js
CHANGED
|
@@ -107,6 +107,55 @@ Tenant.prototype.getTenants = function (data, cb) {
|
|
|
107
107
|
__self.mongoCore.find(colName, condition, null, cb);
|
|
108
108
|
};
|
|
109
109
|
|
|
110
|
+
Tenant.prototype.getTenantsById = function (data, cb) {
|
|
111
|
+
let __self = this;
|
|
112
|
+
if (!data || !data.ids || !Array.isArray(data.ids) || data.ids.length === 0) {
|
|
113
|
+
let error = new Error("Array of ids is required.");
|
|
114
|
+
return cb(error, null);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
let objectIds = data.ids.map(id => __self.mongoCore.ObjectId(id));
|
|
118
|
+
|
|
119
|
+
let pipeline = [
|
|
120
|
+
{ "$match": { "_id": { "$in": objectIds } } },
|
|
121
|
+
{
|
|
122
|
+
"$facet": {
|
|
123
|
+
"count": [{ "$count": "count" }],
|
|
124
|
+
"items": [
|
|
125
|
+
{
|
|
126
|
+
"$project": {
|
|
127
|
+
"_id": 1,
|
|
128
|
+
"name": 1
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
]
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
{ "$unwind": { "path": "$count", "preserveNullAndEmptyArrays": true } },
|
|
135
|
+
{
|
|
136
|
+
"$project": {
|
|
137
|
+
"items": "$items",
|
|
138
|
+
"count": { "$ifNull": ["$count.count", 0] }
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
];
|
|
142
|
+
|
|
143
|
+
__self.mongoCore.aggregate(colName, pipeline, {}, (err, cursor) => {
|
|
144
|
+
if (err) {
|
|
145
|
+
return cb(err);
|
|
146
|
+
}
|
|
147
|
+
cursor.toArray((err, response) => {
|
|
148
|
+
if (err) {
|
|
149
|
+
return cb(err);
|
|
150
|
+
}
|
|
151
|
+
if (response && response[0]) {
|
|
152
|
+
return cb(null, response[0]);
|
|
153
|
+
}
|
|
154
|
+
return cb(null, { items: [], count: 0 });
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
};
|
|
158
|
+
|
|
110
159
|
Tenant.prototype.getTenant = function (data, cb) {
|
|
111
160
|
let __self = this;
|
|
112
161
|
if (!data || !(data.id || data.code || data.name)) {
|