This commit is contained in:
seb
2026-09-29 11:21:57 +02:00
parent 5d2c8fdfed
commit 7bb674d5e7
10 changed files with 123 additions and 7 deletions

View File

@@ -0,0 +1,22 @@
import { FIND_BY_PAIRINGPIN as MSSQL_FIND } from '../../providers/mssql/queries/posterminal.js';
import { FIND_BY_PAIRINGPIN as SQLITE_FIND } from '../../providers/sqlite3/queries/posterminal.js';
import makeRunner from '../runner.js';
export default function findByPairingpin(provider) {
const sql = provider?.dialect === 'sqlite3' ? SQLITE_FIND : MSSQL_FIND;
/**
* Finds a posterminal by its pairingpin.
*
* @param {string} pairingpin - The pairing pin 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 (pairingpin, tx) => {
if (!pairingpin) return null;
const result = await makeRunner(provider, tx).query(sql, {
pairingpin: String(pairingpin).trim(),
});
return result.rows[0] || null;
};
}

View File

@@ -0,0 +1,34 @@
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,
};
};
}

View File

@@ -47,6 +47,8 @@ export default function upsert(provider) {
}
const token = input.token ?? null;
const id = input.id ?? null;
const pairedAt = input.pairedAt ?? null;
const clientserial = input.clientserial ?? null;
const runner = makeRunner(provider, tx);
const { companyId } = await access(googleAuthId, tx);
@@ -64,9 +66,11 @@ export default function upsert(provider) {
name,
token,
pairingpin,
pairedAt,
clientserial,
});
return { id, name, token, pairingpin };
return { id, name, token, pairingpin, pairedAt, clientserial };
}
const created = await runner.query(createSql, {
@@ -74,6 +78,8 @@ export default function upsert(provider) {
name,
token,
pairingpin,
pairedAt,
clientserial,
});
const row = created.rows[0] ?? {
@@ -81,6 +87,8 @@ export default function upsert(provider) {
name,
token,
pairingpin,
pairedAt,
clientserial,
};
return {
@@ -88,6 +96,8 @@ export default function upsert(provider) {
name: row.name,
token: row.token,
pairingpin: row.pairingpin,
pairedAt: row.pairedAt ?? null,
clientserial: row.clientserial ?? null,
};
};
}