ajanin #16
@ -176,18 +176,18 @@ export default class DeedTypeService extends AbstractService {
|
||||
}
|
||||
|
||||
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) => {
|
||||
const newStateId: string = processUpdated.diffs[0]?.state_id;
|
||||
this.messageBus.notifyUpdate(process.processId, newStateId).then(() => {
|
||||
this.messageBus.validateState(process.processId, newStateId).then((_stateValidated) => {
|
||||
const deedTypeUid: string = process.processData.uid;
|
||||
this.removeItem('_deed_types_', deedTypeUid);
|
||||
|
||||
this.getDeedTypeByUid(deedTypeUid).then(resolve).catch(reject);
|
||||
}).catch(reject);
|
||||
}).catch(reject);
|
||||
}).catch(reject);
|
||||
this.messageBus.validateState(process.processId, newStateId).then(() => {
|
||||
resolve();
|
||||
}).catch(() => console.error('Failed to validate state'));
|
||||
}).catch(() => console.error('Failed to notify update'));
|
||||
}).catch(() => console.error('Failed to update'));
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -4,8 +4,6 @@ import User from 'src/sdk/User';
|
||||
|
||||
import AbstractService from './AbstractService';
|
||||
|
||||
import RuleService from './RuleService';
|
||||
|
||||
export default class RoleService extends AbstractService {
|
||||
|
||||
private constructor() {
|
||||
@ -95,9 +93,7 @@ export default class RoleService extends AbstractService {
|
||||
if (processes.length === 0) {
|
||||
return items;
|
||||
} else {
|
||||
for (let process of processes) {
|
||||
process = await this.completeRole(process);
|
||||
|
||||
for (const process of processes) {
|
||||
// Update cache
|
||||
this.setItem('_roles_', process);
|
||||
|
||||
@ -127,8 +123,7 @@ export default class RoleService extends AbstractService {
|
||||
if (processes.length === 0) {
|
||||
resolve(null);
|
||||
} else {
|
||||
let process: any = processes[0];
|
||||
process = await this.completeRole(process);
|
||||
const process: any = processes[0];
|
||||
|
||||
// Update cache
|
||||
this.setItem('_roles_', process);
|
||||
@ -154,20 +149,4 @@ export default class RoleService extends AbstractService {
|
||||
}).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 {
|
||||
LoaderService.getInstance().show();
|
||||
DeedTypeService.getDeedTypeByUid(deedTypeUid as string).then((process: any) => {
|
||||
DeedTypeService.getDeedTypeByUid(deedTypeUid as string).then(async (process: any) => {
|
||||
if (process) {
|
||||
DeedTypeService.updateDeedType(process, { name: values["name"], description: values["description"] }).then(() => {
|
||||
router.push(
|
||||
Module.getInstance()
|
||||
.get()
|
||||
.modules.pages.DeedTypes.pages.DeedTypesInformations.props.path.replace("[uid]", deedTypeUid as string),
|
||||
);
|
||||
LoaderService.getInstance().hide();
|
||||
});
|
||||
// New data
|
||||
const newData: any = {
|
||||
name: values["name"],
|
||||
description: values["description"]
|
||||
};
|
||||
|
||||
// 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) {
|
||||
|
@ -52,12 +52,25 @@ export default function DeedTypesInformations(props: IProps) {
|
||||
|
||||
const deleteDeedType = useCallback(async () => {
|
||||
LoaderService.getInstance().show();
|
||||
DeedTypeService.getDeedTypeByUid(deedTypeUid as string).then((process: any) => {
|
||||
DeedTypeService.getDeedTypeByUid(deedTypeUid as string).then(async (process: any) => {
|
||||
if (process) {
|
||||
DeedTypeService.updateDeedType(process, { isDeleted: 'true', archived_at: new Date().toISOString() }).then(() => {
|
||||
router.push(Module.getInstance().get().modules.pages.DeedTypes.props.path);
|
||||
LoaderService.getInstance().hide();
|
||||
});
|
||||
// New data
|
||||
const newData: any = {
|
||||
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]);
|
||||
@ -107,7 +120,7 @@ export default function DeedTypesInformations(props: IProps) {
|
||||
|
||||
const saveDocumentTypes = useCallback(() => {
|
||||
LoaderService.getInstance().show();
|
||||
DeedTypeService.getDeedTypeByUid(deedTypeUid as string).then((process: any) => {
|
||||
DeedTypeService.getDeedTypeByUid(deedTypeUid as string).then(async (process: any) => {
|
||||
if (process) {
|
||||
const deedType: any = process.processData;
|
||||
|
||||
@ -118,10 +131,17 @@ export default function DeedTypesInformations(props: IProps) {
|
||||
selectedDocuments.map((selectedDocument: any) => ({ uid: selectedDocument.id as string }))
|
||||
.forEach((selectedDocument: any) => document_types.push(selectedDocument));
|
||||
|
||||
DeedTypeService.updateDeedType(process, { document_types: document_types }).then(() => {
|
||||
LoaderService.getInstance().hide();
|
||||
closeSaveModal();
|
||||
});
|
||||
// New data
|
||||
const newData: any = {
|
||||
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]);
|
||||
|
@ -97,14 +97,21 @@ export default function ParameterDocuments(props: IProps) {
|
||||
const oldDocumentsType = props.folder.deed?.document_types!;
|
||||
|
||||
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) {
|
||||
DeedTypeService.updateDeedType(process, {
|
||||
// New data
|
||||
const newData: any = {
|
||||
document_types: [
|
||||
...oldDocumentsType.map((document: any) => ({ uid: document.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!;
|
||||
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) {
|
||||
DeedTypeService.updateDeedType(process, {
|
||||
// New data
|
||||
const newData: any = {
|
||||
document_types: [
|
||||
...oldDocumentsType.map((document: any) => ({ uid: document.uid })),
|
||||
...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