Fix some bugs - continue
This commit is contained in:
parent
ccc0a1620c
commit
d7e27bbb9a
@ -83,11 +83,12 @@ export default class CustomerService {
|
|||||||
|
|
||||||
public static getCustomerByUid(uid: string): Promise<any> {
|
public static getCustomerByUid(uid: string): Promise<any> {
|
||||||
return new Promise<any>((resolve: (process: any) => void, reject: (error: string) => void) => {
|
return new Promise<any>((resolve: (process: any) => void, reject: (error: string) => void) => {
|
||||||
this.messageBus.getProcessesDecoded((publicValues: any) => publicValues['uid'] && publicValues['uid'] === uid && publicValues['utype'] && publicValues['utype'] === 'customer').then((profiles: any[]) => {
|
this.messageBus.getProcessesDecoded((publicValues: any) => publicValues['uid'] && publicValues['uid'] === uid && publicValues['utype'] && publicValues['utype'] === 'customer').then((processes: any[]) => {
|
||||||
if (profiles.length === 0) {
|
if (processes.length === 0) {
|
||||||
resolve(null);
|
resolve(null);
|
||||||
} else {
|
} else {
|
||||||
resolve(profiles[0]);
|
const process: any = processes[0];
|
||||||
|
resolve(process);
|
||||||
}
|
}
|
||||||
}).catch(reject);
|
}).catch(reject);
|
||||||
});
|
});
|
||||||
|
@ -87,7 +87,8 @@ export default class DocumentService {
|
|||||||
if (processes.length === 0) {
|
if (processes.length === 0) {
|
||||||
resolve(null);
|
resolve(null);
|
||||||
} else {
|
} else {
|
||||||
resolve(processes[0]);
|
const process: any = processes[0];
|
||||||
|
resolve(process);
|
||||||
}
|
}
|
||||||
}).catch(reject);
|
}).catch(reject);
|
||||||
});
|
});
|
||||||
|
@ -87,7 +87,8 @@ export default class DocumentTypeService {
|
|||||||
if (processes.length === 0) {
|
if (processes.length === 0) {
|
||||||
resolve(null);
|
resolve(null);
|
||||||
} else {
|
} else {
|
||||||
resolve(processes[0]);
|
const process: any = processes[0];
|
||||||
|
resolve(process);
|
||||||
}
|
}
|
||||||
}).catch(reject);
|
}).catch(reject);
|
||||||
});
|
});
|
||||||
|
109
src/common/Api/LeCoffreApi/sdk/FileService.ts
Normal file
109
src/common/Api/LeCoffreApi/sdk/FileService.ts
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
|
||||||
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
|
|
||||||
|
import MessageBus from 'src/sdk/MessageBus';
|
||||||
|
import User from 'src/sdk/User';
|
||||||
|
|
||||||
|
export default class FileService {
|
||||||
|
|
||||||
|
private static readonly messageBus: MessageBus = MessageBus.getInstance();
|
||||||
|
|
||||||
|
private constructor() { }
|
||||||
|
|
||||||
|
public static createFile(fileData: any, validatorId: string): Promise<any> {
|
||||||
|
const ownerId = User.getInstance().getPairingId()!;
|
||||||
|
|
||||||
|
const processData: any = {
|
||||||
|
uid: uuidv4(),
|
||||||
|
utype: 'file',
|
||||||
|
isDeleted: 'false',
|
||||||
|
created_at: new Date().toISOString(),
|
||||||
|
updated_at: new Date().toISOString(),
|
||||||
|
...fileData,
|
||||||
|
};
|
||||||
|
|
||||||
|
const privateFields: string[] = Object.keys(processData);
|
||||||
|
privateFields.splice(privateFields.indexOf('uid'), 1);
|
||||||
|
privateFields.splice(privateFields.indexOf('utype'), 1);
|
||||||
|
|
||||||
|
const roles: any = {
|
||||||
|
demiurge: {
|
||||||
|
members: [...[ownerId], validatorId],
|
||||||
|
validation_rules: [],
|
||||||
|
storages: []
|
||||||
|
},
|
||||||
|
owner: {
|
||||||
|
members: [ownerId],
|
||||||
|
validation_rules: [
|
||||||
|
{
|
||||||
|
quorum: 0.5,
|
||||||
|
fields: [...privateFields, 'roles', 'uid', 'utype'],
|
||||||
|
min_sig_member: 1,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
storages: []
|
||||||
|
},
|
||||||
|
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: {
|
||||||
|
members: [ownerId],
|
||||||
|
validation_rules: [],
|
||||||
|
storages: []
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return new Promise<any>((resolve: (processCreated: any) => void, reject: (error: string) => void) => {
|
||||||
|
this.messageBus.createProcess(processData, privateFields, roles).then((processCreated: any) => {
|
||||||
|
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) => {
|
||||||
|
resolve(processCreated);
|
||||||
|
}).catch(reject);
|
||||||
|
}).catch(reject);
|
||||||
|
}).catch(reject);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static getFiles(): Promise<any[]> {
|
||||||
|
return this.messageBus.getProcessesDecoded((publicValues: any) => publicValues['uid'] && publicValues['utype'] && publicValues['utype'] === 'file');
|
||||||
|
}
|
||||||
|
|
||||||
|
public static getFileByUid(uid: string): Promise<any> {
|
||||||
|
return new Promise<any>((resolve: (process: any) => void, reject: (error: string) => void) => {
|
||||||
|
this.messageBus.getProcessesDecoded((publicValues: any) => publicValues['uid'] && publicValues['uid'] === uid && publicValues['utype'] && publicValues['utype'] === 'file').then(async (processes: any[]) => {
|
||||||
|
if (processes.length === 0) {
|
||||||
|
resolve(null);
|
||||||
|
} else {
|
||||||
|
const process: any = processes[0];
|
||||||
|
resolve(process);
|
||||||
|
}
|
||||||
|
}).catch(reject);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static updateFile(process: any, newData: any): Promise<void> {
|
||||||
|
return new Promise<void>((resolve: () => void, reject: (error: string) => void) => {
|
||||||
|
this.messageBus.updateProcess(process.processId, 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) => {
|
||||||
|
resolve();
|
||||||
|
}).catch(reject);
|
||||||
|
}).catch(reject);
|
||||||
|
}).catch(reject);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -8,6 +8,8 @@ import Files from "@Front/Api/LeCoffreApi/Customer/Files/Files";
|
|||||||
import { ToasterService } from "@Front/Components/DesignSystem/Toaster";
|
import { ToasterService } from "@Front/Components/DesignSystem/Toaster";
|
||||||
import Confirm from "@Front/Components/DesignSystem/OldModal/Confirm";
|
import Confirm from "@Front/Components/DesignSystem/OldModal/Confirm";
|
||||||
|
|
||||||
|
import FileService from "src/common/Api/LeCoffreApi/sdk/FileService";
|
||||||
|
|
||||||
type IProps = {
|
type IProps = {
|
||||||
document: Document;
|
document: Document;
|
||||||
onChange: () => void;
|
onChange: () => void;
|
||||||
@ -29,6 +31,7 @@ export default function DepositDocumentComponent(props: IProps) {
|
|||||||
|
|
||||||
const addFile = useCallback(
|
const addFile = useCallback(
|
||||||
(file: File) => {
|
(file: File) => {
|
||||||
|
/* TODO: review
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
const safeFileName = file.name.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
|
const safeFileName = file.name.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
|
||||||
formData.append("file", file, safeFileName);
|
formData.append("file", file, safeFileName);
|
||||||
@ -39,17 +42,64 @@ export default function DepositDocumentComponent(props: IProps) {
|
|||||||
.then(onChange)
|
.then(onChange)
|
||||||
.then(() => ToasterService.getInstance().success({ title: "Succès !", description: "Fichier uploadé avec succès!" }))
|
.then(() => ToasterService.getInstance().success({ title: "Succès !", description: "Fichier uploadé avec succès!" }))
|
||||||
.catch((error) => ToasterService.getInstance().error({ title: "Erreur !", description: error.message }));
|
.catch((error) => ToasterService.getInstance().error({ title: "Erreur !", description: error.message }));
|
||||||
|
*/
|
||||||
|
|
||||||
|
return new Promise<void>(
|
||||||
|
(resolve: () => void) => {
|
||||||
|
const reader = new FileReader();
|
||||||
|
reader.onload = (event) => {
|
||||||
|
if (event.target?.result) {
|
||||||
|
const arrayBuffer = event.target.result as ArrayBuffer;
|
||||||
|
const uint8Array = new Uint8Array(arrayBuffer);
|
||||||
|
|
||||||
|
const fileBlob = {
|
||||||
|
type: file.type,
|
||||||
|
data: uint8Array
|
||||||
|
};
|
||||||
|
|
||||||
|
const fileData = {
|
||||||
|
document: {
|
||||||
|
uid: document.uid
|
||||||
|
},
|
||||||
|
file: fileBlob,
|
||||||
|
file_name: file.name,
|
||||||
|
mimetype: file.type
|
||||||
|
}
|
||||||
|
const validatorId: string = '884cb36a346a79af8697559f16940141f068bdf1656f88fa0df0e9ecd7311fb8:0';
|
||||||
|
|
||||||
|
FileService.createFile(fileData, validatorId).then(() => resolve());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
reader.readAsArrayBuffer(file);
|
||||||
|
})
|
||||||
|
.then(onChange)
|
||||||
|
.then(() => ToasterService.getInstance().success({ title: "Succès !", description: "Fichier uploadé avec succès!" }))
|
||||||
|
.catch((error) => ToasterService.getInstance().error({ title: "Erreur !", description: error.message }));
|
||||||
},
|
},
|
||||||
[document.uid, onChange],
|
[document.uid, onChange],
|
||||||
);
|
);
|
||||||
|
|
||||||
const deleteFile = useCallback(
|
const deleteFile = useCallback(
|
||||||
(filedUid: string) => {
|
(filedUid: string) => {
|
||||||
|
return new Promise<void>(
|
||||||
|
(resolve: () => void) => {
|
||||||
|
FileService.getFileByUid(filedUid).then((process: any) => {
|
||||||
|
if (process) {
|
||||||
|
FileService.updateFile(process, { isDeleted: 'true' }).then(() => resolve());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.then(onChange)
|
||||||
|
.then(() => ToasterService.getInstance().success({ title: "Succès !", description: "Fichier supprimé avec succès!" }))
|
||||||
|
.catch((error) => ToasterService.getInstance().error({ title: "Erreur !", description: error.message }));
|
||||||
|
|
||||||
|
/* TODO: review
|
||||||
return Files.getInstance()
|
return Files.getInstance()
|
||||||
.delete(filedUid)
|
.delete(filedUid)
|
||||||
.then(onChange)
|
.then(onChange)
|
||||||
.then(() => ToasterService.getInstance().success({ title: "Succès !", description: "Fichier supprimé avec succès!" }))
|
.then(() => ToasterService.getInstance().success({ title: "Succès !", description: "Fichier supprimé avec succès!" }))
|
||||||
.catch((error) => ToasterService.getInstance().error({ title: "Erreur !", description: error.message }));
|
.catch((error) => ToasterService.getInstance().error({ title: "Erreur !", description: error.message }));
|
||||||
|
*/
|
||||||
},
|
},
|
||||||
[onChange],
|
[onChange],
|
||||||
);
|
);
|
||||||
|
@ -25,14 +25,13 @@ import DocumentsNotary from "@Front/Api/LeCoffreApi/Customer/DocumentsNotary/Doc
|
|||||||
import { EDocumentNotaryStatus } from "le-coffre-resources/dist/Notary/DocumentNotary";
|
import { EDocumentNotaryStatus } from "le-coffre-resources/dist/Notary/DocumentNotary";
|
||||||
import DepositOtherDocument from "@Front/Components/DesignSystem/DepositOtherDocument";
|
import DepositOtherDocument from "@Front/Components/DesignSystem/DepositOtherDocument";
|
||||||
|
|
||||||
import { v4 as uuidv4 } from "uuid";
|
|
||||||
|
|
||||||
import AuthModal from "src/sdk/AuthModal";
|
import AuthModal from "src/sdk/AuthModal";
|
||||||
//import FormModal from "./FormModal";
|
//import FormModal from "./FormModal";
|
||||||
|
|
||||||
import FolderService from "src/common/Api/LeCoffreApi/sdk/FolderService";
|
import FolderService from "src/common/Api/LeCoffreApi/sdk/FolderService";
|
||||||
import DocumentService from "src/common/Api/LeCoffreApi/sdk/DocumentService";
|
import DocumentService from "src/common/Api/LeCoffreApi/sdk/DocumentService";
|
||||||
import DocumentTypeService from "src/common/Api/LeCoffreApi/sdk/DocumentTypeService";
|
import DocumentTypeService from "src/common/Api/LeCoffreApi/sdk/DocumentTypeService";
|
||||||
|
import FileService from "src/common/Api/LeCoffreApi/sdk/FileService";
|
||||||
|
|
||||||
type IProps = {};
|
type IProps = {};
|
||||||
|
|
||||||
@ -61,9 +60,7 @@ export default function ClientDashboard(props: IProps) {
|
|||||||
const customers: any[] = folder.customers;
|
const customers: any[] = folder.customers;
|
||||||
const customer: any = customers.find((customer: any) => customer.uid === profileUid as string);
|
const customer: any = customers.find((customer: any) => customer.uid === profileUid as string);
|
||||||
if (customer) {
|
if (customer) {
|
||||||
|
resolve({ folder: folder, customer });
|
||||||
|
|
||||||
resolve({ folder: folder, customer, file: null });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -177,9 +174,17 @@ export default function ClientDashboard(props: IProps) {
|
|||||||
if (processes.length > 0) {
|
if (processes.length > 0) {
|
||||||
const documents: any[] = processes.map((process: any) => process.processData);
|
const documents: any[] = processes.map((process: any) => process.processData);
|
||||||
|
|
||||||
|
const files: any[] = (await FileService.getFiles())
|
||||||
|
.map((p: any) => p.processData)
|
||||||
|
.filter((file: any) => file.isDeleted === 'false');
|
||||||
|
|
||||||
for (const document of documents) {
|
for (const document of documents) {
|
||||||
const p: any = await DocumentTypeService.getDocumentTypeByUid(document.document_type.uid);
|
const p: any = await DocumentTypeService.getDocumentTypeByUid(document.document_type.uid);
|
||||||
document.document_type = p.processData;
|
document.document_type = p.processData;
|
||||||
|
|
||||||
|
if (files.length > 0) {
|
||||||
|
document.files = files.filter((file: any) => file.document.uid === document.uid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setDocuments(documents);
|
setDocuments(documents);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user