2022-10-22 11:51:07 -08:00
|
|
|
import { BaseCRUDAPI } from "../base/base-clients";
|
2025-06-20 00:09:12 +07:00
|
|
|
import type { PaginationData } from "../types/non-generated";
|
|
|
|
import type { QueryValue } from "../base/route";
|
|
|
|
import type { GroupBase, GroupInDB, GroupSummary, UserSummary } from "~/lib/api/types/user";
|
|
|
|
import type {
|
2022-10-22 11:51:07 -08:00
|
|
|
GroupAdminUpdate,
|
|
|
|
GroupStorage,
|
|
|
|
ReadGroupPreferences,
|
|
|
|
UpdateGroupPreferences,
|
|
|
|
} from "~/lib/api/types/group";
|
2021-08-06 16:28:12 -08:00
|
|
|
|
|
|
|
const prefix = "/api";
|
|
|
|
|
|
|
|
const routes = {
|
2021-09-09 08:51:29 -08:00
|
|
|
groups: `${prefix}/admin/groups`,
|
2021-08-06 16:28:12 -08:00
|
|
|
groupsSelf: `${prefix}/groups/self`,
|
2021-09-05 22:05:29 -08:00
|
|
|
preferences: `${prefix}/groups/preferences`,
|
2022-03-27 15:12:18 -08:00
|
|
|
storage: `${prefix}/groups/storage`,
|
2024-10-11 19:36:26 -05:00
|
|
|
members: `${prefix}/groups/members`,
|
2021-09-09 08:51:29 -08:00
|
|
|
groupsId: (id: string | number) => `${prefix}/admin/groups/${id}`,
|
2021-08-06 16:28:12 -08:00
|
|
|
};
|
|
|
|
|
2022-05-21 21:22:02 +02:00
|
|
|
export class GroupAPI extends BaseCRUDAPI<GroupBase, GroupInDB, GroupAdminUpdate> {
|
2021-08-06 16:28:12 -08:00
|
|
|
baseRoute = routes.groups;
|
|
|
|
itemRoute = routes.groupsId;
|
|
|
|
/** Returns the Group Data for the Current User
|
|
|
|
*/
|
|
|
|
async getCurrentUserGroup() {
|
2024-03-15 19:50:39 +00:00
|
|
|
return await this.requests.get<GroupSummary>(routes.groupsSelf);
|
2021-09-01 21:39:40 -08:00
|
|
|
}
|
|
|
|
|
2021-09-05 22:05:29 -08:00
|
|
|
async getPreferences() {
|
2022-05-21 21:22:02 +02:00
|
|
|
return await this.requests.get<ReadGroupPreferences>(routes.preferences);
|
2021-09-05 22:05:29 -08:00
|
|
|
}
|
|
|
|
|
2022-05-21 21:22:02 +02:00
|
|
|
async setPreferences(payload: UpdateGroupPreferences) {
|
2022-01-09 07:15:23 +01:00
|
|
|
// TODO: This should probably be a patch request, which isn't offered by the API currently
|
2022-05-21 21:22:02 +02:00
|
|
|
return await this.requests.put<ReadGroupPreferences, UpdateGroupPreferences>(routes.preferences, payload);
|
2021-09-05 22:05:29 -08:00
|
|
|
}
|
2021-09-09 08:51:29 -08:00
|
|
|
|
2024-10-11 19:36:26 -05:00
|
|
|
async fetchMembers(page = 1, perPage = -1, params = {} as Record<string, QueryValue>) {
|
|
|
|
return await this.requests.get<PaginationData<UserSummary>>(routes.members, { page, perPage, ...params });
|
2021-10-04 20:16:37 -08:00
|
|
|
}
|
2022-03-27 15:12:18 -08:00
|
|
|
|
|
|
|
async storage() {
|
|
|
|
return await this.requests.get<GroupStorage>(routes.storage);
|
|
|
|
}
|
2021-08-06 16:28:12 -08:00
|
|
|
}
|