Skip to content

Commit bfdabca

Browse files
renemadsenclaude
andcommitted
fix: replace hardcoded FieldTypeId comparisons with DB lookups
EFormService.cs (template duplication): - CreateFields() had `if (field.FieldTypeId == 17)` to detect FieldGroup. The DB auto-increments FieldType.Id, so 17 is not guaranteed to be FieldGroup. Now queries FieldTypes table by Constants.FieldTypes.FieldGroup. This was the root cause of corrupted FieldTypeIds when duplicating eforms. EformCaseReportService.cs (case reports): - Two places had `x.Field.FieldTypeId == 5` to filter Picture fields. Now queries FieldTypes table by Constants.FieldTypes.Picture. There are additional hardcoded IDs in plugin repos (Workflow, ItemsPlanning, BackendConfiguration report service) that need the same fix separately. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 9d6c059 commit bfdabca

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

eFormAPI/eFormAPI.Web/Services/EFormService.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -934,10 +934,13 @@ private static async Task<CheckList> FindTemplates(int idEform, MicrotingDbConte
934934
private static async Task CreateFields(int eformId, MicrotingDbContext sdkDbContext,
935935
List<Microting.eForm.Infrastructure.Data.Entities.Field> fieldsList)
936936
{
937+
var fieldGroupTypeId = (await sdkDbContext.FieldTypes
938+
.FirstAsync(ft => ft.Type == Microting.eForm.Infrastructure.Constants.Constants.FieldTypes.FieldGroup)).Id;
939+
937940
foreach (var field in fieldsList)
938941
{
939942
field.CheckListId = eformId;
940-
if (field.FieldTypeId == 17) // field group
943+
if (field.FieldTypeId == fieldGroupTypeId)
941944
{
942945
foreach (var fieldChild in field.Children)
943946
{

eFormAPI/eFormAPI.Web/Services/EformCaseReportService.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,12 @@ public async Task<OperationDataResult<EFormCasesReportModel>> GetReportEformCase
152152
}
153153
}
154154

155+
var pictureFieldTypeId = (await sdkDbContext.FieldTypes
156+
.FirstAsync(ft => ft.Type == Constants.FieldTypes.Picture)).Id;
157+
155158
var imagesForEform = await sdkDbContext.FieldValues
156159
.Where(x => x.WorkflowState != Constants.WorkflowStates.Removed)
157-
.Where(x => x.Field.FieldTypeId == 5)
160+
.Where(x => x.Field.FieldTypeId == pictureFieldTypeId)
158161
.Where(x => casesIds.Contains((int) x.CaseId))
159162
.OrderBy(x => x.CaseId)
160163
.ToListAsync();
@@ -290,7 +293,7 @@ await sdkDbContext.FieldOptionTranslations.SingleAsync(x =>
290293

291294
reportEformCaseModel.ImagesCount = await sdkDbContext.FieldValues
292295
.Where(x => x.WorkflowState != Constants.WorkflowStates.Removed)
293-
.Where(x => x.Field.FieldTypeId == 5)
296+
.Where(x => x.Field.FieldTypeId == pictureFieldTypeId)
294297
.Where(x => x.CaseId == caseDto.Id)
295298
.Select(x => x.Id)
296299
.CountAsync();

0 commit comments

Comments
 (0)