@appxdigital/appx-core 0.1.97 → 0.1.98
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.
|
@@ -90,6 +90,7 @@ export declare class PrismaService {
|
|
|
90
90
|
* @param modelName - The name of the model being queried.
|
|
91
91
|
* @param omitFields - A list of fields to omit based on the user's role.
|
|
92
92
|
* @param includeRelations - The relations to include in the query.
|
|
93
|
+
* @param defaultSelect - The select object provided in the query arguments.
|
|
93
94
|
* @param userRole - The role of the user making the request.
|
|
94
95
|
* @returns A `select` object for Prisma queries.
|
|
95
96
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prisma.service.d.ts","sourceRoot":"","sources":["../../src/prisma/prisma.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,MAAM,EAAE,YAAY,EAAC,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAC,qBAAqB,EAAC,MAAM,yCAAyC,CAAC;AAE9E,OAAO,KAAK,EAAC,YAAY,IAAI,aAAa,EAAC,MAAM,gBAAgB,CAAC;AAGlE,KAAK,QAAQ,GAAG,MAAM,aAAa,CAAC;AAEpC,oDAAoD;AACpD,MAAM,MAAM,iBAAiB,GAAG;IAC5B,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC9B,CAAC;AAGF,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,QAAQ,IAAI,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,YAAY,GAAG,mBAAmB,GAAG,QAAQ,GAAG,QAAQ,CAAC,CAAC;AAEtI,qBACa,aAAa;IAMY,OAAO,CAAC,QAAQ,CAAC,iBAAiB;IALpE,OAAO,CAAC,YAAY,CAA2B;IAC/C,YAAY,EAAE,YAAY,CAAC;gBAGvB,YAAY,EAAE,YAAY,EACqB,iBAAiB,EAAE,qBAAqB;IAO3F,YAAY,CAAC,MAAM,EAAE,OAAO;IAI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194,11 +194,11 @@ let PrismaService = class PrismaService {
|
|
|
194
194
|
}
|
|
195
195
|
else if (args.include) {
|
|
196
196
|
this.debug(`Found included model '${modelName}', generating select fields`);
|
|
197
|
-
args.select = this.buildSelectFields(modelName, omitFields, args.include, userRole);
|
|
197
|
+
args.select = this.buildSelectFields(modelName, omitFields, args.include, null, userRole);
|
|
198
198
|
delete args.include;
|
|
199
199
|
}
|
|
200
200
|
else {
|
|
201
|
-
args.select = this.buildSelectFields(modelName, omitFields, null, userRole);
|
|
201
|
+
args.select = this.buildSelectFields(modelName, omitFields, null, null, userRole);
|
|
202
202
|
}
|
|
203
203
|
return args;
|
|
204
204
|
}
|
|
@@ -249,11 +249,16 @@ let PrismaService = class PrismaService {
|
|
|
249
249
|
// If field is relation
|
|
250
250
|
let relation = this.getRelation(modelName, field);
|
|
251
251
|
if (!relation) {
|
|
252
|
+
if (field === '_count') {
|
|
253
|
+
// TODO implement filtering on _count
|
|
254
|
+
// args.select[field] = this.applyWhereConditions(modelName, userRole, args.select[field], user, action);
|
|
255
|
+
}
|
|
252
256
|
continue;
|
|
253
257
|
}
|
|
254
258
|
if (relation.relation === 'belongsTo') {
|
|
255
259
|
this.debug(`Found 1:1 / *:1 (belongsTo) relation to model '${relation.model}' from model '${modelName}' via field '${field}'. Filter will be applied to main conditions...`);
|
|
256
|
-
|
|
260
|
+
// findFirst permissions for related model
|
|
261
|
+
const relatedPermissions = this.selectPermission(permissionsConfig[relation.model.toLowerCase()]?.[userRole] || {}, 'findFirst', relation.model, userRole);
|
|
257
262
|
// If model is exposed, do not apply conditions
|
|
258
263
|
if (nestjs_request_context_1.RequestContext.currentContext?.req.prismaExposedModels?.map((m) => m.toLowerCase()).includes(relation.model.toLowerCase())) {
|
|
259
264
|
this.debug(`Related model '${relation.model}' is exposed via @Permission() decorator. Skipping conditions for action '${String(action)}' on role ${userRole}.`);
|
|
@@ -289,7 +294,11 @@ let PrismaService = class PrismaService {
|
|
|
289
294
|
},
|
|
290
295
|
})
|
|
291
296
|
*/
|
|
292
|
-
|
|
297
|
+
if (args.select[field] === true) {
|
|
298
|
+
args.select[field] = {};
|
|
299
|
+
}
|
|
300
|
+
// findMany permissions for related model
|
|
301
|
+
args.select[field].where = this.applyWhereConditions(relation.model, userRole, args.select[field], user, 'findMany').where;
|
|
293
302
|
delete args.select[field].select.where;
|
|
294
303
|
}
|
|
295
304
|
}
|
|
@@ -400,16 +409,30 @@ let PrismaService = class PrismaService {
|
|
|
400
409
|
* @param modelName - The name of the model being queried.
|
|
401
410
|
* @param omitFields - A list of fields to omit based on the user's role.
|
|
402
411
|
* @param includeRelations - The relations to include in the query.
|
|
412
|
+
* @param defaultSelect - The select object provided in the query arguments.
|
|
403
413
|
* @param userRole - The role of the user making the request.
|
|
404
414
|
* @returns A `select` object for Prisma queries.
|
|
405
415
|
*/
|
|
406
|
-
buildSelectFields(modelName, omitFields, includeRelations, userRole) {
|
|
416
|
+
buildSelectFields(modelName, omitFields, includeRelations, defaultSelect, userRole) {
|
|
407
417
|
const modelInfo = this.fieldConfigs[modelName.toLowerCase()];
|
|
408
418
|
if (!modelInfo) {
|
|
409
419
|
return {};
|
|
410
420
|
}
|
|
411
|
-
|
|
421
|
+
let { scalarFields, relationFields } = modelInfo;
|
|
412
422
|
const selectFields = {};
|
|
423
|
+
// If defaultSelect is provided, only include those fields
|
|
424
|
+
if (defaultSelect) {
|
|
425
|
+
// Use default select but separate scalar and relation fields. If not in any, consider relation
|
|
426
|
+
scalarFields = Object.keys(defaultSelect).filter((field) => modelInfo.scalarFields.includes(field));
|
|
427
|
+
relationFields = Object.keys(defaultSelect).filter((field) => !modelInfo.scalarFields.includes(field) || field === '_count').reduce((acc, field) => {
|
|
428
|
+
acc[field] = defaultSelect[field];
|
|
429
|
+
return acc;
|
|
430
|
+
}, {});
|
|
431
|
+
// Merge with includeRelations if any
|
|
432
|
+
if (Object.keys(relationFields).length > 0) {
|
|
433
|
+
includeRelations = { ...(includeRelations || {}), ...relationFields };
|
|
434
|
+
}
|
|
435
|
+
}
|
|
413
436
|
for (const field of scalarFields) {
|
|
414
437
|
if (!omitFields.includes(field)) {
|
|
415
438
|
selectFields[field] = true;
|
|
@@ -417,16 +440,27 @@ let PrismaService = class PrismaService {
|
|
|
417
440
|
}
|
|
418
441
|
if (includeRelations) {
|
|
419
442
|
for (const relationKey in includeRelations) {
|
|
420
|
-
if (!relationFields[relationKey])
|
|
443
|
+
if (!relationFields[relationKey] && relationKey !== '_count')
|
|
421
444
|
continue;
|
|
422
445
|
let includedArgs = includeRelations[relationKey];
|
|
423
446
|
if (includedArgs === true) {
|
|
424
447
|
includedArgs = {};
|
|
425
448
|
}
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
449
|
+
let relatedSelectFields = {};
|
|
450
|
+
if (relationKey === '_count') {
|
|
451
|
+
if (includedArgs.select) {
|
|
452
|
+
relatedSelectFields = includedArgs.select;
|
|
453
|
+
omitFields.forEach((field) => {
|
|
454
|
+
delete relatedSelectFields[field];
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
else {
|
|
459
|
+
const relatedModelName = this.getRelation(modelName, relationKey, true).model;
|
|
460
|
+
this.debug(`Found relation to model '${relatedModelName}' from model '${modelName}' via field '${relationKey}'. Generating select fields...`);
|
|
461
|
+
const relatedModelOmitFields = this.getFieldsToOmit(relatedModelName, userRole);
|
|
462
|
+
relatedSelectFields = this.buildSelectFields(relatedModelName, relatedModelOmitFields, includedArgs.include || null, includedArgs.select || null, userRole);
|
|
463
|
+
}
|
|
430
464
|
if (Object.keys(relatedSelectFields).length > 0) {
|
|
431
465
|
selectFields[relationKey] = { select: relatedSelectFields };
|
|
432
466
|
}
|
package/package.json
CHANGED