This commit is contained in:
seb
2026-10-30 12:08:08 +01:00
parent e82ea15d02
commit fbe3105dc9
2 changed files with 36 additions and 2 deletions

View File

@@ -69,6 +69,13 @@ export function buildClientStep2(authCode, config) {
* security: []
* x-markdown: pos/client.md
* parameters:
* - in: header
* name: version
* required: false
* schema:
* type: string
* description: POS client software version (e.g. 2.0.0.5)
* example: "2.0.0.5"
* - in: query
* name: authCode
* required: true
@@ -167,13 +174,14 @@ export async function handleClient(req, res) {
const token = terminal.token;
const strToken = String(token || crypto.randomBytes(16).toString('hex')).trim();
const pairedAt = serverTimestamp();
const clientversion = req.query.clientversion || req.query.version || req.query.clientVersion || null;
const rawVersion = req.headers.version || req.headers.clientversion || req.query.clientversion || req.query.version || req.query.clientVersion || null;
const clientversion = rawVersion ? String(rawVersion).trim() : null;
await db.pair(terminal.id, {
token: strToken,
clientserial: name,
pairedAt,
clientversion: clientversion ? String(clientversion).trim() : null,
clientversion,
});
if (terminal.companyId) {

View File

@@ -1,4 +1,5 @@
import * as db from '../../db/posterminal.js';
import { emit } from '../../api/sse.js';
/**
* @openapi
@@ -19,6 +20,13 @@ import * as db from '../../db/posterminal.js';
* type: string
* description: POS device authToken obtained during pairing (`Bearer <token>` or `<token>`)
* example: "Bearer c30099b66ec1fcb9ccd05795423c94e8"
* - in: header
* name: version
* required: false
* schema:
* type: string
* description: POS client software version reported by the device
* example: "2.0.0.5"
* - in: query
* name: lastChangedProduct
* required: false
@@ -121,6 +129,23 @@ import * as db from '../../db/posterminal.js';
export async function handleInit(req, res) {
const posterminalId = req.posterminal.id;
const rawVersion = req.headers.version || req.headers.clientversion;
const incomingVersion = rawVersion ? String(rawVersion).trim() : '';
const currentVersion = req.posterminal.clientversion ? String(req.posterminal.clientversion).trim() : '';
const updateVersionPromise = (incomingVersion && incomingVersion !== currentVersion)
? db.setClientversion(posterminalId, incomingVersion)
.then(() => {
req.posterminal.clientversion = incomingVersion;
if (req.posterminal.companyId) {
emit('posterminal', { companyId: req.posterminal.companyId });
}
})
.catch((err) => {
console.error(`Failed to update posterminal ${posterminalId} version:`, err);
})
: null;
const productCursor = Number(req.query.lastChangedProduct) || 0;
const categoryCursor = Number(req.query.lastChangedCategory) || 0;
const customerCursor = Number(req.query.lastChangedCustomer) || 0;
@@ -145,6 +170,7 @@ export async function handleInit(req, res) {
db.getCompositeProductCount({ posterminalId, cursor: compositeProductCursor }),
db.getDeletedEntityCount({ posterminalId, cursor: deletedEntityCursor }),
db.getMaxOrderIdCount({ posterminalId }),
updateVersionPromise,
]);
return res.status(200).json({