Revert "tweak(server/player): Added regex replace to getIdentifierByPhoneNumber"

Reverted as to ensure current compatibility with messages app, messages
should be altered to deal with this in the future.

This reverts commit 258ea66746.
This commit is contained in:
Taso committed 2021-03-10 21:27:21 -05:00
1 parent 1801255c04
commit 7fd02913da
2 files changed
+14 -3

No files matched your search

+1 -1
View File
@@ -35,7 +35,7 @@ export async function getIdentifierByPhoneNumber(
}
// Whether we fetch from database if not found in online players
if (fetch) {
const query = `SELECT identifier FROM users WHERE phone_number = ?`
const query = `SELECT identifier FROM users WHERE phone_number = ?`;
const [results] = await pool.query(query, [phoneNumber]);
// Get identifier from results
return (results as { identifier: string }[])[0].identifier;
+13 -2
View File
@@ -9,7 +9,7 @@ import {
import { pool, withTransaction } from './db';
import { getIdentifier, getSource, getPlayerFromIdentifier } from './functions';
import { mainLogger } from './sv_logger';
import { getIdentifierByPhoneNumber } from './functions';
import { group } from 'console';
const messageLogger = mainLogger.child({ module: 'messages' });
@@ -183,6 +183,17 @@ async function createMessageGroup(
* Find a players identifier from their phone number
* @param phoneNumber - the phone number to search for
*/
async function getIdentifierFromPhoneNumber(phoneNumber: string): Promise<string> {
const query = `
SELECT identifier
FROM users
WHERE REGEXP_REPLACE(phone_number, '[^0-9]', '') = ?
LIMIT 1
`;
const [results] = await pool.query(query, [phoneNumber]);
const identifiers = <any>results;
return identifiers[0]['identifier'];
}
/**
* This method checks if the input groupId already exists in
@@ -326,7 +337,7 @@ async function createMessageGroupsFromPhoneNumbers(
// we check that each phoneNumber exists before we create the group
const identifiers: string[] = [];
for (const phoneNumber of phoneNumbers) {
const identifier = await getIdentifierByPhoneNumber(phoneNumber, true);
const identifier = await getIdentifierFromPhoneNumber(phoneNumber);
identifiers.push(identifier);
}