forked from Ivasoft/mattermost-mobile
* 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
36 lines
1.3 KiB
TypeScript
36 lines
1.3 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 ServerDataOperator from '@database/operator/server_data_operator';
|
|
import type GroupModel from '@typings/database/models/servers/group';
|
|
|
|
const {SERVER: {GROUP, GROUP_CHANNEL, 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 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 prepareGroups = (operator: ServerDataOperator, groups: Group[]) => {
|
|
return operator.handleGroups({groups, prepareRecordsOnly: true});
|
|
};
|