forked from Ivasoft/mattermost-mobile
MM-42787 - Gekidou User DB field remote_id (#6094)
* added remote_id to user table schema * update user model to accomodate for remote_id field * transform - reaction - split into its own file * update user transformer * update isShared function * Fix typescript * make remote_id field optional Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
|
||||
import {MM_TABLES} from '@constants/database';
|
||||
import DataOperatorException from '@database/exceptions/data_operator_exception';
|
||||
import {transformReactionRecord} from '@database/operator/server_data_operator/transformers/user';
|
||||
import {transformReactionRecord} from '@database/operator/server_data_operator/transformers/reaction';
|
||||
import {sanitizeReactions} from '@database/operator/utils/reaction';
|
||||
|
||||
import type {HandleReactionsArgs} from '@typings/database/database';
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import {transformReactionRecord} from '@database/operator/server_data_operator/transformers/reaction';
|
||||
import {createTestConnection} from '@database/operator/utils/create_test_connection';
|
||||
import {OperationType} from '@typings/database/enums';
|
||||
|
||||
describe('*** REACTION Prepare Records Test ***', () => {
|
||||
it('=> transformReactionRecord: should return an array of type Reaction', async () => {
|
||||
expect.assertions(3);
|
||||
|
||||
const database = await createTestConnection({databaseName: 'reaction_prepare_records', setActive: true});
|
||||
expect(database).toBeTruthy();
|
||||
|
||||
const preparedRecords = await transformReactionRecord({
|
||||
action: OperationType.CREATE,
|
||||
database: database!,
|
||||
value: {
|
||||
record: undefined,
|
||||
raw: {
|
||||
id: 'ps81iqbddesfby8jayz7owg4yypoo',
|
||||
user_id: 'q3mzxua9zjfczqakxdkowc6u6yy',
|
||||
post_id: 'ps81iqbddesfby8jayz7owg4yypoo',
|
||||
emoji_name: 'thumbsup',
|
||||
create_at: 1596032651748,
|
||||
update_at: 1608253011321,
|
||||
delete_at: 0,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
expect(preparedRecords).toBeTruthy();
|
||||
expect(preparedRecords!.collection.modelClass.name).toBe('ReactionModel');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,41 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import {MM_TABLES} from '@constants/database';
|
||||
import {prepareBaseRecord} from '@database/operator/server_data_operator/transformers/index';
|
||||
import {OperationType} from '@typings/database/enums';
|
||||
|
||||
import type {TransformerArgs} from '@typings/database/database';
|
||||
import type ReactionModel from '@typings/database/models/servers/reaction';
|
||||
|
||||
const {REACTION} = MM_TABLES.SERVER;
|
||||
|
||||
/**
|
||||
* transformReactionRecord: Prepares a record of the SERVER database 'Reaction' table for update or create actions.
|
||||
* @param {TransformerArgs} operator
|
||||
* @param {Database} operator.database
|
||||
* @param {RecordPair} operator.value
|
||||
* @returns {Promise<ReactionModel>}
|
||||
*/
|
||||
export const transformReactionRecord = ({action, database, value}: TransformerArgs): Promise<ReactionModel> => {
|
||||
const raw = value.raw as Reaction;
|
||||
const record = value.record as ReactionModel;
|
||||
const isCreateAction = action === OperationType.CREATE;
|
||||
|
||||
// id of reaction comes from server response
|
||||
const fieldsMapper = (reaction: ReactionModel) => {
|
||||
reaction._raw.id = isCreateAction ? (raw?.id ?? reaction.id) : record.id;
|
||||
reaction.userId = raw.user_id;
|
||||
reaction.postId = raw.post_id;
|
||||
reaction.emojiName = raw.emoji_name;
|
||||
reaction.createAt = raw.create_at;
|
||||
};
|
||||
|
||||
return prepareBaseRecord({
|
||||
action,
|
||||
database,
|
||||
tableName: REACTION,
|
||||
value,
|
||||
fieldsMapper,
|
||||
}) as Promise<ReactionModel>;
|
||||
};
|
||||
@@ -1,11 +1,7 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import {
|
||||
transformPreferenceRecord,
|
||||
transformReactionRecord,
|
||||
transformUserRecord,
|
||||
} from '@database/operator/server_data_operator/transformers/user';
|
||||
import {transformPreferenceRecord, transformUserRecord} from '@database/operator/server_data_operator/transformers/user';
|
||||
import {createTestConnection} from '@database/operator/utils/create_test_connection';
|
||||
import {OperationType} from '@typings/database/enums';
|
||||
|
||||
@@ -29,33 +25,6 @@ describe('*** USER Prepare Records Test ***', () => {
|
||||
expect(preparedRecords!.collection.modelClass.name).toBe('PreferenceModel');
|
||||
});
|
||||
|
||||
it('=> transformReactionRecord: should return an array of type Reaction', async () => {
|
||||
expect.assertions(3);
|
||||
|
||||
const database = await createTestConnection({databaseName: 'user_prepare_records', setActive: true});
|
||||
expect(database).toBeTruthy();
|
||||
|
||||
const preparedRecords = await transformReactionRecord({
|
||||
action: OperationType.CREATE,
|
||||
database: database!,
|
||||
value: {
|
||||
record: undefined,
|
||||
raw: {
|
||||
id: 'ps81iqbddesfby8jayz7owg4yypoo',
|
||||
user_id: 'q3mzxua9zjfczqakxdkowc6u6yy',
|
||||
post_id: 'ps81iqbddesfby8jayz7owg4yypoo',
|
||||
emoji_name: 'thumbsup',
|
||||
create_at: 1596032651748,
|
||||
update_at: 1608253011321,
|
||||
delete_at: 0,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
expect(preparedRecords).toBeTruthy();
|
||||
expect(preparedRecords!.collection.modelClass.name).toBe('ReactionModel');
|
||||
});
|
||||
|
||||
it('=> transformUserRecord: should return an array of type User', async () => {
|
||||
expect.assertions(3);
|
||||
|
||||
|
||||
@@ -7,44 +7,9 @@ import {OperationType} from '@typings/database/enums';
|
||||
|
||||
import type {TransformerArgs} from '@typings/database/database';
|
||||
import type PreferenceModel from '@typings/database/models/servers/preference';
|
||||
import type ReactionModel from '@typings/database/models/servers/reaction';
|
||||
import type UserModel from '@typings/database/models/servers/user';
|
||||
|
||||
const {
|
||||
PREFERENCE,
|
||||
REACTION,
|
||||
USER,
|
||||
} = MM_TABLES.SERVER;
|
||||
|
||||
/**
|
||||
* transformReactionRecord: Prepares a record of the SERVER database 'Reaction' table for update or create actions.
|
||||
* @param {TransformerArgs} operator
|
||||
* @param {Database} operator.database
|
||||
* @param {RecordPair} operator.value
|
||||
* @returns {Promise<ReactionModel>}
|
||||
*/
|
||||
export const transformReactionRecord = ({action, database, value}: TransformerArgs): Promise<ReactionModel> => {
|
||||
const raw = value.raw as Reaction;
|
||||
const record = value.record as ReactionModel;
|
||||
const isCreateAction = action === OperationType.CREATE;
|
||||
|
||||
// id of reaction comes from server response
|
||||
const fieldsMapper = (reaction: ReactionModel) => {
|
||||
reaction._raw.id = isCreateAction ? (raw?.id ?? reaction.id) : record.id;
|
||||
reaction.userId = raw.user_id;
|
||||
reaction.postId = raw.post_id;
|
||||
reaction.emojiName = raw.emoji_name;
|
||||
reaction.createAt = raw.create_at;
|
||||
};
|
||||
|
||||
return prepareBaseRecord({
|
||||
action,
|
||||
database,
|
||||
tableName: REACTION,
|
||||
value,
|
||||
fieldsMapper,
|
||||
}) as Promise<ReactionModel>;
|
||||
};
|
||||
const {PREFERENCE, USER} = MM_TABLES.SERVER;
|
||||
|
||||
/**
|
||||
* transformUserRecord: Prepares a record of the SERVER database 'User' table for update or create actions.
|
||||
@@ -78,6 +43,7 @@ export const transformUserRecord = ({action, database, value}: TransformerArgs):
|
||||
user.props = raw.props || null;
|
||||
user.timezone = raw.timezone || null;
|
||||
user.isBot = raw.is_bot;
|
||||
user.remoteId = raw?.remote_id ?? '';
|
||||
if (raw.status) {
|
||||
user.status = raw.status;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user