Improve save process
This commit is contained in:
parent
b0f699f6f0
commit
d672e79064
@ -176,18 +176,18 @@ export default class DeedTypeService extends AbstractService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static updateDeedType(process: any, newData: any): Promise<void> {
|
public static updateDeedType(process: any, newData: any): Promise<void> {
|
||||||
return new Promise<void>((resolve: () => void, reject: (error: string) => void) => {
|
// Update cache
|
||||||
|
this.setItem('_deed_types_', process);
|
||||||
|
|
||||||
|
return new Promise<void>((resolve: () => void) => {
|
||||||
this.messageBus.updateProcess(process.processId, { updated_at: new Date().toISOString(), ...newData }, [], null).then((processUpdated: any) => {
|
this.messageBus.updateProcess(process.processId, { updated_at: new Date().toISOString(), ...newData }, [], null).then((processUpdated: any) => {
|
||||||
const newStateId: string = processUpdated.diffs[0]?.state_id;
|
const newStateId: string = processUpdated.diffs[0]?.state_id;
|
||||||
this.messageBus.notifyUpdate(process.processId, newStateId).then(() => {
|
this.messageBus.notifyUpdate(process.processId, newStateId).then(() => {
|
||||||
this.messageBus.validateState(process.processId, newStateId).then((_stateValidated) => {
|
this.messageBus.validateState(process.processId, newStateId).then(() => {
|
||||||
const deedTypeUid: string = process.processData.uid;
|
resolve();
|
||||||
this.removeItem('_deed_types_', deedTypeUid);
|
}).catch(() => console.error('Failed to validate state'));
|
||||||
|
}).catch(() => console.error('Failed to notify update'));
|
||||||
this.getDeedTypeByUid(deedTypeUid).then(resolve).catch(reject);
|
}).catch(() => console.error('Failed to update'));
|
||||||
}).catch(reject);
|
|
||||||
}).catch(reject);
|
|
||||||
}).catch(reject);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,8 +4,6 @@ import User from 'src/sdk/User';
|
|||||||
|
|
||||||
import AbstractService from './AbstractService';
|
import AbstractService from './AbstractService';
|
||||||
|
|
||||||
import RuleService from './RuleService';
|
|
||||||
|
|
||||||
export default class RoleService extends AbstractService {
|
export default class RoleService extends AbstractService {
|
||||||
|
|
||||||
private constructor() {
|
private constructor() {
|
||||||
@ -95,9 +93,7 @@ export default class RoleService extends AbstractService {
|
|||||||
if (processes.length === 0) {
|
if (processes.length === 0) {
|
||||||
return items;
|
return items;
|
||||||
} else {
|
} else {
|
||||||
for (let process of processes) {
|
for (const process of processes) {
|
||||||
process = await this.completeRole(process);
|
|
||||||
|
|
||||||
// Update cache
|
// Update cache
|
||||||
this.setItem('_roles_', process);
|
this.setItem('_roles_', process);
|
||||||
|
|
||||||
@ -127,8 +123,7 @@ export default class RoleService extends AbstractService {
|
|||||||
if (processes.length === 0) {
|
if (processes.length === 0) {
|
||||||
resolve(null);
|
resolve(null);
|
||||||
} else {
|
} else {
|
||||||
let process: any = processes[0];
|
const process: any = processes[0];
|
||||||
process = await this.completeRole(process);
|
|
||||||
|
|
||||||
// Update cache
|
// Update cache
|
||||||
this.setItem('_roles_', process);
|
this.setItem('_roles_', process);
|
||||||
@ -154,20 +149,4 @@ export default class RoleService extends AbstractService {
|
|||||||
}).catch(reject);
|
}).catch(reject);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async completeRole(process: any): Promise<any> {
|
|
||||||
/*
|
|
||||||
if (process.processData.rules && process.processData.rules.length > 0) {
|
|
||||||
process.processData.rules = await new Promise<any[]>(async (resolve: (rules: any[]) => void) => {
|
|
||||||
const rules: any[] = [];
|
|
||||||
for (const rule of process.processData.rules) {
|
|
||||||
rules.push((await RuleService.getRuleByUid(rule.uid)).processData);
|
|
||||||
}
|
|
||||||
resolve(rules);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
return process;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -63,16 +63,25 @@ export default function DeedTypesEdit() {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
LoaderService.getInstance().show();
|
LoaderService.getInstance().show();
|
||||||
DeedTypeService.getDeedTypeByUid(deedTypeUid as string).then((process: any) => {
|
DeedTypeService.getDeedTypeByUid(deedTypeUid as string).then(async (process: any) => {
|
||||||
if (process) {
|
if (process) {
|
||||||
DeedTypeService.updateDeedType(process, { name: values["name"], description: values["description"] }).then(() => {
|
// New data
|
||||||
router.push(
|
const newData: any = {
|
||||||
Module.getInstance()
|
name: values["name"],
|
||||||
.get()
|
description: values["description"]
|
||||||
.modules.pages.DeedTypes.pages.DeedTypesInformations.props.path.replace("[uid]", deedTypeUid as string),
|
};
|
||||||
);
|
|
||||||
LoaderService.getInstance().hide();
|
// Merge process data with new data & update process
|
||||||
});
|
process.processData.name = newData.name;
|
||||||
|
process.processData.description = newData.description;
|
||||||
|
await DeedTypeService.updateDeedType(process, newData);
|
||||||
|
|
||||||
|
router.push(
|
||||||
|
Module.getInstance()
|
||||||
|
.get()
|
||||||
|
.modules.pages.DeedTypes.pages.DeedTypesInformations.props.path.replace("[uid]", deedTypeUid as string),
|
||||||
|
);
|
||||||
|
LoaderService.getInstance().hide();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (validationErrors) {
|
} catch (validationErrors) {
|
||||||
|
@ -52,12 +52,25 @@ export default function DeedTypesInformations(props: IProps) {
|
|||||||
|
|
||||||
const deleteDeedType = useCallback(async () => {
|
const deleteDeedType = useCallback(async () => {
|
||||||
LoaderService.getInstance().show();
|
LoaderService.getInstance().show();
|
||||||
DeedTypeService.getDeedTypeByUid(deedTypeUid as string).then((process: any) => {
|
DeedTypeService.getDeedTypeByUid(deedTypeUid as string).then(async (process: any) => {
|
||||||
if (process) {
|
if (process) {
|
||||||
DeedTypeService.updateDeedType(process, { isDeleted: 'true', archived_at: new Date().toISOString() }).then(() => {
|
// New data
|
||||||
router.push(Module.getInstance().get().modules.pages.DeedTypes.props.path);
|
const newData: any = {
|
||||||
LoaderService.getInstance().hide();
|
isDeleted: 'true',
|
||||||
});
|
archived_at: new Date().toISOString()
|
||||||
|
};
|
||||||
|
|
||||||
|
// Merge process data with new data & update process
|
||||||
|
process.processData.isDeleted = newData.isDeleted;
|
||||||
|
process.processData.archived_at = newData.archived_at;
|
||||||
|
await DeedTypeService.updateDeedType(process, newData);
|
||||||
|
|
||||||
|
router.push(
|
||||||
|
Module.getInstance()
|
||||||
|
.get()
|
||||||
|
.modules.pages.DeedTypes.props.path
|
||||||
|
);
|
||||||
|
LoaderService.getInstance().hide();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, [deedTypeUid, router]);
|
}, [deedTypeUid, router]);
|
||||||
@ -107,7 +120,7 @@ export default function DeedTypesInformations(props: IProps) {
|
|||||||
|
|
||||||
const saveDocumentTypes = useCallback(() => {
|
const saveDocumentTypes = useCallback(() => {
|
||||||
LoaderService.getInstance().show();
|
LoaderService.getInstance().show();
|
||||||
DeedTypeService.getDeedTypeByUid(deedTypeUid as string).then((process: any) => {
|
DeedTypeService.getDeedTypeByUid(deedTypeUid as string).then(async (process: any) => {
|
||||||
if (process) {
|
if (process) {
|
||||||
const deedType: any = process.processData;
|
const deedType: any = process.processData;
|
||||||
|
|
||||||
@ -118,10 +131,17 @@ export default function DeedTypesInformations(props: IProps) {
|
|||||||
selectedDocuments.map((selectedDocument: any) => ({ uid: selectedDocument.id as string }))
|
selectedDocuments.map((selectedDocument: any) => ({ uid: selectedDocument.id as string }))
|
||||||
.forEach((selectedDocument: any) => document_types.push(selectedDocument));
|
.forEach((selectedDocument: any) => document_types.push(selectedDocument));
|
||||||
|
|
||||||
DeedTypeService.updateDeedType(process, { document_types: document_types }).then(() => {
|
// New data
|
||||||
LoaderService.getInstance().hide();
|
const newData: any = {
|
||||||
closeSaveModal();
|
document_types: document_types
|
||||||
});
|
};
|
||||||
|
|
||||||
|
// Merge process data with new data & update process
|
||||||
|
process.processData.document_types = newData.document_types;
|
||||||
|
await DeedTypeService.updateDeedType(process, newData);
|
||||||
|
|
||||||
|
LoaderService.getInstance().hide();
|
||||||
|
closeSaveModal();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, [closeSaveModal, deedTypeUid, selectedDocuments]);
|
}, [closeSaveModal, deedTypeUid, selectedDocuments]);
|
||||||
|
@ -97,14 +97,21 @@ export default function ParameterDocuments(props: IProps) {
|
|||||||
const oldDocumentsType = props.folder.deed?.document_types!;
|
const oldDocumentsType = props.folder.deed?.document_types!;
|
||||||
|
|
||||||
await new Promise<void>((resolve: () => void) => {
|
await new Promise<void>((resolve: () => void) => {
|
||||||
DeedTypeService.getDeedTypeByUid(props.folder.deed?.deed_type?.uid!).then((process: any) => {
|
DeedTypeService.getDeedTypeByUid(props.folder.deed?.deed_type?.uid!).then(async (process: any) => {
|
||||||
if (process) {
|
if (process) {
|
||||||
DeedTypeService.updateDeedType(process, {
|
// New data
|
||||||
|
const newData: any = {
|
||||||
document_types: [
|
document_types: [
|
||||||
...oldDocumentsType.map((document: any) => ({ uid: document.uid })),
|
...oldDocumentsType.map((document: any) => ({ uid: document.uid })),
|
||||||
{ uid: documentType.uid }
|
{ uid: documentType.uid }
|
||||||
]
|
]
|
||||||
}).then(() => resolve());
|
};
|
||||||
|
|
||||||
|
// Merge process data with new data & update process
|
||||||
|
process.processData.document_types = newData.document_types;
|
||||||
|
await DeedTypeService.updateDeedType(process, newData);
|
||||||
|
|
||||||
|
resolve();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -131,14 +138,21 @@ export default function ParameterDocuments(props: IProps) {
|
|||||||
|
|
||||||
const oldDocumentsType = props.folder.deed?.document_types!;
|
const oldDocumentsType = props.folder.deed?.document_types!;
|
||||||
await new Promise<void>((resolve: () => void) => {
|
await new Promise<void>((resolve: () => void) => {
|
||||||
DeedTypeService.getDeedTypeByUid(props.folder.deed?.deed_type?.uid!).then((process: any) => {
|
DeedTypeService.getDeedTypeByUid(props.folder.deed?.deed_type?.uid!).then(async (process: any) => {
|
||||||
if (process) {
|
if (process) {
|
||||||
DeedTypeService.updateDeedType(process, {
|
// New data
|
||||||
|
const newData: any = {
|
||||||
document_types: [
|
document_types: [
|
||||||
...oldDocumentsType.map((document: any) => ({ uid: document.uid })),
|
...oldDocumentsType.map((document: any) => ({ uid: document.uid })),
|
||||||
...selectedDocuments.map((document: any) => ({ uid: document.id as string }))
|
...selectedDocuments.map((document: any) => ({ uid: document.id as string }))
|
||||||
]
|
]
|
||||||
}).then(() => resolve());
|
};
|
||||||
|
|
||||||
|
// Merge process data with new data & update process
|
||||||
|
process.processData.document_types = newData.document_types;
|
||||||
|
await DeedTypeService.updateDeedType(process, newData);
|
||||||
|
|
||||||
|
resolve();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user