Make createAndSend{Profile,Folder}Tx returns object

This commit is contained in:
Sosthene 2025-06-11 21:42:30 +02:00 committed by NicolasCantu
parent 00bc3d8ad2
commit 39f2b086b5

View File

@ -1852,7 +1852,7 @@ export default class Services {
this.stateId = null;
}
public async createAndSendProfileTx(userData: any): Promise<void> {
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<void> {
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<void> {