From db97b00078028f47b353b1f38cef1d072d99c531 Mon Sep 17 00:00:00 2001 From: OxSaitama Date: Fri, 29 Sep 2023 09:52:34 +0200 Subject: [PATCH 1/3] remove customers calls for customer namespace --- .../Customer/Customers/Customers.ts | 67 ------------------- .../Layouts/ClientDashboard/index.tsx | 20 +++--- .../Layouts/ClientDashboard/index2.tsx | 42 ++++++------ .../Layouts/Folder/ViewDocuments/index.tsx | 1 - .../Components/Layouts/MyAccount/index.tsx | 7 +- .../Components/Layouts/SelectFolder/index.tsx | 2 +- src/front/Services/JwtService/JwtService.ts | 2 +- 7 files changed, 35 insertions(+), 106 deletions(-) delete mode 100644 src/front/Api/LeCoffreApi/Customer/Customers/Customers.ts diff --git a/src/front/Api/LeCoffreApi/Customer/Customers/Customers.ts b/src/front/Api/LeCoffreApi/Customer/Customers/Customers.ts deleted file mode 100644 index b596a695..00000000 --- a/src/front/Api/LeCoffreApi/Customer/Customers/Customers.ts +++ /dev/null @@ -1,67 +0,0 @@ -import Customer, { Contact } from "le-coffre-resources/dist/Customer"; - -import BaseCustomer from "../BaseCustomer"; -import { ECivility } from "le-coffre-resources/dist/Customer/Contact"; - -// TODO Type get query params -> Where + inclue + orderby -export interface IGetCustomersparams { - where?: {}; - include?: {}; -} - -// TODO Type getbyuid query params - -export type IPutCustomersParams = { - uid?: Customer["uid"]; - contact?: Customer["contact"]; -}; - -export interface IPostCustomersParams { - first_name: string; - last_name: string; - email: string; - cell_phone_number: string; - civility: ECivility; - address?: Contact["address"]; -} - -export default class Customers extends BaseCustomer { - private static instance: Customers; - private readonly baseURl = this.namespaceUrl.concat("/customers"); - - private constructor() { - super(); - } - - public static getInstance() { - if (!this.instance) { - return new this(); - } else { - return this.instance; - } - } - - public async get(q: IGetCustomersparams): Promise { - const url = new URL(this.baseURl); - const query = { q }; - Object.entries(query).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value))); - try { - return await this.getRequest(url); - } catch (err) { - this.onError(err); - return Promise.reject(err); - } - } - - public async getByUid(uid: string, q?: any): Promise { - const url = new URL(this.baseURl.concat(`/${uid}`)); - const query = { q }; - if (q) Object.entries(query).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value))); - try { - return await this.getRequest(url); - } catch (err) { - this.onError(err); - return Promise.reject(err); - } - } -} diff --git a/src/front/Components/Layouts/ClientDashboard/index.tsx b/src/front/Components/Layouts/ClientDashboard/index.tsx index 2985328c..b090a4bf 100644 --- a/src/front/Components/Layouts/ClientDashboard/index.tsx +++ b/src/front/Components/Layouts/ClientDashboard/index.tsx @@ -1,5 +1,4 @@ "use client"; -import Customers from "@Front/Api/LeCoffreApi/Customer/Customers/Customers"; import Documents, { IGetDocumentsparams } from "@Front/Api/LeCoffreApi/Customer/Documents/Documents"; import Button, { EButtonVariant } from "@Front/Components/DesignSystem/Button"; import DepositDocument from "@Front/Components/DesignSystem/DepositDocument"; @@ -10,7 +9,7 @@ import React, { useCallback, useEffect, useState } from "react"; import classes from "./classes.module.scss"; import { useRouter } from "next/router"; -import JwtService from "@Front/Services/JwtService/JwtService"; +import JwtService, { ICustomerJwtPayload } from "@Front/Services/JwtService/JwtService"; import DepositOtherDocument from "@Front/Components/DesignSystem/DepositOtherDocument"; import Folders from "@Front/Api/LeCoffreApi/Customer/Folders/Folders"; @@ -25,15 +24,15 @@ export default function ClientDashboard(props: IProps) { const [isAddDocumentModalVisible, setIsAddDocumentModalVisible] = useState(false); const getDocuments = useCallback(async () => { - let jwt; + let jwt: ICustomerJwtPayload | undefined;; if (typeof document !== "undefined") { - jwt = JwtService.getInstance().decodeJwt(); + jwt = JwtService.getInstance().decodeCustomerJwt(); } - if (!jwt || !jwt.email) return; - const customers = await Customers.getInstance().get({ - where: { contact: { email: jwt.email }, office_folders: { some: { uid: folderUid } } }, - }); - const actualCustomer: Customer = customers[0]!; + + const folder = await Folders.getInstance().getByUid(folderUid as string, { q: { office: true, customers: true } }); + + const actualCustomer = folder?.customers?.find((customer) => customer.uid === jwt?.customerId); + if(!actualCustomer) throw new Error("Customer not found"); const query: IGetDocumentsparams = { where: { depositor: { uid: actualCustomer.uid }, folder_uid: folderUid as string }, @@ -47,7 +46,8 @@ export default function ClientDashboard(props: IProps) { const documentList = await Documents.getInstance().get(query); - const folder = await Folders.getInstance().getByUid(folderUid as string, { q: { office: true } }); + //const folder = await Folders.getInstance().getByUid(folderUid as string, { q: { office: true, customers: true } }); + setFolder(folder); setDocuments(documentList); setCustomer(actualCustomer); diff --git a/src/front/Components/Layouts/ClientDashboard/index2.tsx b/src/front/Components/Layouts/ClientDashboard/index2.tsx index ee472c3e..226c45d1 100644 --- a/src/front/Components/Layouts/ClientDashboard/index2.tsx +++ b/src/front/Components/Layouts/ClientDashboard/index2.tsx @@ -1,5 +1,4 @@ -import Customers from "@Front/Api/LeCoffreApi/Customer/Customers/Customers"; -import Documents, { IGetDocumentsparams } from "@Front/Api/LeCoffreApi/Customer/Documents/Documents"; +//import Customers from "@Front/Api/LeCoffreApi/Customer/Customers/Customers"; import Button, { EButtonVariant } from "@Front/Components/DesignSystem/Button"; import DepositDocument from "@Front/Components/DesignSystem/DepositDocument"; import TextField from "@Front/Components/DesignSystem/Form/TextField"; @@ -11,7 +10,6 @@ import Customer, { Document, DocumentType } from "le-coffre-resources/dist/Custo import React from "react"; import classes from "./classes.module.scss"; -import JwtService from "@Front/Services/JwtService/JwtService"; type IProps = {}; type IState = { @@ -109,27 +107,27 @@ export default class ClientDashboard extends Base { ); } - public override async componentDidMount() { - // TODO Get documents of the current customer according to userStore - // REMOVE this mock + // public override async componentDidMount() { + // // TODO Get documents of the current customer according to userStore + // // REMOVE this mock - const jwt = JwtService.getInstance().decodeJwt(); - const mockedCustomers = await Customers.getInstance().get({ - where: { contact: { email: jwt?.email } }, - }); - const mockedCustomer: Customer = mockedCustomers[0]!; + // const jwt = JwtService.getInstance().decodeJwt(); + // const mockedCustomers = await Customers.getInstance().get({ + // where: { contact: { email: jwt?.email } }, + // }); + // const mockedCustomer: Customer = mockedCustomers[0]!; - const query: IGetDocumentsparams = { - where: { depositor: { uid: mockedCustomer.uid } }, - include: { - files: true, - document_history: true, - document_type: true, - }, - }; - const documents: Document[] = await Documents.getInstance().get(query); - this.setState({ documents, mockedCustomer }); - } + // const query: IGetDocumentsparams = { + // where: { depositor: { uid: mockedCustomer.uid } }, + // include: { + // files: true, + // document_history: true, + // document_type: true, + // }, + // }; + // const documents: Document[] = await Documents.getInstance().get(query); + // this.setState({ documents, mockedCustomer }); + // } private onCloseModalAddDocument() { this.setState({ isAddDocumentModalVisible: false }); diff --git a/src/front/Components/Layouts/Folder/ViewDocuments/index.tsx b/src/front/Components/Layouts/Folder/ViewDocuments/index.tsx index e7827e19..3dc4d9d1 100644 --- a/src/front/Components/Layouts/Folder/ViewDocuments/index.tsx +++ b/src/front/Components/Layouts/Folder/ViewDocuments/index.tsx @@ -15,7 +15,6 @@ import React from "react"; import BasePage from "../../Base"; import classes from "./classes.module.scss"; -import OcrResult from "./OcrResult"; import Files from "@Front/Api/LeCoffreApi/Notary/Files/Files"; import TextAreaField from "@Front/Components/DesignSystem/Form/TextareaField"; diff --git a/src/front/Components/Layouts/MyAccount/index.tsx b/src/front/Components/Layouts/MyAccount/index.tsx index 43863b7b..4ac8be58 100644 --- a/src/front/Components/Layouts/MyAccount/index.tsx +++ b/src/front/Components/Layouts/MyAccount/index.tsx @@ -116,10 +116,9 @@ export default class MyAccount extends Base { } public override async componentDidMount() { - const jwtUncoded = JwtService.getInstance().decodeCustomerJwt(); - console.log(jwtUncoded); - if (!jwtUncoded) return; - const user = await Users.getInstance().getByUid(jwtUncoded.userId, { + const jwtDecoded = JwtService.getInstance().decodeJwt(); + if (!jwtDecoded) return; + const user = await Users.getInstance().getByUid(jwtDecoded.userId, { q: { office_membership: { include: { diff --git a/src/front/Components/Layouts/SelectFolder/index.tsx b/src/front/Components/Layouts/SelectFolder/index.tsx index 3f4f54d2..7650cc05 100644 --- a/src/front/Components/Layouts/SelectFolder/index.tsx +++ b/src/front/Components/Layouts/SelectFolder/index.tsx @@ -25,7 +25,7 @@ export default function SelectFolder() { where: { customers: { some: { - uid: jwt.userId || (jwt as any).customerId, + uid: jwt.customerId || (jwt as any).customerId, }, }, }, diff --git a/src/front/Services/JwtService/JwtService.ts b/src/front/Services/JwtService/JwtService.ts index a2fd9183..dd1dbf2c 100644 --- a/src/front/Services/JwtService/JwtService.ts +++ b/src/front/Services/JwtService/JwtService.ts @@ -20,7 +20,7 @@ export interface IUserJwtPayload { } export interface ICustomerJwtPayload { - userId: string; + customerId: string; email: string; } From cd05e2dde0d647264f99d642eff0429b8b0ef266 Mon Sep 17 00:00:00 2001 From: OxSaitama Date: Fri, 29 Sep 2023 09:55:09 +0200 Subject: [PATCH 2/3] update resource version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cc9c4d3e..53e1bb64 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "eslint-config-next": "13.2.4", "form-data": "^4.0.0", "jwt-decode": "^3.1.2", - "le-coffre-resources": "git@github.com:smart-chain-fr/leCoffre-resources.git#v2.84", + "le-coffre-resources": "git@github.com:smart-chain-fr/leCoffre-resources.git#v2.85", "next": "13.2.4", "prettier": "^2.8.7", "react": "18.2.0", From 1a8439a2a66f547d325615004ed9aa1ebab63d88 Mon Sep 17 00:00:00 2001 From: OxSaitama Date: Fri, 29 Sep 2023 10:46:48 +0200 Subject: [PATCH 3/3] delete unused api calls --- .../Api/LeCoffreApi/Customer/Users/Users.ts | 49 ------------------- .../Layouts/ClientDashboard/index.tsx | 3 +- 2 files changed, 1 insertion(+), 51 deletions(-) delete mode 100644 src/front/Api/LeCoffreApi/Customer/Users/Users.ts diff --git a/src/front/Api/LeCoffreApi/Customer/Users/Users.ts b/src/front/Api/LeCoffreApi/Customer/Users/Users.ts deleted file mode 100644 index e64928bc..00000000 --- a/src/front/Api/LeCoffreApi/Customer/Users/Users.ts +++ /dev/null @@ -1,49 +0,0 @@ -import BaseNotary from "../BaseCustomer"; -import User from "le-coffre-resources/dist/Notary"; - -export default class Users extends BaseNotary { - private static instance: Users; - private readonly baseURl = this.namespaceUrl.concat("/Users"); - - private constructor() { - super(); - } - - public static getInstance() { - if (!this.instance) { - return new Users(); - } else { - return this.instance; - } - } - - public async get(): Promise { - const url = new URL(this.baseURl); - try { - return await this.getRequest(url); - } catch (err) { - this.onError(err); - return Promise.reject(err); - } - } - - public async getOne(uid: string): Promise { - const url = new URL(this.baseURl.concat("/").concat(uid)); - try { - return await this.getRequest(url); - } catch (err) { - this.onError(err); - return Promise.reject(err); - } - } - - // public async post(params: User): Promise { - // const url = new URL(this.baseURl); - // try { - // return await this.postRequest(url, params); - // } catch (err) { - // this.onError(err); - // return Promise.reject(err); - // } - // } -} diff --git a/src/front/Components/Layouts/ClientDashboard/index.tsx b/src/front/Components/Layouts/ClientDashboard/index.tsx index b090a4bf..de5609e4 100644 --- a/src/front/Components/Layouts/ClientDashboard/index.tsx +++ b/src/front/Components/Layouts/ClientDashboard/index.tsx @@ -30,7 +30,7 @@ export default function ClientDashboard(props: IProps) { } const folder = await Folders.getInstance().getByUid(folderUid as string, { q: { office: true, customers: true } }); - + console.log(folder) const actualCustomer = folder?.customers?.find((customer) => customer.uid === jwt?.customerId); if(!actualCustomer) throw new Error("Customer not found"); @@ -67,7 +67,6 @@ export default function ClientDashboard(props: IProps) { }, [folderUid, getDocuments]); const renderHeader = useCallback(() => { - console.log("Dossier : ", customer); return (