@@ -2,6 +2,7 @@ import { Request, Response } from "express";
22import { GroupService } from "../services/GroupService" ;
33import { CharterSignatureService } from "../services/CharterSignatureService" ;
44import { spinUpEVault } from "web3-adapter" ;
5+ import { adapter } from "../web3adapter" ;
56import dotenv from "dotenv" ;
67
78dotenv . config ( ) ;
@@ -27,6 +28,9 @@ export class GroupController {
2728 participants : [ ]
2829 } ) ;
2930
31+ // Lock the group so it doesn't sync until charter+ename are added
32+ adapter . addToLockedIds ( group . id ) ;
33+
3034 // Add participants including the creator
3135 const allParticipants = [ ...new Set ( [ userId , ...participants ] ) ] ;
3236 for ( const participantId of allParticipants ) {
@@ -142,13 +146,41 @@ export class GroupController {
142146 updateData . ename = evaultResult . w3id ;
143147 }
144148
149+ // Unlock the group so it CAN sync now that it has charter+ename
150+ if ( needsEVault ) {
151+ const lockIndex = adapter . lockedIds . indexOf ( id ) ;
152+ if ( lockIndex > - 1 ) {
153+ adapter . lockedIds . splice ( lockIndex , 1 ) ;
154+ }
155+ }
156+
145157 // Now save with both charter and ename (if provisioned)
146158 const updatedGroup = await this . groupService . updateGroup ( id , updateData ) ;
147159
148160 if ( ! updatedGroup ) {
149161 return res . status ( 404 ) . json ( { error : "Group not found" } ) ;
150162 }
151163
164+ // HACK: Manually trigger sync after delay to ensure complete data is sent
165+ if ( needsEVault ) {
166+ setTimeout ( async ( ) => {
167+ try {
168+ // Re-fetch the complete group entity with all relations
169+ const completeGroup = await this . groupService . getGroupById ( id ) ;
170+ if ( completeGroup && completeGroup . charter && completeGroup . ename ) {
171+ // Convert to plain object and trigger the adapter manually
172+ const plainGroup = JSON . parse ( JSON . stringify ( completeGroup ) ) ;
173+ await adapter . handleChange ( {
174+ data : plainGroup ,
175+ tableName : "groups"
176+ } ) ;
177+ }
178+ } catch ( error ) {
179+ console . error ( "Error in manual sync:" , error ) ;
180+ }
181+ } , 5000 ) ; // 5 second delay
182+ }
183+
152184 res . json ( updatedGroup ) ;
153185 } catch ( error ) {
154186 console . error ( "Error updating charter:" , error ) ;
0 commit comments