From 575700761e981f707f0befc55b461dfcd79fe4de Mon Sep 17 00:00:00 2001 From: Maxime Lalo Date: Wed, 4 Oct 2023 17:23:18 +0200 Subject: [PATCH] :sparkles: Refacto archive/restore --- .../Api/LeCoffreApi/Notary/Folders/Folders.ts | 25 +++++++++++++------ .../Folder/FolderInformation/index.tsx | 4 +-- .../FolderInformation/index.tsx | 4 +-- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/front/Api/LeCoffreApi/Notary/Folders/Folders.ts b/src/front/Api/LeCoffreApi/Notary/Folders/Folders.ts index 800d3c96..b7aa1342 100644 --- a/src/front/Api/LeCoffreApi/Notary/Folders/Folders.ts +++ b/src/front/Api/LeCoffreApi/Notary/Folders/Folders.ts @@ -1,7 +1,6 @@ import { type OfficeFolder } from "le-coffre-resources/dist/Notary"; import BaseNotary from "../BaseNotary"; -import EFolderStatus from "le-coffre-resources/dist/Customer/EFolderStatus"; // TODO Type get query params -> Where + inclue + orderby export interface IGetFoldersParams { @@ -97,20 +96,32 @@ export default class Folders extends BaseNotary { } } - public async archive(uid: string, body: Partial): Promise { - body.status = EFolderStatus.ARCHIVED; + public async archive(uid: string, archived_description: string): Promise { try { - return await this.put(uid, body); + const url = new URL(this.baseURl.concat(`/${uid}/archive`)); + try { + return await this.putRequest(url, { + archived_description, + }); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } } catch (err) { this.onError(err); return Promise.reject(err); } } - public async restore(uid: string, body: Partial): Promise { - body.status = EFolderStatus.LIVE; + public async restore(uid: string): Promise { try { - return await this.put(uid, body); + const url = new URL(this.baseURl.concat(`/${uid}/restore`)); + try { + return await this.putRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } } catch (err) { this.onError(err); return Promise.reject(err); diff --git a/src/front/Components/Layouts/Folder/FolderInformation/index.tsx b/src/front/Components/Layouts/Folder/FolderInformation/index.tsx index aa817ad9..640ad945 100644 --- a/src/front/Components/Layouts/Folder/FolderInformation/index.tsx +++ b/src/front/Components/Layouts/Folder/FolderInformation/index.tsx @@ -393,9 +393,7 @@ class FolderInformationClass extends BasePage { private async onArchivedModalAccepted() { if (!this.props.selectedFolder) return; - const ressourceFolder = OfficeFolder.hydrate(this.props.selectedFolder); - ressourceFolder.archived_description = this.state.inputArchivedDescripton; - await Folders.getInstance().archive(this.props.selectedFolder.uid ?? "", ressourceFolder); + await Folders.getInstance().archive(this.props.selectedFolder.uid ?? "", this.state.inputArchivedDescripton); this.closeArchivedModal(); this.props.router.push(Module.getInstance().get().modules.pages.Folder.props.path); } diff --git a/src/front/Components/Layouts/FolderArchived/FolderInformation/index.tsx b/src/front/Components/Layouts/FolderArchived/FolderInformation/index.tsx index 8376f0a4..1eb5600c 100644 --- a/src/front/Components/Layouts/FolderArchived/FolderInformation/index.tsx +++ b/src/front/Components/Layouts/FolderArchived/FolderInformation/index.tsx @@ -123,9 +123,7 @@ class FolderInformationClass extends BasePage { private async restoreFolder() { if (!this.state.selectedFolder) return; - const ressourceFolder = OfficeFolder.hydrate(this.state.selectedFolder); - ressourceFolder.archived_description = null; - await Folders.getInstance().restore(this.state.selectedFolder.uid ?? "", ressourceFolder); + await Folders.getInstance().restore(this.state.selectedFolder.uid ?? ""); this.props.router.push( Module.getInstance() .get()