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 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<OfficeFolder>): Promise<OfficeFolder> {
body.status = EFolderStatus.ARCHIVED;
public async archive(uid: string, archived_description: string): Promise<OfficeFolder> {
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<OfficeFolder>): Promise<OfficeFolder> {
body.status = EFolderStatus.LIVE;
public async restore(uid: string): Promise<OfficeFolder> {
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);

View File

@ -393,9 +393,7 @@ class FolderInformationClass extends BasePage<IPropsClass, IState> {
private async onArchivedModalAccepted() {
if (!this.props.selectedFolder) return;
const ressourceFolder = OfficeFolder.hydrate<OfficeFolder>(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);
}

View File

@ -123,9 +123,7 @@ class FolderInformationClass extends BasePage<IPropsClass, IState> {
private async restoreFolder() {
if (!this.state.selectedFolder) return;
const ressourceFolder = OfficeFolder.hydrate<OfficeFolder>(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()