import { Injectable } from '@nestjs/common'; import { EntityServiceImpl } from './entity-service-impl.service'; import { BaseEntity } from '../entity/base-entity.entity'; import { UserData } from '../../user/entity/user.entity'; import { EntityManager } from 'typeorm'; import { ViewMaster } from '../entity/view-master.entity'; @Injectable() export class SectionMasterService extends EntityServiceImpl { constructor() { super(); } async createEntity( entityData: BaseEntity, loggedInUser: UserData, manager?: EntityManager, ): Promise { const entityMaster = await this.entityMasterService.getEntityData( entityData.entity_type, loggedInUser, ); entityData.parent_id = entityMaster.id; entityData.parent_type = entityMaster.entity_type; const savedEntity = await super.createEntity( entityData, loggedInUser, manager, ); return savedEntity; } async updateEntity( entityData: ViewMaster, loggedInUserData: UserData | null, ): Promise { return entityData; } parseLayout(layoutJson: any) { const stepsData: { stepType: string; stepId: string; stepLabel: string; stepPosition: number; fieldsGroup: { type: string; label: string; id: string; }[]; }[] = []; if (layoutJson?.form?.children && Array.isArray(layoutJson.form.children)) { const firstChild = layoutJson.form.children[0]; if (firstChild.type === 'wizard' && Array.isArray(firstChild.steps)) { console.log('Wizard Steps:', firstChild.steps); let i = 0; for (const step of firstChild.steps) { if (step.type === 'step') { const fields = this.extractFields(step.fields); stepsData.push({ stepType: step.type, stepId: step.id, stepLabel: step.label, stepPosition: ++i, fieldsGroup: fields, }); } } } } return stepsData; } extractFields(fieldsArray: any[]): { type: string; label: string; id: string; }[] { const extractedFields: { type: string; label: string; id: string }[] = []; function traverse(fields: any[]) { for (const field of fields) { if (field.type === 'field-set') { extractedFields.push({ type: field.type || 'Default Type', label: field.label || 'Default Label', id: field.id || 'Default ID', }); } if (Array.isArray(field.fields)) { traverse(field.fields); } } } traverse(fieldsArray); return extractedFields; } }