mirror of
https://github.com/aykhans/slash-e.git
synced 2025-07-07 13:42:34 +00:00
chore: update frontend modules
This commit is contained in:
@ -1,6 +1,5 @@
|
||||
import globalService from "./globalService";
|
||||
import shortcutService from "./shortcutService";
|
||||
import userService from "./userService";
|
||||
import workspaceService from "./workspaceService";
|
||||
|
||||
export { globalService, shortcutService, userService, workspaceService };
|
||||
export { globalService, shortcutService, userService };
|
||||
|
@ -15,12 +15,8 @@ const shortcutService = {
|
||||
return store.getState().shortcut;
|
||||
},
|
||||
|
||||
fetchWorkspaceShortcuts: async (workspaceId: WorkspaceId) => {
|
||||
const { data } = (
|
||||
await api.getShortcutList({
|
||||
workspaceId,
|
||||
})
|
||||
).data;
|
||||
fetchWorkspaceShortcuts: async () => {
|
||||
const { data } = (await api.getShortcutList({})).data;
|
||||
const shortcuts = data.map((s) => convertResponseModelShortcut(s));
|
||||
store.dispatch(setShortcuts(shortcuts));
|
||||
return shortcuts;
|
||||
|
@ -1,91 +0,0 @@
|
||||
import * as api from "../helpers/api";
|
||||
import store from "../store";
|
||||
import { createWorkspace, deleteWorkspace, patchWorkspace, setWorkspaceById, setWorkspaceList } from "../store/modules/workspace";
|
||||
|
||||
const convertResponseModelWorkspace = (workspace: Workspace): Workspace => {
|
||||
return {
|
||||
...workspace,
|
||||
createdTs: workspace.createdTs * 1000,
|
||||
updatedTs: workspace.updatedTs * 1000,
|
||||
};
|
||||
};
|
||||
|
||||
const workspaceService = {
|
||||
getState: () => {
|
||||
return store.getState().workspace;
|
||||
},
|
||||
|
||||
fetchWorkspaceList: async () => {
|
||||
const { data } = (await api.getWorkspaceList()).data;
|
||||
const workspaces = data.map((w) => convertResponseModelWorkspace(w));
|
||||
store.dispatch(setWorkspaceList(workspaces));
|
||||
return workspaces;
|
||||
},
|
||||
|
||||
fetchWorkspaceById: async (workspaceId: WorkspaceId) => {
|
||||
const { data } = (await api.getWorkspaceById(workspaceId)).data;
|
||||
const workspace = convertResponseModelWorkspace(data);
|
||||
store.dispatch(setWorkspaceById(workspace));
|
||||
return workspace;
|
||||
},
|
||||
|
||||
getWorkspaceByName: (workspaceName: string) => {
|
||||
const workspaceList = workspaceService.getState().workspaceList;
|
||||
for (const workspace of workspaceList) {
|
||||
if (workspace.name === workspaceName) {
|
||||
return workspace;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
},
|
||||
|
||||
getWorkspaceById: (id: WorkspaceId) => {
|
||||
const workspaceList = workspaceService.getState().workspaceList;
|
||||
for (const workspace of workspaceList) {
|
||||
if (workspace.id === id) {
|
||||
return workspace;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
},
|
||||
|
||||
createWorkspace: async (create: WorkspaceCreate) => {
|
||||
const { data } = (await api.createWorkspace(create)).data;
|
||||
const workspace = convertResponseModelWorkspace(data);
|
||||
store.dispatch(createWorkspace(workspace));
|
||||
return workspace;
|
||||
},
|
||||
|
||||
patchWorkspace: async (patch: WorkspacePatch) => {
|
||||
const { data } = (await api.patchWorkspace(patch)).data;
|
||||
const workspace = convertResponseModelWorkspace(data);
|
||||
store.dispatch(patchWorkspace(workspace));
|
||||
return workspace;
|
||||
},
|
||||
|
||||
deleteWorkspaceById: async (id: WorkspaceId) => {
|
||||
await api.deleteWorkspaceById(id);
|
||||
store.dispatch(deleteWorkspace(id));
|
||||
},
|
||||
|
||||
getWorkspaceUserList: async (id: WorkspaceId) => {
|
||||
const { data } = (
|
||||
await api.getWorkspaceUserList({
|
||||
workspaceId: id,
|
||||
})
|
||||
).data;
|
||||
return data;
|
||||
},
|
||||
|
||||
getWorkspaceUser: async (workspaceId: WorkspaceId, userId: UserId) => {
|
||||
const { data } = (
|
||||
await api.getWorkspaceUser({
|
||||
workspaceId: workspaceId,
|
||||
userId: userId,
|
||||
})
|
||||
).data;
|
||||
return data;
|
||||
},
|
||||
};
|
||||
|
||||
export default workspaceService;
|
Reference in New Issue
Block a user