u
This commit is contained in:
23
src/store/posterminal/findByToken.js
Normal file
23
src/store/posterminal/findByToken.js
Normal file
@@ -0,0 +1,23 @@
|
||||
import { FIND_BY_TOKEN as MSSQL_FIND } from '../../providers/mssql/queries/posterminal.js';
|
||||
import { FIND_BY_TOKEN as SQLITE_FIND } from '../../providers/sqlite3/queries/posterminal.js';
|
||||
import makeRunner from '../runner.js';
|
||||
|
||||
export default function findByToken(provider) {
|
||||
const sql = provider?.dialect === 'sqlite3' ? SQLITE_FIND : MSSQL_FIND;
|
||||
|
||||
/**
|
||||
* Finds a posterminal by its auth token.
|
||||
*
|
||||
* @param {string} token - The auth token to search for.
|
||||
* @param {object} [tx] - Optional transaction to run within.
|
||||
* @returns {Promise<object|null>} The posterminal row, or null if not found.
|
||||
*/
|
||||
return async (token, tx) => {
|
||||
const trimmed = String(token ?? '').trim();
|
||||
if (!trimmed) return null;
|
||||
const result = await makeRunner(provider, tx).query(sql, {
|
||||
token: trimmed,
|
||||
});
|
||||
return result.rows[0] || null;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user