Refacto archive/restore

This commit is contained in:
Maxime Lalo 2023-10-04 17:23:18 +02:00
parent 62f38cc36f
commit 575700761e
3 changed files with 20 additions and 13 deletions

View File

@ -1,7 +1,6 @@
import { type OfficeFolder } from "le-coffre-resources/dist/Notary"; import { type OfficeFolder } from "le-coffre-resources/dist/Notary";
import BaseNotary from "../BaseNotary"; import BaseNotary from "../BaseNotary";
import EFolderStatus from "le-coffre-resources/dist/Customer/EFolderStatus";
// TODO Type get query params -> Where + inclue + orderby // TODO Type get query params -> Where + inclue + orderby
export interface IGetFoldersParams { export interface IGetFoldersParams {
@ -97,20 +96,32 @@ export default class Folders extends BaseNotary {
} }
} }
public async archive(uid: string, body: Partial<OfficeFolder>): Promise<OfficeFolder> { public async archive(uid: string, archived_description: string): Promise<OfficeFolder> {
body.status = EFolderStatus.ARCHIVED;
try { 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) { } catch (err) {
this.onError(err); this.onError(err);
return Promise.reject(err); return Promise.reject(err);
} }
} }
public async restore(uid: string, body: Partial<OfficeFolder>): Promise<OfficeFolder> { public async restore(uid: string): Promise<OfficeFolder> {
body.status = EFolderStatus.LIVE;
try { 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) { } catch (err) {
this.onError(err); this.onError(err);
return Promise.reject(err); return Promise.reject(err);

View File

@ -393,9 +393,7 @@ class FolderInformationClass extends BasePage<IPropsClass, IState> {
private async onArchivedModalAccepted() { private async onArchivedModalAccepted() {
if (!this.props.selectedFolder) return; if (!this.props.selectedFolder) return;
const ressourceFolder = OfficeFolder.hydrate<OfficeFolder>(this.props.selectedFolder); await Folders.getInstance().archive(this.props.selectedFolder.uid ?? "", this.state.inputArchivedDescripton);
ressourceFolder.archived_description = this.state.inputArchivedDescripton;
await Folders.getInstance().archive(this.props.selectedFolder.uid ?? "", ressourceFolder);
this.closeArchivedModal(); this.closeArchivedModal();
this.props.router.push(Module.getInstance().get().modules.pages.Folder.props.path); this.props.router.push(Module.getInstance().get().modules.pages.Folder.props.path);
} }

View File

@ -123,9 +123,7 @@ class FolderInformationClass extends BasePage<IPropsClass, IState> {
private async restoreFolder() { private async restoreFolder() {
if (!this.state.selectedFolder) return; if (!this.state.selectedFolder) return;
const ressourceFolder = OfficeFolder.hydrate<OfficeFolder>(this.state.selectedFolder); await Folders.getInstance().restore(this.state.selectedFolder.uid ?? "");
ressourceFolder.archived_description = null;
await Folders.getInstance().restore(this.state.selectedFolder.uid ?? "", ressourceFolder);
this.props.router.push( this.props.router.push(
Module.getInstance() Module.getInstance()
.get() .get()