From 39f2b086b510140f0ac25bf3be6dc9cd333221f0 Mon Sep 17 00:00:00 2001 From: Sosthene Date: Wed, 11 Jun 2025 21:42:30 +0200 Subject: [PATCH] Make createAndSend{Profile,Folder}Tx returns object --- src/services/service.ts | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/src/services/service.ts b/src/services/service.ts index ab24bd4..9d1c5fb 100755 --- a/src/services/service.ts +++ b/src/services/service.ts @@ -1852,7 +1852,7 @@ export default class Services { this.stateId = null; } - public async createAndSendProfileTx(userData: any): Promise { + public async createAndSendProfileTx(userData: any): Promise<{ processId: string, process: Process }> { try { const createProfileProcessReturn = await this.createProfileProcess( userData, @@ -1862,7 +1862,7 @@ export default class Services { this.setProcessId(createProfileProcessReturn.updated_process!.process_id); this.setStateId(createProfileProcessReturn.updated_process!.current_process.states[0].state_id); } catch (e) { - throw new Error(`creatProfileProcess failed: ${e}`); + throw new Error(`createProfileProcess failed: ${e}`); } try { @@ -1875,16 +1875,24 @@ export default class Services { try { const approveChangeReturn = await this.approveChange(this.processId!, this.stateId!); await this.handleApiReturn(approveChangeReturn); - this.processId = null; - this.stateId = null; } catch (e) { throw new Error(`approveChange failed: ${e}`); } + // Get the new process from db + const processId = this.processId!; + this.setProcessId(null); + this.setStateId(null); + const profileProcess = await this.getProcess(processId); + if (profileProcess) { + return {processId, process: profileProcess}; + } else { + console.error('Failed to retrieve newly created profile process'); // This shouldn't happen + return { processId, process: { states: [] } }; + } } - - public async createAndSendFolderTx(folderData: any): Promise { + public async createAndSendFolderTx(folderData: any): Promise<{ processId: string, process: Process }> { try { await this.checkConnections([]); } catch (e) { @@ -1914,12 +1922,22 @@ export default class Services { try { const approveChangeReturn = await this.approveChange(this.processId!, this.stateId!); await this.handleApiReturn(approveChangeReturn); - this.processId = null; - this.stateId = null; } catch (e) { throw new Error(`approveChange failed: ${e}`); } + // Get the new process from db + const processId = this.processId!; + this.setProcessId(null); + this.setStateId(null); + console.log(`createAndSendFolderTx ~ processId: ${processId}`); + const folderProcess = await this.getProcess(processId); + if (folderProcess) { + return { processId, process: folderProcess }; + } else { + console.error('Failed to retrieve newly created folder process'); // This shouldn't happen + return { processId, process: { states: [] } }; + } } public async generateProcessPdf(processId: string, processState: ProcessState): Promise {