Update DeedTypeService

This commit is contained in:
Sosthene 2025-09-11 14:09:16 +02:00
parent 229a5a9585
commit 02f6a10b9d

View File

@ -21,6 +21,7 @@ export default class DeedTypeService extends AbstractService {
isDeleted: 'false',
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
document_types: [],
...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
const items: any[] = this.getItems('_deed_types_');
if (items.length > 0) {
setTimeout(() => callback([...items]), 0);
const items: Record<string, any> = this.getItems('_deed_types_');
if (Object.keys(items).length > 0) {
setTimeout(() => callback(items), 0);
}
this.messageBus.getProcessesDecoded((values: any) => {
return values['utype'] === 'deedType'
this.messageBus.getProcessesDecoded((_processId: string, values: any) => {
return values['utype']
&& values['utype'] === 'deedType'
&& values['isDeleted']
&& values['isDeleted'] === 'false';
}).then(async (processes: any) => {
if (processes.length === 0) {
callback([...items]);
}).then(async (processes: Record<string, any>) => {
if (Object.keys(processes).length === 0) {
callback(items);
return;
}
const updatedItems: any[] = [...items];
console.log('[DeedTypeService/getDeedTypes] processes', processes);
for (let processIndex = 0; processIndex < processes.length; processIndex++) {
const process = processes[processIndex];
const updatedItems: Record<string, any> = { ...items };
for (const [processId, process] of Object.entries(processes)) {
// 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);
if (existingIndex >= 0) {
updatedItems[existingIndex] = process;
} else {
updatedItems.push(process);
}
updatedItems[processId] = process;
}
callback([...updatedItems]);
callback(updatedItems);
});
}
@ -115,7 +113,7 @@ export default class DeedTypeService extends AbstractService {
const processData = await this.messageBus.getProcessData(processId);
// Update cache
this.setItem('_deed_types_', processData);
this.setItem('_deed_types_', processId, processData);
} catch (error) {
console.error('Failed to update deed type:', error);
throw error; // Re-throw to allow caller to handle