vanta-api 1.0.5 → 1.1.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/package.json +1 -1
- package/src/api-features.js +3 -11
package/package.json
CHANGED
package/src/api-features.js
CHANGED
|
@@ -3,7 +3,6 @@ import winston from "winston";
|
|
|
3
3
|
import { securityConfig } from "./config.js";
|
|
4
4
|
import HandleERROR from "./handleError.js";
|
|
5
5
|
|
|
6
|
-
// تنظیم logger با winston
|
|
7
6
|
const logger = winston.createLogger({
|
|
8
7
|
level: "info",
|
|
9
8
|
format: winston.format.combine(
|
|
@@ -21,7 +20,6 @@ export class ApiFeatures {
|
|
|
21
20
|
this.pipeline = [];
|
|
22
21
|
this.countPipeline = [];
|
|
23
22
|
this.manualFilters = {};
|
|
24
|
-
// انتخاب استفاده از cursor برای پردازش دادههای حجیم
|
|
25
23
|
this.useCursor = false;
|
|
26
24
|
this.#initialSanitization();
|
|
27
25
|
}
|
|
@@ -33,7 +31,6 @@ export class ApiFeatures {
|
|
|
33
31
|
const safeFilters = this.#applySecurityFilters(mergedFilters);
|
|
34
32
|
|
|
35
33
|
if (Object.keys(safeFilters).length > 0) {
|
|
36
|
-
// اضافه کردن فیلتر به ابتدای pipeline جهت بهبود عملکرد
|
|
37
34
|
this.pipeline.push({ $match: safeFilters });
|
|
38
35
|
this.countPipeline.push({ $match: safeFilters });
|
|
39
36
|
}
|
|
@@ -137,11 +134,11 @@ export class ApiFeatures {
|
|
|
137
134
|
lookupStage = {
|
|
138
135
|
$lookup: {
|
|
139
136
|
from: collection,
|
|
140
|
-
let: {
|
|
137
|
+
let: { localId: `$${field}` },
|
|
141
138
|
pipeline: [
|
|
142
139
|
{
|
|
143
140
|
$match: {
|
|
144
|
-
$expr: { $eq: ["$_id", "$$
|
|
141
|
+
$expr: { $eq: ["$_id", "$$localId"] }
|
|
145
142
|
}
|
|
146
143
|
},
|
|
147
144
|
{ $project: projection }
|
|
@@ -295,13 +292,8 @@ export class ApiFeatures {
|
|
|
295
292
|
throw new HandleERROR(`Invalid populate field: ${field}`, 400);
|
|
296
293
|
}
|
|
297
294
|
|
|
298
|
-
const refModel = mongoose.model(schemaPath.options.ref);
|
|
299
|
-
if (refModel.schema.options.restricted && this.userRole !== "admin") {
|
|
300
|
-
throw new HandleERROR(`Unauthorized to populate ${field}`, 403);
|
|
301
|
-
}
|
|
302
|
-
|
|
303
295
|
return {
|
|
304
|
-
collection:
|
|
296
|
+
collection: schemaPath.options.ref.toLowerCase()+'s',
|
|
305
297
|
isArray: schemaPath.instance === "Array"
|
|
306
298
|
};
|
|
307
299
|
}
|