35 lines
1.2 KiB
JavaScript
35 lines
1.2 KiB
JavaScript
import { PAIR as MSSQL_PAIR } from '../../providers/mssql/queries/posterminal.js';
|
|
import { PAIR as SQLITE_PAIR } from '../../providers/sqlite3/queries/posterminal.js';
|
|
import makeRunner from '../runner.js';
|
|
|
|
export default function pair(provider) {
|
|
const sql = provider?.dialect === 'sqlite3' ? SQLITE_PAIR : MSSQL_PAIR;
|
|
|
|
/**
|
|
* Completes POS device pairing for a terminal.
|
|
*
|
|
* @param {number} id - The posterminal id.
|
|
* @param {object} input
|
|
* @param {string} input.token - The auth token for the paired device.
|
|
* @param {string} [input.clientserial] - The client name or serial identifier.
|
|
* @param {string} [input.pairedAt] - Timestamp when paired.
|
|
* @param {object} [tx] - Optional transaction to run within.
|
|
* @returns {Promise<{id: number, token: string, clientserial: string|null, pairedAt: string|null}>}
|
|
*/
|
|
return async (id, { token, clientserial, pairedAt }, tx) => {
|
|
await makeRunner(provider, tx).query(sql, {
|
|
id,
|
|
token,
|
|
clientserial: clientserial ?? null,
|
|
pairedAt: pairedAt ?? null,
|
|
});
|
|
|
|
return {
|
|
id,
|
|
token,
|
|
clientserial: clientserial ?? null,
|
|
pairedAt: pairedAt ?? null,
|
|
};
|
|
};
|
|
}
|