* WIP * Actions updated to fetch remote first, and local on error * Groups fetch and save * PR Feedback: prepare vs store and undefined fix * Forgot to add file * Groups Mention WIP * Groups highlight! * Merge, PR Feedback * PR Feedback * PR Feedback: Try/Catch blocks * PR Feedback * Rebased with PR feedback * Exclusion fix, plus id order * Tidies up iterations * Loops updated * Update app/database/operator/server_data_operator/handlers/group.ts Co-authored-by: Avinash Lingaloo <avinashlng1080@gmail.com> * PR Feedback: Remove unnecessary prepare/store methods * Newline ESLint error * Extracts out id generation for group-associations * Batches if not fetchOnly Co-authored-by: Avinash Lingaloo <avinashlng1080@gmail.com>
69 lines
3.4 KiB
TypeScript
69 lines
3.4 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import {buildQueryString} from '@utils/helpers';
|
|
|
|
import {PER_PAGE_DEFAULT} from './constants';
|
|
|
|
export interface ClientGroupsMix {
|
|
getGroups: (query?: string, filterAllowReference?: boolean, page?: number, perPage?: number, since?: number) => Promise<Group[]>;
|
|
getAllGroupsAssociatedToChannel: (channelId: string, filterAllowReference?: boolean) => Promise<{groups: Group[]; total_group_count: number}>;
|
|
getAllGroupsAssociatedToMembership: (userId: string, filterAllowReference?: boolean) => Promise<Group[]>;
|
|
getAllGroupsAssociatedToTeam: (teamId: string, filterAllowReference?: boolean) => Promise<{groups: Group[]; total_group_count: number}>;
|
|
getAllChannelsAssociatedToGroup: (groupId: string, filterAllowReference?: boolean) => Promise<{groupChannels: GroupChannel[]}>;
|
|
getAllMembershipsAssociatedToGroup: (groupId: string, filterAllowReference?: boolean) => Promise<{groupMemberships: UserProfile[]; total_member_count: number}>;
|
|
getAllTeamsAssociatedToGroup: (groupId: string, filterAllowReference?: boolean) => Promise<{groupTeams: GroupTeam[]}>;
|
|
}
|
|
|
|
const ClientGroups = (superclass: any) => class extends superclass {
|
|
getGroups = async (query = '', filterAllowReference = true, page = 0, perPage = PER_PAGE_DEFAULT, since = 0) => {
|
|
return this.doFetch(
|
|
`${this.urlVersion}/groups${buildQueryString({q: query, filter_allow_reference: filterAllowReference, page, per_page: perPage, since})}`,
|
|
{method: 'get'},
|
|
);
|
|
};
|
|
|
|
getAllGroupsAssociatedToChannel = async (channelId: string, filterAllowReference = false) => {
|
|
return this.doFetch(
|
|
`${this.urlVersion}/channels/${channelId}/groups${buildQueryString({paginate: false, filter_allow_reference: filterAllowReference})}`,
|
|
{method: 'get'},
|
|
);
|
|
};
|
|
|
|
getAllGroupsAssociatedToTeam = async (teamId: string, filterAllowReference = false) => {
|
|
return this.doFetch(
|
|
`${this.urlVersion}/teams/${teamId}/groups${buildQueryString({paginate: false, filter_allow_reference: filterAllowReference})}`,
|
|
{method: 'get'},
|
|
);
|
|
};
|
|
|
|
getAllGroupsAssociatedToMembership = async (userId: string, filterAllowReference = false) => {
|
|
return this.doFetch(
|
|
`${this.urlVersion}/users/${userId}/groups${buildQueryString({paginate: false, filter_allow_reference: filterAllowReference})}`,
|
|
{method: 'get'},
|
|
);
|
|
};
|
|
|
|
getAllTeamsAssociatedToGroup = async (groupId: string, filterAllowReference = false) => {
|
|
return this.doFetch(
|
|
`${this.urlVersion}/groups/${groupId}/teams${buildQueryString({filter_allow_reference: filterAllowReference})}`,
|
|
{method: 'get'},
|
|
);
|
|
};
|
|
|
|
getAllChannelsAssociatedToGroup = async (groupId: string, filterAllowReference = false) => {
|
|
return this.doFetch(
|
|
`${this.urlVersion}/groups/${groupId}/channels${buildQueryString({filter_allow_reference: filterAllowReference})}`,
|
|
{method: 'get'},
|
|
);
|
|
};
|
|
|
|
getAllMembershipsAssociatedToGroup = async (groupId: string, filterAllowReference = false) => {
|
|
return this.doFetch(
|
|
`${this.urlVersion}/groups/${groupId}/members${buildQueryString({filter_allow_reference: filterAllowReference})}`,
|
|
{method: 'get'},
|
|
);
|
|
};
|
|
};
|
|
|
|
export default ClientGroups;
|