Fix DeedType and DocumentType
This commit is contained in:
parent
6ec7d8318e
commit
2213168f8e
@ -99,21 +99,23 @@ export default class DeedTypeService extends AbstractService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async updateDeedType(process: any, newData: any): Promise<void> {
|
public static async updateDeedType(processId: string, newData: any): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const processUpdated = await this.messageBus.updateProcess(
|
const processUpdated = await this.messageBus.updateProcess(
|
||||||
process.processId,
|
processId,
|
||||||
{ updated_at: new Date().toISOString(), ...newData },
|
{ updated_at: new Date().toISOString(), ...newData },
|
||||||
[],
|
[],
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
|
|
||||||
const newStateId: string = processUpdated.diffs[0]?.state_id;
|
const newStateId: string = processUpdated.diffs[0]?.state_id;
|
||||||
await this.messageBus.notifyUpdate(process.processId, newStateId);
|
await this.messageBus.notifyUpdate(processId, newStateId);
|
||||||
await this.messageBus.validateState(process.processId, newStateId);
|
await this.messageBus.validateState(processId, newStateId);
|
||||||
|
|
||||||
|
const processData = await this.messageBus.getProcessData(processId);
|
||||||
|
|
||||||
// Update cache
|
// Update cache
|
||||||
this.setItem('_deed_types_', process);
|
this.setItem('_deed_types_', 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
|
||||||
|
@ -3,6 +3,7 @@ import { v4 as uuidv4 } from 'uuid';
|
|||||||
import User from 'src/sdk/User';
|
import User from 'src/sdk/User';
|
||||||
|
|
||||||
import AbstractService from './AbstractService';
|
import AbstractService from './AbstractService';
|
||||||
|
import { DEFAULT_STORAGE_URLS } from '@Front/Config/AppConstants';
|
||||||
|
|
||||||
export default class DocumentTypeService extends AbstractService {
|
export default class DocumentTypeService extends AbstractService {
|
||||||
|
|
||||||
@ -10,7 +11,7 @@ export default class DocumentTypeService extends AbstractService {
|
|||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static createDocumentType(documentTypeData: any, validatorId: string): Promise<any> {
|
public static createDocumentType(documentTypeData: any, validatorId: string): Promise<{ processId: string, processData: any }> {
|
||||||
const ownerId: string = User.getInstance().getPairingId()!;
|
const ownerId: string = User.getInstance().getPairingId()!;
|
||||||
|
|
||||||
const processData: any = {
|
const processData: any = {
|
||||||
@ -23,45 +24,27 @@ export default class DocumentTypeService extends AbstractService {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const privateFields: string[] = Object.keys(processData);
|
const privateFields: string[] = Object.keys(processData);
|
||||||
privateFields.splice(privateFields.indexOf('uid'), 1);
|
const allFields: string[] = [...privateFields, 'roles'];
|
||||||
privateFields.splice(privateFields.indexOf('utype'), 1);
|
|
||||||
privateFields.splice(privateFields.indexOf('isDeleted'), 1);
|
|
||||||
|
|
||||||
const roles: any = {
|
const roles: any = {
|
||||||
demiurge: {
|
demiurge: {
|
||||||
members: [...[ownerId], validatorId],
|
members: [ownerId],
|
||||||
validation_rules: [],
|
validation_rules: [],
|
||||||
storages: []
|
storages: []
|
||||||
},
|
},
|
||||||
owner: {
|
owner: {
|
||||||
members: [ownerId],
|
members: [ownerId, validatorId],
|
||||||
validation_rules: [
|
validation_rules: [
|
||||||
{
|
{
|
||||||
quorum: 0.5,
|
quorum: 0.01,
|
||||||
fields: [...privateFields, 'roles', 'uid', 'utype'],
|
fields: allFields,
|
||||||
min_sig_member: 1,
|
min_sig_member: 0.01,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
storages: []
|
storages: [...DEFAULT_STORAGE_URLS]
|
||||||
},
|
|
||||||
validator: {
|
|
||||||
members: [validatorId],
|
|
||||||
validation_rules: [
|
|
||||||
{
|
|
||||||
quorum: 0.5,
|
|
||||||
fields: ['idCertified', 'roles'],
|
|
||||||
min_sig_member: 1,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
quorum: 0.0,
|
|
||||||
fields: [...privateFields],
|
|
||||||
min_sig_member: 0,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
storages: []
|
|
||||||
},
|
},
|
||||||
apophis: {
|
apophis: {
|
||||||
members: [ownerId],
|
members: [ownerId, validatorId],
|
||||||
validation_rules: [],
|
validation_rules: [],
|
||||||
storages: []
|
storages: []
|
||||||
}
|
}
|
||||||
@ -71,39 +54,80 @@ export default class DocumentTypeService extends AbstractService {
|
|||||||
this.messageBus.createProcess(processData, privateFields, roles).then((processCreated: any) => {
|
this.messageBus.createProcess(processData, privateFields, roles).then((processCreated: any) => {
|
||||||
this.messageBus.notifyUpdate(processCreated.processId, processCreated.process.states[0].state_id).then(() => {
|
this.messageBus.notifyUpdate(processCreated.processId, processCreated.process.states[0].state_id).then(() => {
|
||||||
this.messageBus.validateState(processCreated.processId, processCreated.process.states[0].state_id).then((_stateValidated: any) => {
|
this.messageBus.validateState(processCreated.processId, processCreated.process.states[0].state_id).then((_stateValidated: any) => {
|
||||||
this.getDocumentTypeByUid(processCreated.processData.uid).then(resolve).catch(reject);
|
this.messageBus.getProcessData(processCreated.processId).then((processData: any) => {
|
||||||
|
resolve({ processId: processCreated.processId, processData: processData });
|
||||||
|
}).catch(reject);
|
||||||
}).catch(reject);
|
}).catch(reject);
|
||||||
}).catch(reject);
|
}).catch(reject);
|
||||||
}).catch(reject);
|
}).catch(reject);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static getDocumentTypes(): Promise<any[]> {
|
public static getDocumentTypes(callback: (processes: any[]) => void): void {
|
||||||
// Check if we have valid cache
|
// Check if we have valid cache
|
||||||
const items: any[] = this.getItems('_document_types_');
|
const items: any[] = this.getItems('_document_types_');
|
||||||
|
if (items.length > 0) {
|
||||||
return this.messageBus.getProcessesDecoded((publicValues: any) =>
|
setTimeout(() => callback([...items]), 0);
|
||||||
publicValues['uid'] &&
|
}
|
||||||
publicValues['utype'] &&
|
|
||||||
publicValues['utype'] === 'documentType' &&
|
this.messageBus.getProcessesDecoded((values: any) => {
|
||||||
publicValues['isDeleted'] &&
|
return values['utype'] === 'documentType'
|
||||||
publicValues['isDeleted'] === 'false' &&
|
&& values['isDeleted'] === 'false';
|
||||||
!items.map((item: any) => item.processData.uid).includes(publicValues['uid'])
|
}).then(async (processes: any) => {
|
||||||
).then(async (processes: any[]) => {
|
|
||||||
if (processes.length === 0) {
|
if (processes.length === 0) {
|
||||||
return items;
|
callback([...items]);
|
||||||
} else {
|
return;
|
||||||
for (const process of processes) {
|
|
||||||
// Update cache
|
|
||||||
this.setItem('_document_types_', process);
|
|
||||||
|
|
||||||
items.push(process);
|
|
||||||
}
|
|
||||||
return items;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const updatedItems: any[] = [...items];
|
||||||
|
|
||||||
|
for (let processIndex = 0; processIndex < processes.length; processIndex++) {
|
||||||
|
const process = processes[processIndex];
|
||||||
|
|
||||||
|
// Update cache
|
||||||
|
this.setItem('_document_types_', process);
|
||||||
|
|
||||||
|
const existingIndex: number = updatedItems.findIndex(item => item.processId === process.processId);
|
||||||
|
if (existingIndex >= 0) {
|
||||||
|
updatedItems[existingIndex] = process;
|
||||||
|
} else {
|
||||||
|
updatedItems.push(process);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
callback([...updatedItems]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static getDocumentTypeByProcessId(processId: string): Promise<any> {
|
||||||
|
// Check if we have valid cache
|
||||||
|
const item: any = this.getItem('_document_types_', processId);
|
||||||
|
if (item) {
|
||||||
|
return Promise.resolve(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Promise<any>((resolve: (process: any) => void, reject: (error: string) => void) => {
|
||||||
|
this.messageBus.getProcessesDecoded((publicValues: any) => {
|
||||||
|
return publicValues['utype'] === 'documentType' && publicValues['isDeleted'] === 'false';
|
||||||
|
}).then((processes: any[]) => {
|
||||||
|
// Find the process with matching processId
|
||||||
|
const process = processes.find((p: any) => p.processId === processId);
|
||||||
|
|
||||||
|
if (!process) {
|
||||||
|
resolve(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update cache
|
||||||
|
this.setItem('_document_types_', process);
|
||||||
|
|
||||||
|
resolve(process);
|
||||||
|
}).catch(reject);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Keep the old method for backward compatibility but mark as deprecated
|
||||||
|
/** @deprecated Use getDocumentTypeByProcessId instead */
|
||||||
public static getDocumentTypeByUid(uid: string): Promise<any> {
|
public static getDocumentTypeByUid(uid: string): Promise<any> {
|
||||||
// Check if we have valid cache
|
// Check if we have valid cache
|
||||||
const item: any = this.getItem('_document_types_', uid);
|
const item: any = this.getItem('_document_types_', uid);
|
||||||
@ -133,10 +157,9 @@ export default class DocumentTypeService extends AbstractService {
|
|||||||
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((_stateValidated) => {
|
||||||
const documentTypeUid: string = process.processData.uid;
|
this.removeItem('_document_types_', process.processId);
|
||||||
this.removeItem('_document_types_', documentTypeUid);
|
|
||||||
|
|
||||||
this.getDocumentTypeByUid(documentTypeUid).then(resolve).catch(reject);
|
this.getDocumentTypeByProcessId(process.processId).then(resolve).catch(reject);
|
||||||
}).catch(reject);
|
}).catch(reject);
|
||||||
}).catch(reject);
|
}).catch(reject);
|
||||||
}).catch(reject);
|
}).catch(reject);
|
||||||
|
@ -28,6 +28,8 @@ export default function DefaultDeedTypeDashboard(props: IProps) {
|
|||||||
deedTypes.sort((a: any, b: any) => a.name.localeCompare(b.name));
|
deedTypes.sort((a: any, b: any) => a.name.localeCompare(b.name));
|
||||||
|
|
||||||
setDeedTypes(deedTypes);
|
setDeedTypes(deedTypes);
|
||||||
|
} else {
|
||||||
|
console.log('[DefaultDeedTypeDashboard] No deed types found');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
@ -51,7 +53,7 @@ export default function DefaultDeedTypeDashboard(props: IProps) {
|
|||||||
}
|
}
|
||||||
bottomButton={{
|
bottomButton={{
|
||||||
link: Module.getInstance().get().modules.pages.DeedTypes.pages.Create.props.path,
|
link: Module.getInstance().get().modules.pages.DeedTypes.pages.Create.props.path,
|
||||||
text: "Créer une liste de pièces",
|
text: "Créer une liste de pièces", // TODO I think this is misleading, should be "Créer un type d'acte"
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
@ -24,44 +24,74 @@ export default function DocumentTypesCreate(props: IProps) {
|
|||||||
const [validationError, setValidationError] = useState<ValidationError[]>([]);
|
const [validationError, setValidationError] = useState<ValidationError[]>([]);
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
|
const handleCancel = useCallback(() => {
|
||||||
|
router.push(Module.getInstance().get().modules.pages.DocumentTypes.props.path);
|
||||||
|
}, [router]);
|
||||||
|
|
||||||
const onSubmitHandler = useCallback(
|
const onSubmitHandler = useCallback(
|
||||||
async (e: React.FormEvent<HTMLFormElement> | null, values: { [key: string]: string }) => {
|
async (e: React.FormEvent<HTMLFormElement> | null, values: { [key: string]: string }) => {
|
||||||
try {
|
try {
|
||||||
const user: any = UserStore.instance.getUser();
|
const user: any = UserStore.instance.getUser();
|
||||||
const officeId: string = user.office.uid;
|
if (!user) {
|
||||||
|
console.error("DocumentTypesCreate: User not found - user is null or undefined");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const office = UserStore.instance.getOffice();
|
||||||
|
if (!office) {
|
||||||
|
console.error("DocumentTypesCreate: office not found - office is undefined or null");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const officeId = office.processId;
|
||||||
|
const officeIdNot = office.processData.idNot;
|
||||||
|
|
||||||
const documentFormModel = DocumentType.hydrate<DocumentType>({
|
// const documentFormModel = DocumentType.hydrate<DocumentType>({
|
||||||
...values,
|
// ...values,
|
||||||
office: Office.hydrate<Office>({
|
// office: Office.hydrate<Office>({
|
||||||
uid: officeId,
|
// uid: officeId,
|
||||||
})
|
// })
|
||||||
});
|
// });
|
||||||
await validateOrReject(documentFormModel, { groups: ["createDocumentType"] });
|
// await validateOrReject(documentFormModel, { groups: ["createDocumentType"] });
|
||||||
|
|
||||||
const documentTypeData: any = {
|
const documentTypeData: any = {
|
||||||
...values,
|
...values,
|
||||||
office: {
|
office: {
|
||||||
uid: officeId,
|
uid: officeId,
|
||||||
|
idNot: officeIdNot,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
LoaderService.getInstance().show();
|
LoaderService.getInstance().show();
|
||||||
DocumentTypeService.createDocumentType(documentTypeData, DEFAULT_VALIDATOR_ID).then((processCreated: any) => {
|
try {
|
||||||
|
const processCreated = await DocumentTypeService.createDocumentType(documentTypeData, DEFAULT_VALIDATOR_ID);
|
||||||
ToasterService.getInstance().success({
|
ToasterService.getInstance().success({
|
||||||
title: "Succès !",
|
title: "Succès !",
|
||||||
description: "Type de document créé avec succès"
|
description: "Type de document créé avec succès"
|
||||||
});
|
});
|
||||||
|
const documentTypeUid = processCreated.processId.split(':')[0];
|
||||||
|
if (!documentTypeUid) {
|
||||||
|
console.error("DocumentTypesCreate: documentTypeUid is undefined - processCreated.processId is missing");
|
||||||
|
return;
|
||||||
|
}
|
||||||
router.push(
|
router.push(
|
||||||
Module.getInstance()
|
Module.getInstance()
|
||||||
.get()
|
.get()
|
||||||
.modules.pages.DocumentTypes.pages.DocumentTypesInformations.props.path.replace("[uid]", processCreated.processData.uid),
|
.modules.pages.DocumentTypes.pages.DocumentTypesInformations.props.path.replace("[uid]", documentTypeUid),
|
||||||
);
|
);
|
||||||
|
} catch (apiError) {
|
||||||
|
ToasterService.getInstance().error({
|
||||||
|
title: "Erreur !",
|
||||||
|
description: "Une erreur est survenue lors de la création du type de document"
|
||||||
|
});
|
||||||
|
console.error("Document type creation error:", apiError);
|
||||||
|
} finally {
|
||||||
LoaderService.getInstance().hide();
|
LoaderService.getInstance().hide();
|
||||||
});
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof Array) {
|
if (e instanceof Array) {
|
||||||
setValidationError(e);
|
setValidationError(e);
|
||||||
}
|
}
|
||||||
|
LoaderService.getInstance().hide();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[router],
|
[router],
|
||||||
@ -90,7 +120,7 @@ export default function DocumentTypesCreate(props: IProps) {
|
|||||||
validationError={validationError.find((error) => error.property === "public_description")}
|
validationError={validationError.find((error) => error.property === "public_description")}
|
||||||
/>
|
/>
|
||||||
<div className={classes["buttons-container"]}>
|
<div className={classes["buttons-container"]}>
|
||||||
<Button variant={EButtonVariant.PRIMARY} styletype={EButtonstyletype.OUTLINED}>
|
<Button variant={EButtonVariant.PRIMARY} styletype={EButtonstyletype.OUTLINED} onClick={handleCancel}>
|
||||||
Annuler
|
Annuler
|
||||||
</Button>
|
</Button>
|
||||||
<Button type="submit">Créer le document</Button>
|
<Button type="submit">Créer le document</Button>
|
||||||
|
@ -26,9 +26,12 @@ export default function DocumentTypesEdit() {
|
|||||||
async function getDocumentType() {
|
async function getDocumentType() {
|
||||||
if (!documentTypeUid) return;
|
if (!documentTypeUid) return;
|
||||||
LoaderService.getInstance().show();
|
LoaderService.getInstance().show();
|
||||||
DocumentTypeService.getDocumentTypeByUid(documentTypeUid as string).then((process: any) => {
|
DocumentTypeService.getDocumentTypeByProcessId(documentTypeUid as string).then((process: any) => {
|
||||||
if (process) {
|
if (process) {
|
||||||
const documentType: any = process.processData;
|
const documentType: any = {
|
||||||
|
...process.processData,
|
||||||
|
processId: process.processId
|
||||||
|
};
|
||||||
setDocumentTypeSelected(documentType);
|
setDocumentTypeSelected(documentType);
|
||||||
}
|
}
|
||||||
LoaderService.getInstance().hide();
|
LoaderService.getInstance().hide();
|
||||||
@ -53,7 +56,7 @@ export default function DocumentTypesEdit() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
LoaderService.getInstance().show();
|
LoaderService.getInstance().show();
|
||||||
DocumentTypeService.getDocumentTypeByUid(documentTypeUid as string).then((process: any) => {
|
DocumentTypeService.getDocumentTypeByProcessId(documentTypeUid as string).then((process: any) => {
|
||||||
if (process) {
|
if (process) {
|
||||||
DocumentTypeService.updateDocumentType(process, values).then(() => {
|
DocumentTypeService.updateDocumentType(process, values).then(() => {
|
||||||
router.push(
|
router.push(
|
||||||
|
@ -22,13 +22,23 @@ export default function DocumentTypesInformations() {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function getDocument() {
|
async function getDocument() {
|
||||||
if (!documentTypeUid) return;
|
if (!documentTypeUid) {
|
||||||
|
console.log('DocumentTypesInformations: documentTypeUid is not available yet');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
DocumentTypeService.getDocumentTypeByUid(documentTypeUid as string).then((process: any) => {
|
DocumentTypeService.getDocumentTypeByProcessId(documentTypeUid as string).then((process: any) => {
|
||||||
if (process) {
|
if (process) {
|
||||||
const document: any = process.processData;
|
const document: any = {
|
||||||
|
...process.processData,
|
||||||
|
processId: process.processId
|
||||||
|
};
|
||||||
setDocumentSelected(document);
|
setDocumentSelected(document);
|
||||||
|
} else {
|
||||||
|
console.log('DocumentTypesInformations: No process found for processId:', documentTypeUid);
|
||||||
}
|
}
|
||||||
|
}).catch((error) => {
|
||||||
|
console.error('DocumentTypesInformations: Error fetching document:', error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,13 +79,15 @@ export default function DocumentTypesInformations() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className={classes["right"]}>
|
<div className={classes["right"]}>
|
||||||
<Link
|
{(documentSelected as any)?.processId && (
|
||||||
href={Module.getInstance()
|
<Link
|
||||||
.get()
|
href={Module.getInstance()
|
||||||
.modules.pages.DocumentTypes.pages.Edit.props.path.replace("[uid]", documentSelected?.uid ?? "")}
|
.get()
|
||||||
className={classes["edit-icon-container"]}>
|
.modules.pages.DocumentTypes.pages.Edit.props.path.replace("[uid]", (documentSelected as any).processId)}
|
||||||
<Image src={PenICon} alt="edit informations" />
|
className={classes["edit-icon-container"]}>
|
||||||
</Link>
|
<Image src={PenICon} alt="edit informations" />
|
||||||
|
</Link>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user