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

Added a regex replace to match the old signature for this function. Also
migrated messages to use the new util function rather than a locally
defined query
This commit is contained in:
Taso committed 2021-03-08 20:35:25 -05:00
1 parent 6e9c3e6d1a
commit 258ea66746
2 files changed
+3 -14

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 REGEXP_REPLACE(phone_number, '[^0-9]', '') = ? `;
const [results] = await pool.query(query, [phoneNumber]);
// Get identifier from results
return (results as { identifier: string }[])[0].identifier;
+2 -13
View File
@@ -9,7 +9,7 @@ import {
import { pool, withTransaction } from './db';
import { getIdentifier, getSource, getPlayerFromIdentifier } from './functions';
import { mainLogger } from './sv_logger';
import { group } from 'console';
import { getIdentifierByPhoneNumber } from './functions';
const messageLogger = mainLogger.child({ module: 'messages' });
@@ -183,17 +183,6 @@ 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
@@ -337,7 +326,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 getIdentifierFromPhoneNumber(phoneNumber);
const identifier = await getIdentifierByPhoneNumber(phoneNumber, true);
identifiers.push(identifier);
}