@flusys/nestjs-form-builder 5.1.2 → 5.2.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.
@@ -10,7 +10,6 @@ Object.defineProperty(exports, "FormBuilderDataSourceProvider", {
10
10
  });
11
11
  const _modules = require("@flusys/nestjs-shared/modules");
12
12
  const _common = require("@nestjs/common");
13
- const _constants = require("@flusys/nestjs-shared/constants");
14
13
  const _core = require("@nestjs/core");
15
14
  const _express = require("express");
16
15
  const _formbuilderconfigservice = require("./form-builder-config.service");
@@ -101,50 +100,6 @@ let FormBuilderDataSourceProvider = class FormBuilderDataSourceProvider extends
101
100
  const entities = await this.getFormBuilderEntities(enableCompanyFeature);
102
101
  return super.createDataSourceFromConfig(config, entities);
103
102
  }
104
- async getSingleDataSource() {
105
- if (FormBuilderDataSourceProvider.singleDataSource?.isInitialized) {
106
- return FormBuilderDataSourceProvider.singleDataSource;
107
- }
108
- if (FormBuilderDataSourceProvider.singleConnectionLock) {
109
- return FormBuilderDataSourceProvider.singleConnectionLock;
110
- }
111
- const config = this.getDefaultDatabaseConfig();
112
- if (!config) {
113
- throw new _common.InternalServerErrorException({
114
- message: 'No database config available. Provide defaultDatabaseConfig in FormBuilderModule options.',
115
- messageKey: _constants.SYSTEM_MESSAGES.DATABASE_CONFIG_NOT_AVAILABLE
116
- });
117
- }
118
- const connectionPromise = this.createDataSourceFromConfig(config);
119
- FormBuilderDataSourceProvider.singleConnectionLock = connectionPromise;
120
- try {
121
- const dataSource = await connectionPromise;
122
- FormBuilderDataSourceProvider.singleDataSource = dataSource;
123
- return dataSource;
124
- } finally{
125
- FormBuilderDataSourceProvider.singleConnectionLock = null;
126
- }
127
- }
128
- async getOrCreateTenantConnection(tenant) {
129
- const existing = FormBuilderDataSourceProvider.tenantConnections.get(tenant.id);
130
- if (existing?.isInitialized) {
131
- return existing;
132
- }
133
- const pendingConnection = FormBuilderDataSourceProvider.connectionLocks.get(tenant.id);
134
- if (pendingConnection) {
135
- return pendingConnection;
136
- }
137
- const config = this.buildTenantDatabaseConfig(tenant);
138
- const connectionPromise = this.createDataSourceFromConfig(config);
139
- FormBuilderDataSourceProvider.connectionLocks.set(tenant.id, connectionPromise);
140
- try {
141
- const dataSource = await connectionPromise;
142
- FormBuilderDataSourceProvider.tenantConnections.set(tenant.id, dataSource);
143
- return dataSource;
144
- } finally{
145
- FormBuilderDataSourceProvider.connectionLocks.delete(tenant.id);
146
- }
147
- }
148
103
  constructor(configService, request){
149
104
  super(FormBuilderDataSourceProvider.buildParentOptions(configService.getOptions()), request), _define_property(this, "configService", void 0), this.configService = configService;
150
105
  }
@@ -49,13 +49,7 @@ function _ts_param(paramIndex, decorator) {
49
49
  decorator(target, key, paramIndex);
50
50
  };
51
51
  }
