From 1e8e5cf16560a7350c9737c08c37487148381646 Mon Sep 17 00:00:00 2001 From: OxSaitama Date: Wed, 18 Oct 2023 18:56:37 +0200 Subject: [PATCH] refacto customer handling --- .../Components/Layouts/ClientDashboard/index.tsx | 12 +++++++++++- src/front/Components/Layouts/SelectFolder/index.tsx | 8 +++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/front/Components/Layouts/ClientDashboard/index.tsx b/src/front/Components/Layouts/ClientDashboard/index.tsx index 6c048e86..96421e68 100644 --- a/src/front/Components/Layouts/ClientDashboard/index.tsx +++ b/src/front/Components/Layouts/ClientDashboard/index.tsx @@ -31,7 +31,7 @@ export default function ClientDashboard(props: IProps) { } const folder = await Folders.getInstance().getByUid(folderUid as string, { q: { office: true, customers: true } }); - const actualCustomer = folder?.customers?.find((customer) => customer.uid === jwt?.customerId); + const actualCustomer = folder?.customers?.find((customer) => customer.contact?.email === jwt?.email); if (!actualCustomer) throw new Error("Customer not found"); const query: IGetDocumentsparams = { @@ -41,6 +41,16 @@ export default function ClientDashboard(props: IProps) { document_history: true, document_type: true, depositor: true, + folder: { + include: { + customers: { + include: { + contact: true, + }, + + } + } + } }, }; diff --git a/src/front/Components/Layouts/SelectFolder/index.tsx b/src/front/Components/Layouts/SelectFolder/index.tsx index d23a8146..912f7107 100644 --- a/src/front/Components/Layouts/SelectFolder/index.tsx +++ b/src/front/Components/Layouts/SelectFolder/index.tsx @@ -18,13 +18,16 @@ export default function SelectFolder() { async function getFolders() { const jwt = JwtService.getInstance().decodeCustomerJwt(); if (!jwt) return; + console.log(jwt) const folders = await Folders.getInstance().get({ q: { where: { customers: { some: { - uid: jwt.customerId || (jwt as any).customerId, + contact: { + email: jwt.email, + }, }, }, }, @@ -33,6 +36,9 @@ export default function SelectFolder() { created_at: "desc", }, ], + include: { + customers: true + } }, }); setFolders(folders);