From 0967c142ddbcfe02f47e373051bca6505873cf5c Mon Sep 17 00:00:00 2001 From: Vins Date: Mon, 7 Aug 2023 11:07:48 +0200 Subject: [PATCH] Changed file namespace for Client-dashboard page --- .../Api/LeCoffreApi/Customer/BaseCustomer.ts | 2 +- .../Api/LeCoffreApi/Customer/Files/Files.ts | 93 +++++++++++++++++++ .../DesignSystem/DepositDocument/index.tsx | 2 +- 3 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 src/front/Api/LeCoffreApi/Customer/Files/Files.ts diff --git a/src/front/Api/LeCoffreApi/Customer/BaseCustomer.ts b/src/front/Api/LeCoffreApi/Customer/BaseCustomer.ts index ac56570d..f732de84 100644 --- a/src/front/Api/LeCoffreApi/Customer/BaseCustomer.ts +++ b/src/front/Api/LeCoffreApi/Customer/BaseCustomer.ts @@ -1,5 +1,5 @@ import BaseApiService from "@Front/Api/BaseApiService"; export default abstract class BaseNotary extends BaseApiService { - protected readonly namespaceUrl = this.getBaseUrl().concat("/customers"); + protected readonly namespaceUrl = this.getBaseUrl().concat("/customer"); } diff --git a/src/front/Api/LeCoffreApi/Customer/Files/Files.ts b/src/front/Api/LeCoffreApi/Customer/Files/Files.ts new file mode 100644 index 00000000..4cf6ebd4 --- /dev/null +++ b/src/front/Api/LeCoffreApi/Customer/Files/Files.ts @@ -0,0 +1,93 @@ +import { File } from "le-coffre-resources/dist/SuperAdmin"; +import BaseCustomer from "../BaseCustomer"; + +// TODO Type get query params -> Where + inclue + orderby +export interface IGetFilesparams { + where?: {}; + include?: {}; +} + +// TODO Type getbyuid query params + +export type IPutFilesParams = {}; + +export interface IPostFilesParams {} + +export default class Files extends BaseCustomer { + private static instance: Files; + private readonly baseURl = this.namespaceUrl.concat("/files"); + + private constructor() { + super(); + } + + public static getInstance() { + return (this.instance ??= new this()); + } + + public async get(q: IGetFilesparams): Promise { + const url = new URL(this.baseURl); + const query = { q }; + if (q) Object.entries(query).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value))); + try { + const files = await this.getRequest(url); + return files; + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + /** + * @description : Create a File + */ + public async post(body: any): Promise { + const url = new URL(this.baseURl); + try { + return await this.postRequestFormData(url, body); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public getUploadLink(uid: string): string { + return this.baseURl.concat(`/download/${uid}`); + } + + 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 { + const file = await this.getRequest(url); + return file; + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public async put(uid: string, body: IPutFilesParams): Promise { + const url = new URL(this.baseURl.concat(`/${uid}`)); + try { + return await this.putRequest(url, body); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + /** + * @description : Delete a folder only if the folder don't contains customers + */ + public async delete(uid: string): Promise { + const url = new URL(this.baseURl.concat(`/${uid}`)); + try { + return await this.deleteRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } +} diff --git a/src/front/Components/DesignSystem/DepositDocument/index.tsx b/src/front/Components/DesignSystem/DepositDocument/index.tsx index 8d1a75e1..56aa6122 100644 --- a/src/front/Components/DesignSystem/DepositDocument/index.tsx +++ b/src/front/Components/DesignSystem/DepositDocument/index.tsx @@ -10,7 +10,7 @@ import Tooltip from "../ToolTip"; import Typography, { ITypo, ITypoColor } from "../Typography"; import classes from "./classes.module.scss"; import { Document, DocumentHistory, File as FileCustomer } from "le-coffre-resources/dist/Customer"; -import Files from "@Front/Api/LeCoffreApi/SuperAdmin/Files/Files"; +import Files from "@Front/Api/LeCoffreApi/Customer/Files/Files"; import { EDocumentStatus } from "le-coffre-resources/dist/Customer/Document"; import classNames from "classnames"; import Confirm from "../Modal/Confirm";