Update DeedTypeService
This commit is contained in:
parent
229a5a9585
commit
02f6a10b9d
@ -21,6 +21,7 @@ export default class DeedTypeService extends AbstractService {
|
|||||||
isDeleted: 'false',
|
isDeleted: 'false',
|
||||||
created_at: new Date().toISOString(),
|
created_at: new Date().toISOString(),
|
||||||
updated_at: new Date().toISOString(),
|
updated_at: new Date().toISOString(),
|
||||||
|
document_types: [],
|
||||||
...deedTypeData
|
...deedTypeData
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -63,39 +64,36 @@ export default class DeedTypeService extends AbstractService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static getDeedTypes(callback: (processes: any[]) => void): void {
|
public static getDeedTypes(callback: (processes: Record<string, any>) => void): void {
|
||||||
// Check if we have valid cache
|
// Check if we have valid cache
|
||||||
const items: any[] = this.getItems('_deed_types_');
|
const items: Record<string, any> = this.getItems('_deed_types_');
|
||||||
if (items.length > 0) {
|
if (Object.keys(items).length > 0) {
|
||||||
setTimeout(() => callback([...items]), 0);
|
setTimeout(() => callback(items), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.messageBus.getProcessesDecoded((values: any) => {
|
this.messageBus.getProcessesDecoded((_processId: string, values: any) => {
|
||||||
return values['utype'] === 'deedType'
|
return values['utype']
|
||||||
|
&& values['utype'] === 'deedType'
|
||||||
|
&& values['isDeleted']
|
||||||
&& values['isDeleted'] === 'false';
|
&& values['isDeleted'] === 'false';
|
||||||
}).then(async (processes: any) => {
|
}).then(async (processes: Record<string, any>) => {
|
||||||
if (processes.length === 0) {
|
if (Object.keys(processes).length === 0) {
|
||||||
callback([...items]);
|
callback(items);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const updatedItems: any[] = [...items];
|
console.log('[DeedTypeService/getDeedTypes] processes', processes);
|
||||||
|
|
||||||
for (let processIndex = 0; processIndex < processes.length; processIndex++) {
|
const updatedItems: Record<string, any> = { ...items };
|
||||||
const process = processes[processIndex];
|
|
||||||
|
|
||||||
|
for (const [processId, process] of Object.entries(processes)) {
|
||||||
// Update cache
|
// Update cache
|
||||||
this.setItem('_deed_types_', process);
|
this.setItem('_deed_types_', processId, process);
|
||||||
|
|
||||||
const existingIndex: number = updatedItems.findIndex(item => item.processData?.uid === process.processData?.uid);
|
updatedItems[processId] = process;
|
||||||
if (existingIndex >= 0) {
|
|
||||||
updatedItems[existingIndex] = process;
|
|
||||||
} else {
|
|
||||||
updatedItems.push(process);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
callback([...updatedItems]);
|
callback(updatedItems);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,7 +113,7 @@ export default class DeedTypeService extends AbstractService {
|
|||||||
const processData = await this.messageBus.getProcessData(processId);
|
const processData = await this.messageBus.getProcessData(processId);
|
||||||
|
|
||||||
// Update cache
|
// Update cache
|
||||||
this.setItem('_deed_types_', processData);
|
this.setItem('_deed_types_', processId, processData);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to update deed type:', error);
|
console.error('Failed to update deed type:', error);
|
||||||
throw error; // Re-throw to allow caller to handle
|
throw error; // Re-throw to allow caller to handle
|
||||||
|
Loading…
x
Reference in New Issue
Block a user