@solidstarters/solid-core 1.2.138 → 1.2.139

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidstarters/solid-core",
3
- "version": "1.2.138",
3
+ "version": "1.2.139",
4
4
  "description": "This module is a NestJS module containing all the required core providers required by a Solid application",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -9,9 +9,10 @@ export interface ManyToOneRelationFieldOptions {
9
9
  required: boolean | undefined | null;
10
10
  relationCoModelSingularName: string | undefined | null;
11
11
  fieldName: string | undefined | null;
12
- modelUserKeyFieldName: string | undefined | null;
12
+ // modelUserKeyFieldName: string | undefined | null;
13
13
  modelSingularName: string | undefined | null;
14
14
  entityManager: EntityManager;
15
+ relationCoModelUserKeyFieldName: string | undefined | null;
15
16
  }
16
17
 
17
18
  // This implementation is meant to be used for many-to-one relation field
@@ -50,8 +51,8 @@ export class ManyToOneRelationFieldCrudManager implements FieldCrudManager {
50
51
  private applyUserKeyFormatValidations(fieldUserKey: string): ValidationError[] {
51
52
  const errors: ValidationError[] = [];
52
53
  !isString(fieldUserKey) ? errors.push({ field: this.options.fieldName, error: 'Field is not a string' }) : "no errors";
53
- if (isEmpty(this.options.modelUserKeyFieldName)) {
54
- errors.push({ field: this.options.fieldName, error: `UserKey field name is not defined in the model ${this.options.modelSingularName}` });
54
+ if (isEmpty(this.options.relationCoModelUserKeyFieldName)) {
55
+ errors.push({ field: this.options.fieldName, error: `UserKey field name is not defined in the model ${this.options.relationCoModelSingularName}` });
55
56
  }
56
57
  return errors;
57
58
  }
@@ -72,9 +73,9 @@ export class ManyToOneRelationFieldCrudManager implements FieldCrudManager {
72
73
  }
73
74
  }
74
75
  else {
75
- dto[this.options.fieldName] = await this.options.entityManager.getRepository(entityTarget).findOneBy({ [this.options.modelUserKeyFieldName]: fieldUserKeyValue });
76
+ dto[this.options.fieldName] = await this.options.entityManager.getRepository(entityTarget).findOneBy({ [this.options.relationCoModelUserKeyFieldName]: fieldUserKeyValue });
76
77
  if (this.options.required && isEmpty(dto[this.options.fieldName])) {
77
- throw new Error(`ManyToOneRelationFieldCrudManager: Record with userKey: ${this.options.modelUserKeyFieldName}: ${fieldUserKeyValue} not found in ${this.options.relationCoModelSingularName}`);
78
+ throw new Error(`ManyToOneRelationFieldCrudManager: Record with userKey: ${this.options.relationCoModelUserKeyFieldName}: ${fieldUserKeyValue} not found in ${this.options.relationCoModelSingularName}`);
78
79
  }
79
80
  }
80
81
 
@@ -111,7 +111,7 @@ export class CRUDService<T> { // Add two generic value i.e Person,CreatePersonDt
111
111
  }
112
112
 
113
113
  private async validateAndTransformDto(field: FieldMetadata, dto: any, files: Express.Multer.File[], hasMediaFields: boolean, isPartialUpdate: boolean = false, isUpdate: boolean = false) {
114
- const fieldManager: FieldCrudManager = this.fieldCrudManager(field, this.entityManager, isPartialUpdate, isUpdate);
114
+ const fieldManager: FieldCrudManager = await this.fieldCrudManager(field, this.entityManager, isPartialUpdate, isUpdate);
115
115
  const validationErrors = fieldManager.validate(dto, files);
116
116
  const errors = (validationErrors instanceof Promise) ? await validationErrors : validationErrors;
117
117
  if (errors.length > 0) {
@@ -259,7 +259,7 @@ export class CRUDService<T> { // Add two generic value i.e Person,CreatePersonDt
259
259
  }
260
260
  }
261
261
 
262
- private fieldCrudManager(fieldMetadata: FieldMetadata, entityManager: EntityManager, isPartialUpdate: boolean = false, isUpdate: boolean = false): FieldCrudManager {
262
+ private async fieldCrudManager(fieldMetadata: FieldMetadata, entityManager: EntityManager, isPartialUpdate: boolean = false, isUpdate: boolean = false) {
263
263
  const commonOptions = { required: fieldMetadata.required && !isPartialUpdate, fieldName: fieldMetadata.name, isUpdate };
264
264
  switch (fieldMetadata.type) {
265
265
  case SolidFieldType.shortText: {
@@ -326,11 +326,13 @@ export class CRUDService<T> { // Add two generic value i.e Person,CreatePersonDt
326
326
  case SolidFieldType.relation: {
327
327
  // Identify if the field is for the inverse side or not
328
328
  if (fieldMetadata.relationType === RelationType.manyToOne) {
329
+ const relationCoModelUserKeyFieldName = await this.getUserKeyFieldNameForModel(fieldMetadata.relationCoModelSingularName);
329
330
  const manyToOneOptions: ManyToOneRelationFieldOptions = {
330
331
  ...commonOptions,
331
332
  relationCoModelSingularName: fieldMetadata.relationCoModelSingularName,
332
- modelUserKeyFieldName: fieldMetadata.model.userKeyField?.name,
333
+ // modelUserKeyFieldName: fieldMetadata.model.userKeyField?.name,
333
334
  modelSingularName: fieldMetadata.model.singularName,
335
+ relationCoModelUserKeyFieldName: relationCoModelUserKeyFieldName,
334
336
  entityManager,
335
337
  }
336
338
  return new ManyToOneRelationFieldCrudManager(manyToOneOptions);
@@ -677,7 +679,7 @@ export class CRUDService<T> { // Add two generic value i.e Person,CreatePersonDt
677
679
 
678
680
  // Process each field
679
681
  for (const field of model.fields) {
680
- const fieldManager: FieldCrudManager = this.fieldCrudManager(field, this.entityManager);
682
+ const fieldManager: FieldCrudManager = await this.fieldCrudManager(field, this.entityManager);
681
683
  const validationErrors = await fieldManager.validate(createDto, files);
682
684
  if (validationErrors.length > 0) {
683
685
  throw new BadRequestException(`Validation errors in ${field.name} are invalid: ${validationErrors.map(e => e.error).join(', ')}`);
@@ -871,5 +873,13 @@ export class CRUDService<T> { // Add two generic value i.e Person,CreatePersonDt
871
873
 
872
874
  return this.getFieldMetadataRecursively(remainingParts, relationCoModel.fields);
873
875
  }
876
+
877
+ async getUserKeyFieldNameForModel(modelSingularName: string): Promise<string> {
878
+ const model = await this.modelMetadataService.findOneBySingularName(modelSingularName, ['userKeyField']);
879
+ if (!model) {
880
+ throw new BadRequestException(`Model ${modelSingularName} not found`);
881
+ }
882
+ return model.userKeyField?.name || '';
883
+ }
874
884
  }
875
885
 
@@ -1,9 +1,7 @@
1
1
  import { Injectable, Logger } from '@nestjs/common';
2
2
  import { InjectDataSource } from "@nestjs/typeorm";
3
- import * as fs from 'fs/promises'; // Use the Promise-based version of fs for async/await
4
3
  import { Dashboard } from 'src/entities/dashboard.entity';
5
4
  import { ModuleMetadataHelperService } from "src/helpers/module-metadata-helper.service";
6
- import { DashboardMapper } from 'src/mappers/dashboard-mapper';
7
5
  import { DashboardService } from 'src/services/dashboard.service';
8
6
  import { DataSource, EntityManager, EntitySubscriberInterface, InsertEvent, UpdateEvent } from "typeorm";
9
7
 
@@ -49,7 +47,7 @@ export class DashboardSubscriber implements EntitySubscriberInterface<Dashboard>
49
47
  // Load the dashboard with module relation populated
50
48
  const populatedDashboard = await entityManager.findOne(Dashboard, {
51
49
  where: { id: dashboard.id },
52
- relations: ['module'],
50
+ relations: ['module','dashboardVariables', 'questions', 'questions.questionSqlDatasetConfigs'],
53
51
  });
54
52
 
55
53
  if (!populatedDashboard) {