52
- let FormResultService = class FormResultService extends _classes.RequestScopedApiService {
53
- resolveEntity() {
54
- return _entities.FormResult;
55
- }
56
- getDataSourceProvider() {
57
- return this.dataSourceProvider;
58
- }
52
+ let FormResultService = class FormResultService extends _classes.ApiService {
59
53
  async ensureFormRepositoryInitialized() {
60
54
  if (!this.formRepository) {
61
55
  const enableCompanyFeature = this.formBuilderConfig.isCompanyFeatureEnabled();
@@ -191,7 +185,7 @@ let FormResultService = class FormResultService extends _classes.RequestScopedAp
191
185
  }
192
186
  // Form Submission
193
187
  async submitForm(dto, user, isPublic = false) {
194
- await this.ensureRepositoryInitialized();
188
+ await this.ensureDataSourceRepository();
195
189
  const form = await this.getActiveForm(dto.formId);
196
190
  await this.validateSubmissionAccess(form, user, isPublic);
197
191
  const isDraft = dto.isDraft ?? false;
@@ -226,7 +220,7 @@ let FormResultService = class FormResultService extends _classes.RequestScopedAp
226
220
  return this.convertEntityToResponseDto(saved, false);
227
221
  }
228
222
  async getMyDraft(formId, user) {
229
- await this.ensureRepositoryInitialized();
223
+ await this.ensureDataSourceRepository();
230
224
  const draft = await this.repository.findOne({
231
225
  where: this.buildUserDraftWhere(formId, user.id),
232
226
  order: {
@@ -236,7 +230,7 @@ let FormResultService = class FormResultService extends _classes.RequestScopedAp
236
230
  return draft ? this.convertEntityToResponseDto(draft, false) : null;
237
231
  }
238
232
  async updateDraft(draftId, dto, user) {
239
- await this.ensureRepositoryInitialized();
233
+ await this.ensureDataSourceRepository();
240
234
  const draft = await this.repository.findOne({
241
235
  where: {
242
236
  id: draftId,
@@ -263,7 +257,7 @@ let FormResultService = class FormResultService extends _classes.RequestScopedAp
263
257
  return this.convertEntityToResponseDto(saved, false);
264
258
  }
265
259
  async getByFormId(formId, user, pagination) {
266
- await this.ensureRepositoryInitialized();
260
+ await this.ensureDataSourceRepository();
267
261
  const query = this.repository.createQueryBuilder(this.entityName).where('form_result.formId = :formId', {
268
262
  formId
269
263
  }).andWhere('form_result.deletedAt IS NULL');
@@ -278,7 +272,7 @@ let FormResultService = class FormResultService extends _classes.RequestScopedAp
278
272
  };
279
273
  }
280
274
  async hasUserSubmitted(formId, user) {
281
- await this.ensureRepositoryInitialized();
275
+ await this.ensureDataSourceRepository();
282
276
  const count = await this.repository.count({
283
277
  where: {
284
278
  formId,
@@ -290,7 +284,7 @@ let FormResultService = class FormResultService extends _classes.RequestScopedAp
290
284
  return count > 0;
291
285
  }
292
286
  constructor(cacheManager, utilsService, formBuilderConfig, dataSourceProvider){
293
- super('form_result', null, cacheManager, utilsService, FormResultService.name, true, 'form-builder'), _define_property(this, "cacheManager", void 0), _define_property(this, "utilsService", void 0), _define_property(this, "formBuilderConfig", void 0), _define_property(this, "dataSourceProvider", void 0), _define_property(this, "formRepository", void 0), this.cacheManager = cacheManager, this.utilsService = utilsService, this.formBuilderConfig = formBuilderConfig, this.dataSourceProvider = dataSourceProvider, this.formRepository = null;
287
+ super('form_result', cacheManager, utilsService, FormResultService.name, true, 'form-builder', _entities.FormResult, dataSourceProvider), _define_property(this, "cacheManager", void 0), _define_property(this, "utilsService", void 0), _define_property(this, "formBuilderConfig", void 0), _define_property(this, "dataSourceProvider", void 0), _define_property(this, "formRepository", void 0), this.cacheManager = cacheManager, this.utilsService = utilsService, this.formBuilderConfig = formBuilderConfig, this.dataSourceProvider = dataSourceProvider, this.formRepository = null;
294
288
  }
295
289
  };
296
290
  _ts_decorate([
@@ -46,13 +46,9 @@ function _ts_param(paramIndex, decorator) {
46
46
  decorator(target, key, paramIndex);
47
47
  };
48
48
  }
49
- let FormService = class FormService extends _classes.RequestScopedApiService {
49
+ let FormService = class FormService extends _classes.ApiService {
50
50
  resolveEntity() {
51
- const enableCompanyFeature = this.formBuilderConfig.isCompanyFeatureEnabled();
52
- return enableCompanyFeature ? _entities.FormWithCompany : _entities.Form;
53
- }
54
- getDataSourceProvider() {
55
- return this.dataSourceProvider;
51
+ return this.formBuilderConfig.isCompanyFeatureEnabled() ? _entities.FormWithCompany : _entities.Form;
56
52
  }
57
53
  // Entity Conversion
58
54
  async convertSingleDtoToEntity(dto, user) {
@@ -170,7 +166,7 @@ let FormService = class FormService extends _classes.RequestScopedApiService {
170
166
  };
171
167
  }
172
168
  async findPublicActiveForm(where) {
173
- await this.ensureRepositoryInitialized();
169
+ await this.ensureDataSourceRepository();
174
170
  return await this.repository.findOne({
175
171
  where: {
176
172
  ...where,
@@ -194,7 +190,7 @@ let FormService = class FormService extends _classes.RequestScopedApiService {
194
190
  return this.toPublicForm(form);
195
191
  }
196
192
  async getFormForSubmission(formId, user) {
197
- await this.ensureRepositoryInitialized();
193
+ await this.ensureDataSourceRepository();
198
194
  const form = await this.repository.findOne({
199
195
  where: {
200
196
  id: formId,
@@ -228,7 +224,7 @@ let FormService = class FormService extends _classes.RequestScopedApiService {
228
224
  });
229
225
  }
230
226
  async getBySlug(slug) {
231
- await this.ensureRepositoryInitialized();
227
+ await this.ensureDataSourceRepository();
232
228
  const form = await this.repository.findOne({
233
229
  where: {
234
230
  slug,
@@ -247,7 +243,7 @@ let FormService = class FormService extends _classes.RequestScopedApiService {
247
243
  return form ? this.toPublicForm(form) : null;
248
244
  }
249
245
  async getFormAccessInfo(formId) {
250
- await this.ensureRepositoryInitialized();
246
+ await this.ensureDataSourceRepository();
251
247
  const form = await this.repository.findOne({
252
248
  where: {
253
249
  id: formId,
@@ -292,7 +288,7 @@ let FormService = class FormService extends _classes.RequestScopedApiService {
292
288
  return this.toPublicForm(form);
293
289
  }
294
290
  constructor(cacheManager, utilsService, formBuilderConfig, dataSourceProvider){
295
- super('form', null, cacheManager, utilsService, FormService.name, true, 'form-builder'), _define_property(this, "cacheManager", void 0), _define_property(this, "utilsService", void 0), _define_property(this, "formBuilderConfig", void 0), _define_property(this, "dataSourceProvider", void 0), this.cacheManager = cacheManager, this.utilsService = utilsService, this.formBuilderConfig = formBuilderConfig, this.dataSourceProvider = dataSourceProvider;
291
+ super('form', cacheManager, utilsService, FormService.name, true, 'form-builder', undefined, dataSourceProvider), _define_property(this, "cacheManager", void 0), _define_property(this, "utilsService", void 0), _define_property(this, "formBuilderConfig", void 0), this.cacheManager = cacheManager, this.utilsService = utilsService, this.formBuilderConfig = formBuilderConfig;
296
292
  }
297
293
  };
298
294
  FormService = _ts_decorate([
@@ -3,19 +3,19 @@ import { ILoggedUserInfo } from '@flusys/nestjs-shared/interfaces';
3
3
  import { CreateFormResultDto, FormResultResponseDto, GetMyDraftDto, GetResultsByFormDto, SubmitFormDto, UpdateDraftDto, UpdateFormResultDto } from '../dtos';
4
4
  import { FormResultService } from '../services/form-result.service';
5
5
  declare const FormResultController_base: abstract new (service: FormResultService) => {
6
- readonly enabledEndpoints: import("@flusys/nestjs-shared/classes").ApiEndpoint[] | "all";
6
+ readonly enabledEndpoints: import("@flusys/nestjs-shared").ApiEndpoint[] | "all";
7
7
  service: FormResultService;
8
- isEnabled(endpoint: import("@flusys/nestjs-shared/classes").ApiEndpoint): boolean;
8
+ isEnabled(endpoint: import("@flusys/nestjs-shared").ApiEndpoint): boolean;
9
9
  insert(addDto: CreateFormResultDto, user: ILoggedUserInfo | null): Promise<SingleResponseDto<FormResultResponseDto>>;
10
- insertMany(addDto: CreateFormResultDto[], user: ILoggedUserInfo | null): Promise<import("@flusys/nestjs-shared/dtos").BulkResponseDto<FormResultResponseDto>>;
11
- getById(id: string, body: import("@flusys/nestjs-shared/dtos").GetByIdBodyDto, user: ILoggedUserInfo | null): Promise<SingleResponseDto<FormResultResponseDto>>;
12
- getByIds(body: import("@flusys/nestjs-shared/dtos").GetByIdsDto, user: ILoggedUserInfo | null): Promise<ListResponseDto<FormResultResponseDto>>;
10
+ insertMany(addDto: CreateFormResultDto[], user: ILoggedUserInfo | null): Promise<import("@flusys/nestjs-shared").BulkResponseDto<FormResultResponseDto>>;
11
+ getById(id: string, body: import("@flusys/nestjs-shared").GetByIdBodyDto, user: ILoggedUserInfo | null): Promise<SingleResponseDto<FormResultResponseDto>>;
12
+ getByIds(body: import("@flusys/nestjs-shared").GetByIdsDto, user: ILoggedUserInfo | null): Promise<ListResponseDto<FormResultResponseDto>>;
13
13
  update(updateDto: UpdateFormResultDto, user: ILoggedUserInfo | null): Promise<SingleResponseDto<FormResultResponseDto>>;
14
- updateMany(updateDtos: UpdateFormResultDto[], user: ILoggedUserInfo | null): Promise<import("@flusys/nestjs-shared/dtos").BulkResponseDto<FormResultResponseDto>>;
15
- bulkUpsert(dtos: (CreateFormResultDto | UpdateFormResultDto)[], user: ILoggedUserInfo | null): Promise<import("@flusys/nestjs-shared/dtos").BulkResponseDto<FormResultResponseDto>>;
14
+ updateMany(updateDtos: UpdateFormResultDto[], user: ILoggedUserInfo | null): Promise<import("@flusys/nestjs-shared").BulkResponseDto<FormResultResponseDto>>;
15
+ bulkUpsert(dtos: (CreateFormResultDto | UpdateFormResultDto)[], user: ILoggedUserInfo | null): Promise<import("@flusys/nestjs-shared").BulkResponseDto<FormResultResponseDto>>;
16
16
  getByFilter(filter: Record<string, any>, user: ILoggedUserInfo | null): Promise<SingleResponseDto<FormResultResponseDto>>;
17
- getAll(filterAndPaginationDto: import("@flusys/nestjs-shared/dtos").FilterAndPaginationDto, user: ILoggedUserInfo | null, search?: string): Promise<ListResponseDto<FormResultResponseDto>>;
18
- delete(deleteDto: import("@flusys/nestjs-shared/dtos").DeleteDto, user: ILoggedUserInfo | null): Promise<import("@flusys/nestjs-shared/dtos").MessageResponseDto>;
17
+ getAll(filterAndPaginationDto: import("@flusys/nestjs-shared").FilterAndPaginationDto, user: ILoggedUserInfo | null, search?: string): Promise<ListResponseDto<FormResultResponseDto>>;
18
+ delete(deleteDto: import("@flusys/nestjs-shared").DeleteDto, user: ILoggedUserInfo | null): Promise<import("@flusys/nestjs-shared").MessageResponseDto>;
19
19
  };
20
20
  export declare class FormResultController extends FormResultController_base {
21
21
  formResultService: FormResultService;
@@ -3,19 +3,19 @@ import { ILoggedUserInfo } from '@flusys/nestjs-shared/interfaces';
3
3
  import { CreateFormDto, FormAccessInfoResponseDto, FormResponseDto, PublicFormResponseDto, UpdateFormDto } from '../dtos';
4
4
  import { FormService } from '../services/form.service';
5
5
  declare const FormController_base: abstract new (service: FormService) => {
6
- readonly enabledEndpoints: import("@flusys/nestjs-shared/classes").ApiEndpoint[] | "all";
6
+ readonly enabledEndpoints: import("@flusys/nestjs-shared").ApiEndpoint[] | "all";
7
7
  service: FormService;
8
- isEnabled(endpoint: import("@flusys/nestjs-shared/classes").ApiEndpoint): boolean;
8
+ isEnabled(endpoint: import("@flusys/nestjs-shared").ApiEndpoint): boolean;
9
9
  insert(addDto: CreateFormDto, user: ILoggedUserInfo | null): Promise<SingleResponseDto<FormResponseDto>>;
10
- insertMany(addDto: CreateFormDto[], user: ILoggedUserInfo | null): Promise<import("@flusys/nestjs-shared/dtos").BulkResponseDto<FormResponseDto>>;
11
- getById(id: string, body: import("@flusys/nestjs-shared/dtos").GetByIdBodyDto, user: ILoggedUserInfo | null): Promise<SingleResponseDto<FormResponseDto>>;
12
- getByIds(body: import("@flusys/nestjs-shared/dtos").GetByIdsDto, user: ILoggedUserInfo | null): Promise<import("@flusys/nestjs-shared/dtos").ListResponseDto<FormResponseDto>>;
10
+ insertMany(addDto: CreateFormDto[], user: ILoggedUserInfo | null): Promise<import("@flusys/nestjs-shared").BulkResponseDto<FormResponseDto>>;
11
+ getById(id: string, body: import("@flusys/nestjs-shared").GetByIdBodyDto, user: ILoggedUserInfo | null): Promise<SingleResponseDto<FormResponseDto>>;
12
+ getByIds(body: import("@flusys/nestjs-shared").GetByIdsDto, user: ILoggedUserInfo | null): Promise<import("@flusys/nestjs-shared").ListResponseDto<FormResponseDto>>;
13
13
  update(updateDto: UpdateFormDto, user: ILoggedUserInfo | null): Promise<SingleResponseDto<FormResponseDto>>;
14
- updateMany(updateDtos: UpdateFormDto[], user: ILoggedUserInfo | null): Promise<import("@flusys/nestjs-shared/dtos").BulkResponseDto<FormResponseDto>>;
15
- bulkUpsert(dtos: (CreateFormDto | UpdateFormDto)[], user: ILoggedUserInfo | null): Promise<import("@flusys/nestjs-shared/dtos").BulkResponseDto<FormResponseDto>>;
14
+ updateMany(updateDtos: UpdateFormDto[], user: ILoggedUserInfo | null): Promise<import("@flusys/nestjs-shared").BulkResponseDto<FormResponseDto>>;
15
+ bulkUpsert(dtos: (CreateFormDto | UpdateFormDto)[], user: ILoggedUserInfo | null): Promise<import("@flusys/nestjs-shared").BulkResponseDto<FormResponseDto>>;
16
16
  getByFilter(filter: Record<string, any>, user: ILoggedUserInfo | null): Promise<SingleResponseDto<FormResponseDto>>;
17
- getAll(filterAndPaginationDto: import("@flusys/nestjs-shared/dtos").FilterAndPaginationDto, user: ILoggedUserInfo | null, search?: string): Promise<import("@flusys/nestjs-shared/dtos").ListResponseDto<FormResponseDto>>;
18
- delete(deleteDto: import("@flusys/nestjs-shared/dtos").DeleteDto, user: ILoggedUserInfo | null): Promise<import("@flusys/nestjs-shared/dtos").MessageResponseDto>;
17
+ getAll(filterAndPaginationDto: import("@flusys/nestjs-shared").FilterAndPaginationDto, user: ILoggedUserInfo | null, search?: string): Promise<import("@flusys/nestjs-shared").ListResponseDto<FormResponseDto>>;
18
+ delete(deleteDto: import("@flusys/nestjs-shared").DeleteDto, user: ILoggedUserInfo | null): Promise<import("@flusys/nestjs-shared").MessageResponseDto>;
19
19
  };
20
20
  export declare class FormController extends FormController_base {
21
21
  formService: FormService;
@@ -26,8 +26,7 @@ function _ts_param(paramIndex, decorator) {
26
26
  };
27
27
  }
28
28
  import { MultiTenantDataSourceService } from '@flusys/nestjs-shared/modules';
29
- import { Inject, Injectable, InternalServerErrorException, Optional, Scope } from '@nestjs/common';
30
- import { SYSTEM_MESSAGES } from '@flusys/nestjs-shared/constants';
29
+ import { Inject, Injectable, Optional, Scope } from '@nestjs/common';
31
30
  import { REQUEST } from '@nestjs/core';
32
31
  import { Request } from 'express';
33
32
  import { FormBuilderConfigService } from './form-builder-config.service';
@@ -50,50 +49,6 @@ export class FormBuilderDataSourceProvider extends MultiTenantDataSourceService
50
49
  const entities = await this.getFormBuilderEntities(enableCompanyFeature);
51
50
  return super.createDataSourceFromConfig(config, entities);
52
51
  }
53
- async getSingleDataSource() {
54
- if (FormBuilderDataSourceProvider.singleDataSource?.isInitialized) {
55
- return FormBuilderDataSourceProvider.singleDataSource;
56
- }
57
- if (FormBuilderDataSourceProvider.singleConnectionLock) {
58
- return FormBuilderDataSourceProvider.singleConnectionLock;
59
- }
60
- const config = this.getDefaultDatabaseConfig();
61
- if (!config) {
62
- throw new InternalServerErrorException({
63
- message: 'No database config available. Provide defaultDatabaseConfig in FormBuilderModule options.',
64
- messageKey: SYSTEM_MESSAGES.DATABASE_CONFIG_NOT_AVAILABLE
65
- });
66
- }
67
- const connectionPromise = this.createDataSourceFromConfig(config);
68
- FormBuilderDataSourceProvider.singleConnectionLock = connectionPromise;
69
- try {
70
- const dataSource = await connectionPromise;
71
- FormBuilderDataSourceProvider.singleDataSource = dataSource;
72
- return dataSource;
73
- } finally{
74
- FormBuilderDataSourceProvider.singleConnectionLock = null;
75
- }
76
- }
77
- async getOrCreateTenantConnection(tenant) {
78
- const existing = FormBuilderDataSourceProvider.tenantConnections.get(tenant.id);
79
- if (existing?.isInitialized) {
80
- return existing;
81
- }
82
- const pendingConnection = FormBuilderDataSourceProvider.connectionLocks.get(tenant.id);
83
- if (pendingConnection) {
84
- return pendingConnection;
85
- }
86
- const config = this.buildTenantDatabaseConfig(tenant);
87
- const connectionPromise = this.createDataSourceFromConfig(config);
88
- FormBuilderDataSourceProvider.connectionLocks.set(tenant.id, connectionPromise);
89
- try {
90
- const dataSource = await connectionPromise;
91
- FormBuilderDataSourceProvider.tenantConnections.set(tenant.id, dataSource);
92
- return dataSource;
93
- } finally{
94
- FormBuilderDataSourceProvider.connectionLocks.delete(tenant.id);
95
- }
96
- }
97
52
  constructor(configService, request){
98
53
  super(FormBuilderDataSourceProvider.buildParentOptions(configService.getOptions()), request), _define_property(this, "configService", void 0), this.configService = configService;
99
54
  }
@@ -25,7 +25,7 @@ function _ts_param(paramIndex, decorator) {
25
25
  decorator(target, key, paramIndex);
26
26
  };
27
27
  }
28
- import { HybridCache, RequestScopedApiService } from '@flusys/nestjs-shared/classes';
28
+ import { HybridCache, ApiService } from '@flusys/nestjs-shared/classes';
29
29
  import { LogAction } from '@flusys/nestjs-shared/decorators';
30
30
  import { ILoggedUserInfo } from '@flusys/nestjs-shared/interfaces';
31
31
  import { UtilsService } from '@flusys/nestjs-shared/modules';
@@ -39,13 +39,7 @@ import { calculateComputedFields } from '../utils/computed-field.utils';
39
39
  import { validateUserPermissions } from '../utils/permission.utils';
40
40
  import { FormBuilderConfigService } from './form-builder-config.service';
41
41
  import { FormBuilderDataSourceProvider } from './form-builder-datasource.provider';
42
- export class FormResultService extends RequestScopedApiService {
43
- resolveEntity() {
44
- return FormResult;
45
- }
46
- getDataSourceProvider() {
47
- return this.dataSourceProvider;
48
- }
42
+ export class FormResultService extends ApiService {
49
43
  async ensureFormRepositoryInitialized() {
50
44
  if (!this.formRepository) {
51
45
  const enableCompanyFeature = this.formBuilderConfig.isCompanyFeatureEnabled();
@@ -181,7 +175,7 @@ export class FormResultService extends RequestScopedApiService {
181
175
  }
182
176
  // Form Submission
183
177
  async submitForm(dto, user, isPublic = false) {
184
- await this.ensureRepositoryInitialized();
178
+ await this.ensureDataSourceRepository();
185
179
  const form = await this.getActiveForm(dto.formId);
186
180
  await this.validateSubmissionAccess(form, user, isPublic);
187
181
  const isDraft = dto.isDraft ?? false;
@@ -216,7 +210,7 @@ export class FormResultService extends RequestScopedApiService {
216
210
  return this.convertEntityToResponseDto(saved, false);
217
211
  }
218
212
  async getMyDraft(formId, user) {
219
- await this.ensureRepositoryInitialized();
213
+ await this.ensureDataSourceRepository();
220
214
  const draft = await this.repository.findOne({
221
215
  where: this.buildUserDraftWhere(formId, user.id),
222
216
  order: {
@@ -226,7 +220,7 @@ export class FormResultService extends RequestScopedApiService {
226
220
  return draft ? this.convertEntityToResponseDto(draft, false) : null;
227
221
  }
228
222
  async updateDraft(draftId, dto, user) {
229
- await this.ensureRepositoryInitialized();
223
+ await this.ensureDataSourceRepository();
230
224
  const draft = await this.repository.findOne({
231
225
  where: {
232
226
  id: draftId,
@@ -253,7 +247,7 @@ export class FormResultService extends RequestScopedApiService {
253
247
  return this.convertEntityToResponseDto(saved, false);
254
248
  }
255
249
  async getByFormId(formId, user, pagination) {
256
- await this.ensureRepositoryInitialized();
250
+ await this.ensureDataSourceRepository();
257
251
  const query = this.repository.createQueryBuilder(this.entityName).where('form_result.formId = :formId', {
258
252
  formId
259
253
  }).andWhere('form_result.deletedAt IS NULL');
@@ -268,7 +262,7 @@ export class FormResultService extends RequestScopedApiService {
268
262
  };
269
263
  }
270
264
  async hasUserSubmitted(formId, user) {
271
- await this.ensureRepositoryInitialized();
265
+ await this.ensureDataSourceRepository();
272
266
  const count = await this.repository.count({
273
267
  where: {
274
268
  formId,
@@ -280,7 +274,7 @@ export class FormResultService extends RequestScopedApiService {
280
274
  return count > 0;
281
275
  }
282
276
  constructor(cacheManager, utilsService, formBuilderConfig, dataSourceProvider){
283
- super('form_result', null, cacheManager, utilsService, FormResultService.name, true, 'form-builder'), _define_property(this, "cacheManager", void 0), _define_property(this, "utilsService", void 0), _define_property(this, "formBuilderConfig", void 0), _define_property(this, "dataSourceProvider", void 0), _define_property(this, "formRepository", void 0), this.cacheManager = cacheManager, this.utilsService = utilsService, this.formBuilderConfig = formBuilderConfig, this.dataSourceProvider = dataSourceProvider, this.formRepository = null;
277
+ super('form_result', cacheManager, utilsService, FormResultService.name, true, 'form-builder', FormResult, dataSourceProvider), _define_property(this, "cacheManager", void 0), _define_property(this, "utilsService", void 0), _define_property(this, "formBuilderConfig", void 0), _define_property(this, "dataSourceProvider", void 0), _define_property(this, "formRepository", void 0), this.cacheManager = cacheManager, this.utilsService = utilsService, this.formBuilderConfig = formBuilderConfig, this.dataSourceProvider = dataSourceProvider, this.formRepository = null;
284
278
  }
285
279
  }
286
280
  _ts_decorate([
@@ -25,7 +25,7 @@ function _ts_param(paramIndex, decorator) {
25
25
  decorator(target, key, paramIndex);
26
26
  };
27
27
  }
28
- import { HybridCache, RequestScopedApiService } from '@flusys/nestjs-shared/classes';
28
+ import { HybridCache, ApiService } from '@flusys/nestjs-shared/classes';
29
29
  import { UtilsService } from '@flusys/nestjs-shared/modules';
30
30
  import { applyCompanyFilter } from '@flusys/nestjs-shared/utils';
31
31
  import { BadRequestException, ForbiddenException, Inject, Injectable, NotFoundException, Scope, UnauthorizedException } from '@nestjs/common';
@@ -36,13 +36,9 @@ import { FormAccessType } from '../enums/form-access-type.enum';
36
36
  import { validateUserPermissions } from '../utils/permission.utils';
37
37
  import { FormBuilderConfigService } from './form-builder-config.service';
38
38
  import { FormBuilderDataSourceProvider } from './form-builder-datasource.provider';
39
- export class FormService extends RequestScopedApiService {
39
+ export class FormService extends ApiService {
40
40
  resolveEntity() {
41
- const enableCompanyFeature = this.formBuilderConfig.isCompanyFeatureEnabled();
42
- return enableCompanyFeature ? FormWithCompany : Form;
43
- }
44
- getDataSourceProvider() {
45
- return this.dataSourceProvider;
41
+ return this.formBuilderConfig.isCompanyFeatureEnabled() ? FormWithCompany : Form;
46
42
  }
47
43
  // Entity Conversion
48
44
  async convertSingleDtoToEntity(dto, user) {
@@ -160,7 +156,7 @@ export class FormService extends RequestScopedApiService {
160
156
  };
161
157
  }
162
158
  async findPublicActiveForm(where) {
163
- await this.ensureRepositoryInitialized();
159
+ await this.ensureDataSourceRepository();
164
160
  return await this.repository.findOne({
165
161
  where: {
166
162
  ...where,
@@ -184,7 +180,7 @@ export class FormService extends RequestScopedApiService {
184
180
  return this.toPublicForm(form);
185
181
  }
186
182
  async getFormForSubmission(formId, user) {
187
- await this.ensureRepositoryInitialized();
183
+ await this.ensureDataSourceRepository();
188
184
  const form = await this.repository.findOne({
189
185
  where: {
190
186
  id: formId,
@@ -218,7 +214,7 @@ export class FormService extends RequestScopedApiService {
218
214
  });
219
215
  }
220
216
  async getBySlug(slug) {
221
- await this.ensureRepositoryInitialized();
217
+ await this.ensureDataSourceRepository();
222
218
  const form = await this.repository.findOne({
223
219
  where: {
224
220
  slug,
@@ -237,7 +233,7 @@ export class FormService extends RequestScopedApiService {
237
233
  return form ? this.toPublicForm(form) : null;
238
234
  }
239
235
  async getFormAccessInfo(formId) {
240
- await this.ensureRepositoryInitialized();
236
+ await this.ensureDataSourceRepository();
241
237
  const form = await this.repository.findOne({
242
238
  where: {
243
239
  id: formId,
@@ -282,7 +278,7 @@ export class FormService extends RequestScopedApiService {
282
278
  return this.toPublicForm(form);
283
279
  }
284
280
  constructor(cacheManager, utilsService, formBuilderConfig, dataSourceProvider){
285
- super('form', null, cacheManager, utilsService, FormService.name, true, 'form-builder'), _define_property(this, "cacheManager", void 0), _define_property(this, "utilsService", void 0), _define_property(this, "formBuilderConfig", void 0), _define_property(this, "dataSourceProvider", void 0), this.cacheManager = cacheManager, this.utilsService = utilsService, this.formBuilderConfig = formBuilderConfig, this.dataSourceProvider = dataSourceProvider;
281
+ super('form', cacheManager, utilsService, FormService.name, true, 'form-builder', undefined, dataSourceProvider), _define_property(this, "cacheManager", void 0), _define_property(this, "utilsService", void 0), _define_property(this, "formBuilderConfig", void 0), this.cacheManager = cacheManager, this.utilsService = utilsService, this.formBuilderConfig = formBuilderConfig;
286
282
  }
287
283
  }
288
284
  FormService = _ts_decorate([
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flusys/nestjs-form-builder",
3
- "version": "5.1.2",
3
+ "version": "5.2.0",
4
4
  "description": "Dynamic form builder module with schema versioning and access control",
5
5
  "main": "cjs/index.js",
6
6
  "module": "fesm/index.js",
@@ -72,19 +72,19 @@
72
72
  }
73
73
  },
74
74
  "peerDependencies": {
75
- "@nestjs/common": "^10.0.0 || ^11.0.0",
76
- "@nestjs/config": "^3.0.0 || ^4.0.0",
77
- "@nestjs/core": "^10.0.0 || ^11.0.0",
78
- "@nestjs/platform-express": "^10.0.0 || ^11.0.0",
79
- "@nestjs/swagger": "^7.0.0 || ^11.0.0",
80
- "@nestjs/typeorm": "^10.0.0 || ^11.0.0",
81
- "class-transformer": "^0.5.0",
82
- "class-validator": "^0.14.0",
75
+ "@nestjs/common": "^11.0.0",
76
+ "@nestjs/config": "^4.0.0",
77
+ "@nestjs/core": "^11.0.0",
78
+ "@nestjs/platform-express": "^11.0.0",
79
+ "@nestjs/swagger": "^11.0.0",
80
+ "@nestjs/typeorm": "^11.0.0",
81
+ "class-transformer": "^0.5.1",
82
+ "class-validator": "^0.14.0 || ^0.15.0",
83
83
  "typeorm": "^0.3.0",
84
- "express": "^4.18.0"
84
+ "express": "^4.18.0 || ^5.0.0"
85
85
  },
86
86
  "dependencies": {
87
- "@flusys/nestjs-core": "5.1.2",
88
- "@flusys/nestjs-shared": "5.1.2"
87
+ "@flusys/nestjs-core": "5.2.0",
88
+ "@flusys/nestjs-shared": "5.2.0"
89
89
  }
90
90
  }
@@ -8,5 +8,5 @@ export declare class FormBuilderConfigService implements IModuleConfigService {
8
8
  getDatabaseMode(): DatabaseMode;
9
9
  isMultiTenant(): boolean;
10
10
  getOptions(): FormBuilderModuleOptions;
11
- getConfig(): import("../interfaces/form-builder-module.interface").IFormBuilderConfig;
11
+ getConfig(): import("..").IFormBuilderConfig | undefined;
12
12
  }
@@ -15,6 +15,4 @@ export declare class FormBuilderDataSourceProvider extends MultiTenantDataSource
15
15
  private static buildParentOptions;
16
16
  getFormBuilderEntities(enableCompanyFeature?: boolean): Promise<any[]>;
17
17
  protected createDataSourceFromConfig(config: IDatabaseConfig): Promise<DataSource>;
18
- protected getSingleDataSource(): Promise<DataSource>;
19
- protected getOrCreateTenantConnection(tenant: ITenantDatabaseConfig): Promise<DataSource>;
20
18
  }
@@ -1,22 +1,20 @@
1
- import { HybridCache, RequestScopedApiService } from '@flusys/nestjs-shared/classes';
1
+ import { HybridCache, ApiService } from '@flusys/nestjs-shared/classes';
2
2
  import { FilterAndPaginationDto } from '@flusys/nestjs-shared/dtos';
3
3
  import { ILoggedUserInfo } from '@flusys/nestjs-shared/interfaces';
4
4
  import { UtilsService } from '@flusys/nestjs-shared/modules';
5
- import { EntityTarget, SelectQueryBuilder } from 'typeorm';
5
+ import { SelectQueryBuilder } from 'typeorm';
6
6
  import { CreateFormResultDto, SubmitFormDto, UpdateFormResultDto } from '../dtos/form-result.dto';
7
7
  import { FormResult } from '../entities';
8
8
  import { IFormResult } from '../interfaces/form-result.interface';
9
9
  import { FormBuilderConfigService } from './form-builder-config.service';
10
10
  import { FormBuilderDataSourceProvider } from './form-builder-datasource.provider';
11
- export declare class FormResultService extends RequestScopedApiService<CreateFormResultDto, UpdateFormResultDto, IFormResult, FormResult> {
11
+ export declare class FormResultService extends ApiService<CreateFormResultDto, UpdateFormResultDto, IFormResult, FormResult> {
12
12
  protected cacheManager: HybridCache;
13
13
  protected utilsService: UtilsService;
14
14
  private readonly formBuilderConfig;
15
15
  private readonly dataSourceProvider;
16
16
  private formRepository;
17
17
  constructor(cacheManager: HybridCache, utilsService: UtilsService, formBuilderConfig: FormBuilderConfigService, dataSourceProvider: FormBuilderDataSourceProvider);
18
- protected resolveEntity(): EntityTarget<FormResult>;
19
- protected getDataSourceProvider(): FormBuilderDataSourceProvider;
20
18
  private ensureFormRepositoryInitialized;
21
19
  private getActiveForm;
22
20
  private applyCompanyFilterToQuery;
@@ -1,4 +1,4 @@
1
- import { HybridCache, RequestScopedApiService } from '@flusys/nestjs-shared/classes';
1
+ import { HybridCache, ApiService } from '@flusys/nestjs-shared/classes';
2
2
  import { FilterAndPaginationDto } from '@flusys/nestjs-shared/dtos';
3
3
  import { ILoggedUserInfo } from '@flusys/nestjs-shared/interfaces';
4
4
  import { UtilsService } from '@flusys/nestjs-shared/modules';
@@ -9,14 +9,12 @@ import { FormAccessType } from '../enums/form-access-type.enum';
9
9
  import { IForm, IPublicForm } from '../interfaces/form.interface';
10
10
  import { FormBuilderConfigService } from './form-builder-config.service';
11
11
  import { FormBuilderDataSourceProvider } from './form-builder-datasource.provider';
12
- export declare class FormService extends RequestScopedApiService<CreateFormDto, UpdateFormDto, IForm, Form> {
12
+ export declare class FormService extends ApiService<CreateFormDto, UpdateFormDto, IForm, Form> {
13
13
  protected cacheManager: HybridCache;
14
14
  protected utilsService: UtilsService;
15
15
  private readonly formBuilderConfig;
16
- private readonly dataSourceProvider;
17
16
  constructor(cacheManager: HybridCache, utilsService: UtilsService, formBuilderConfig: FormBuilderConfigService, dataSourceProvider: FormBuilderDataSourceProvider);
18
17
  protected resolveEntity(): EntityTarget<Form>;
19
- protected getDataSourceProvider(): FormBuilderDataSourceProvider;
20
18
  convertSingleDtoToEntity(dto: CreateFormDto | UpdateFormDto, user: ILoggedUserInfo | null): Promise<Form>;
21
19
  getSelectQuery(query: SelectQueryBuilder<Form>, _user: ILoggedUserInfo | null, select?: string[]): Promise<{
22
20
  query: SelectQueryBuilder<Form>;