* Rebases and addresses PR feedback * Rebased and addresses PR feedback * Checks group constraint in action instead * Update method docs, parallel promises * Parallel promises, method docs * Cleans up method docs * Method docs cleanup * Update app/database/operator/server_data_operator/handlers/group.ts Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
57 lines
2.2 KiB
TypeScript
57 lines
2.2 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import {Database, Q} from '@nozbe/watermelondb';
|
|
|
|
import {MM_TABLES} from '@constants/database';
|
|
|
|
import type GroupModel from '@typings/database/models/servers/group';
|
|
import type GroupChannelModel from '@typings/database/models/servers/group_channel';
|
|
import type GroupMembershipModel from '@typings/database/models/servers/group_membership';
|
|
import type GroupTeamModel from '@typings/database/models/servers/group_team';
|
|
|
|
const {SERVER: {GROUP, GROUP_CHANNEL, GROUP_MEMBERSHIP, GROUP_TEAM}} = MM_TABLES;
|
|
|
|
export const queryGroupsByName = (database: Database, name: string) => {
|
|
return database.collections.get<GroupModel>(GROUP).query(
|
|
Q.where('name', Q.like(`%${Q.sanitizeLikeString(name)}%`)),
|
|
);
|
|
};
|
|
|
|
export const queryGroupsByNames = (database: Database, names: string[]) => {
|
|
return database.collections.get<GroupModel>(GROUP).query(
|
|
Q.where('name', Q.oneOf(names)),
|
|
);
|
|
};
|
|
|
|
export const queryGroupsByNameInTeam = (database: Database, name: string, teamId: string) => {
|
|
return database.collections.get<GroupModel>(GROUP).query(
|
|
Q.on(GROUP_TEAM, 'team_id', teamId),
|
|
Q.where('name', Q.like(`%${Q.sanitizeLikeString(name)}%`)),
|
|
);
|
|
};
|
|
|
|
export const queryGroupsByNameInChannel = (database: Database, name: string, channelId: string) => {
|
|
return database.collections.get<GroupModel>(GROUP).query(
|
|
Q.on(GROUP_CHANNEL, 'channel_id', channelId),
|
|
Q.where('name', Q.like(`%${Q.sanitizeLikeString(name)}%`)),
|
|
);
|
|
};
|
|
|
|
export const queryGroupChannelForChannel = (database: Database, channelId: string) => {
|
|
return database.collections.get<GroupChannelModel>(GROUP_CHANNEL).query(
|
|
Q.where('channel_id', channelId),
|
|
);
|
|
};
|
|
|
|
export const queryGroupMembershipForMember = (database: Database, userId: string) => {
|
|
return database.collections.get<GroupMembershipModel>(GROUP_MEMBERSHIP).query(
|
|
Q.where('user_id', userId),
|
|
);
|
|
};
|
|
|
|
export const queryGroupTeamForTeam = (database: Database, teamId: string) => {
|
|
return database.collections.get<GroupTeamModel>(GROUP_TEAM).query(
|
|
Q.where('team_id', teamId),
|
|
);
|
|
};
|