mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-05 06:28:51 +00:00
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:
1 parent
6e9c3e6d1a
commit
258ea66746
2 files changed
+3
-14
No files matched your search
@@ -35,7 +35,7 @@ export async function getIdentifierByPhoneNumber(
|
|||||||
}
|
}
|
||||||
// Whether we fetch from database if not found in online players
|
// Whether we fetch from database if not found in online players
|
||||||
if (fetch) {
|
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]);
|
const [results] = await pool.query(query, [phoneNumber]);
|
||||||
// Get identifier from results
|
// Get identifier from results
|
||||||
return (results as { identifier: string }[])[0].identifier;
|
return (results as { identifier: string }[])[0].identifier;
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import {
|
|||||||
import { pool, withTransaction } from './db';
|
import { pool, withTransaction } from './db';
|
||||||
import { getIdentifier, getSource, getPlayerFromIdentifier } from './functions';
|
import { getIdentifier, getSource, getPlayerFromIdentifier } from './functions';
|
||||||
import { mainLogger } from './sv_logger';
|
import { mainLogger } from './sv_logger';
|
||||||
import { group } from 'console';
|
import { getIdentifierByPhoneNumber } from './functions';
|
||||||
|
|
||||||
const messageLogger = mainLogger.child({ module: 'messages' });
|
const messageLogger = mainLogger.child({ module: 'messages' });
|
||||||
|
|
||||||
@@ -183,17 +183,6 @@ async function createMessageGroup(
|
|||||||
* Find a players identifier from their phone number
|
* Find a players identifier from their phone number
|
||||||
* @param phoneNumber - the phone number to search for
|
* @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
|
* 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
|
// we check that each phoneNumber exists before we create the group
|
||||||
const identifiers: string[] = [];
|
const identifiers: string[] = [];
|
||||||
for (const phoneNumber of phoneNumbers) {
|
for (const phoneNumber of phoneNumbers) {
|
||||||
const identifier = await getIdentifierFromPhoneNumber(phoneNumber);
|
const identifier = await getIdentifierByPhoneNumber(phoneNumber, true);
|
||||||
identifiers.push(identifier);
|
identifiers.push(identifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user