DocSpace-client/packages/common/api/rooms/index.js
2022-08-25 18:16:03 +03:00

205 lines
3.8 KiB
JavaScript

import { request } from "../client";
import { decodeDisplayName } from "../../utils";
import { FolderType } from "../../constants";
export function getRooms(filter) {
const options = {
method: "get",
url: `/files/rooms?${filter.toApiUrlParams()}`,
};
return request(options).then((res) => {
res.files = decodeDisplayName(res.files);
res.folders = decodeDisplayName(res.folders);
if (res.current.rootFolderType === FolderType.Archive) {
res.folders.forEach((room) => (room.isArchive = true));
}
return res;
});
}
export function getRoomInfo(id) {
const options = {
method: "get",
url: `/files/rooms/${id}`,
};
return request(options).then((res) => {
res.files = decodeDisplayName(res.files);
res.folders = decodeDisplayName(res.folders);
return res;
});
}
export function createRoom(data) {
const options = { method: "post", url: `/files/rooms`, data };
return request(options).then((res) => {
return res;
});
}
export function createRoomInThirdpary(id, data) {
const options = {
method: "post",
url: `/files/rooms/thirdparty/${id}`,
data,
};
return request(options).then((res) => {
return res;
});
}
export function editRoom(id, data) {
const options = { method: "put", url: `/files/rooms/${id}`, data };
return request(options).then((res) => {
return res;
});
}
export function pinRoom(id) {
const options = { method: "put", url: `/files/rooms/${id}/pin` };
return request(options).then((res) => {
return res;
});
}
export function unpinRoom(id) {
const options = { method: "put", url: `/files/rooms/${id}/unpin` };
return request(options).then((res) => {
return res;
});
}
export function deleteRoom(id, deleteAfter = true) {
const data = { deleteAfter };
const options = {
method: "delete",
url: `/files/rooms/${id}`,
data,
};
return request(options).then((res) => {
return res;
});
}
export function archiveRoom(id, deleteAfter = true) {
const data = { deleteAfter };
const options = {
method: "put",
url: `/files/rooms/${id}/archive`,
data,
};
return request(options).then((res) => {
return res;
});
}
export function unarchiveRoom(id, deleteAfter = true) {
const data = { deleteAfter };
const options = {
method: "put",
url: `/files/rooms/${id}/unarchive`,
data,
};
return request(options).then((res) => {
return res;
});
}
export function createTag(name) {
const data = { name };
const options = {
method: "post",
url: "/files/tags",
data,
};
return request(options).then((res) => {
return res;
});
}
export function addTagsToRoom(id, tagArray) {
const data = { names: tagArray };
const options = {
method: "put",
url: `/files/rooms/${id}/tags`,
data,
};
return request(options).then((res) => {
return res;
});
}
export function removeTagsFromRoom(id, tagArray) {
const data = { names: tagArray };
const options = {
method: "delete",
url: `/files/rooms/${id}/tags`,
data,
};
return request(options).then((res) => {
return res;
});
}
export function getTags() {
const options = {
method: "get",
url: "/files/tags",
};
return request(options).then((res) => {
return res;
});
}
export function uploadRoomLogo(data) {
const options = {
method: "post",
url: `/files/logos`,
data,
};
return request(options).then((res) => {
return res;
});
}
export function addLogoToRoom(id, data) {
const options = {
method: "post",
url: `/files/rooms/${id}/logo`,
data,
};
return request(options).then((res) => {
return res;
});
}
export function removeLogoFromRoom(id) {
const options = {
method: "delete",
url: `/files/rooms/${id}/logo`,
};
return request(options).then((res) => {
return res;
});
}