u
This commit is contained in:
@@ -97,6 +97,8 @@ import posterminalSetOff from './store/posterminal/setOff.js';
|
|||||||
import posterminalSetOnAll from './store/posterminal/setOnAll.js';
|
import posterminalSetOnAll from './store/posterminal/setOnAll.js';
|
||||||
import posterminalSetOffAll from './store/posterminal/setOffAll.js';
|
import posterminalSetOffAll from './store/posterminal/setOffAll.js';
|
||||||
import posterminalGetCategoryPosterminalIds from './store/posterminal/getCategoryPosterminalIds.js';
|
import posterminalGetCategoryPosterminalIds from './store/posterminal/getCategoryPosterminalIds.js';
|
||||||
|
import posterminalFindByPairingpin from './store/posterminal/findByPairingpin.js';
|
||||||
|
import posterminalPair from './store/posterminal/pair.js';
|
||||||
import langCreate from './store/lang/create.js';
|
import langCreate from './store/lang/create.js';
|
||||||
import langDelete from './store/lang/delete.js';
|
import langDelete from './store/lang/delete.js';
|
||||||
import langList from './store/lang/list.js';
|
import langList from './store/lang/list.js';
|
||||||
@@ -328,6 +330,8 @@ export default class LibDashStore {
|
|||||||
setOnAll: posterminalSetOnAll(provider),
|
setOnAll: posterminalSetOnAll(provider),
|
||||||
setOffAll: posterminalSetOffAll(provider),
|
setOffAll: posterminalSetOffAll(provider),
|
||||||
getCategoryPosterminalIds: posterminalGetCategoryPosterminalIds(provider),
|
getCategoryPosterminalIds: posterminalGetCategoryPosterminalIds(provider),
|
||||||
|
findByPairingpin: posterminalFindByPairingpin(provider),
|
||||||
|
pair: posterminalPair(provider),
|
||||||
};
|
};
|
||||||
|
|
||||||
this.google_auth = {
|
this.google_auth = {
|
||||||
|
|||||||
@@ -167,6 +167,16 @@ export class MssqlProvider {
|
|||||||
ALTER TABLE ledger ADD warehouse_id INT NULL;
|
ALTER TABLE ledger ADD warehouse_id INT NULL;
|
||||||
ALTER TABLE ledger ADD CONSTRAINT FK_ledger_warehouse FOREIGN KEY (warehouse_id) REFERENCES warehouse(id) ON DELETE NO ACTION;
|
ALTER TABLE ledger ADD CONSTRAINT FK_ledger_warehouse FOREIGN KEY (warehouse_id) REFERENCES warehouse(id) ON DELETE NO ACTION;
|
||||||
END
|
END
|
||||||
|
|
||||||
|
IF OBJECT_ID(N'dbo.posterminal', N'U') IS NOT NULL AND COL_LENGTH('posterminal', 'paired_at') IS NULL
|
||||||
|
BEGIN
|
||||||
|
ALTER TABLE posterminal ADD paired_at DATETIME2 NULL;
|
||||||
|
END
|
||||||
|
|
||||||
|
IF OBJECT_ID(N'dbo.posterminal', N'U') IS NOT NULL AND COL_LENGTH('posterminal', 'clientserial') IS NULL
|
||||||
|
BEGIN
|
||||||
|
ALTER TABLE posterminal ADD clientserial NVARCHAR(255) NULL;
|
||||||
|
END
|
||||||
`);
|
`);
|
||||||
} catch {
|
} catch {
|
||||||
// ignore
|
// ignore
|
||||||
|
|||||||
@@ -3,7 +3,9 @@ SELECT
|
|||||||
id,
|
id,
|
||||||
name,
|
name,
|
||||||
token,
|
token,
|
||||||
pairingpin
|
pairingpin,
|
||||||
|
paired_at AS pairedAt,
|
||||||
|
clientserial AS clientserial
|
||||||
FROM posterminal
|
FROM posterminal
|
||||||
WHERE company_id = @companyId
|
WHERE company_id = @companyId
|
||||||
ORDER BY id
|
ORDER BY id
|
||||||
@@ -15,20 +17,41 @@ SELECT
|
|||||||
company_id AS companyId,
|
company_id AS companyId,
|
||||||
name,
|
name,
|
||||||
token,
|
token,
|
||||||
pairingpin
|
pairingpin,
|
||||||
|
paired_at AS pairedAt,
|
||||||
|
clientserial AS clientserial
|
||||||
FROM posterminal
|
FROM posterminal
|
||||||
WHERE id = @id
|
WHERE id = @id
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
export const FIND_BY_PAIRINGPIN = `
|
||||||
|
SELECT
|
||||||
|
id,
|
||||||
|
company_id AS companyId,
|
||||||
|
name,
|
||||||
|
token,
|
||||||
|
pairingpin,
|
||||||
|
paired_at AS pairedAt,
|
||||||
|
clientserial AS clientserial
|
||||||
|
FROM posterminal
|
||||||
|
WHERE pairingpin = @pairingpin
|
||||||
|
`;
|
||||||
|
|
||||||
|
export const PAIR = `
|
||||||
|
UPDATE posterminal
|
||||||
|
SET token = @token, paired_at = @pairedAt, clientserial = @clientserial, pairingpin = ''
|
||||||
|
WHERE id = @id
|
||||||
|
`;
|
||||||
|
|
||||||
export const CREATE = `
|
export const CREATE = `
|
||||||
INSERT INTO posterminal (company_id, name, token, pairingpin)
|
INSERT INTO posterminal (company_id, name, token, pairingpin, paired_at, clientserial)
|
||||||
OUTPUT INSERTED.id, INSERTED.name, INSERTED.token, INSERTED.pairingpin
|
OUTPUT INSERTED.id, INSERTED.name, INSERTED.token, INSERTED.pairingpin, INSERTED.paired_at AS pairedAt, INSERTED.clientserial AS clientserial
|
||||||
VALUES (@companyId, @name, @token, @pairingpin)
|
VALUES (@companyId, @name, @token, @pairingpin, @pairedAt, @clientserial)
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export const UPDATE = `
|
export const UPDATE = `
|
||||||
UPDATE posterminal
|
UPDATE posterminal
|
||||||
SET name = @name, token = @token, pairingpin = @pairingpin
|
SET name = @name, token = @token, pairingpin = @pairingpin, paired_at = @pairedAt, clientserial = @clientserial
|
||||||
WHERE id = @id AND company_id = @companyId
|
WHERE id = @id AND company_id = @companyId
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
|||||||
@@ -777,6 +777,8 @@ BEGIN
|
|||||||
name NVARCHAR(255) NOT NULL,
|
name NVARCHAR(255) NOT NULL,
|
||||||
token NVARCHAR(255) NULL,
|
token NVARCHAR(255) NULL,
|
||||||
pairingpin NVARCHAR(50) NOT NULL,
|
pairingpin NVARCHAR(50) NOT NULL,
|
||||||
|
paired_at DATETIME2 NULL,
|
||||||
|
clientserial NVARCHAR(255) NULL,
|
||||||
CONSTRAINT FK_posterminal_company FOREIGN KEY (company_id) REFERENCES company(id) ON DELETE CASCADE
|
CONSTRAINT FK_posterminal_company FOREIGN KEY (company_id) REFERENCES company(id) ON DELETE CASCADE
|
||||||
);
|
);
|
||||||
CREATE UNIQUE INDEX UQ_posterminal_token ON posterminal(token) WHERE token IS NOT NULL;
|
CREATE UNIQUE INDEX UQ_posterminal_token ON posterminal(token) WHERE token IS NOT NULL;
|
||||||
|
|||||||
@@ -413,6 +413,14 @@ export class BetterSqlite3Provider extends BetterSqlite3Executor {
|
|||||||
`ALTER TABLE warehouse ADD COLUMN sort INTEGER NOT NULL DEFAULT 0`,
|
`ALTER TABLE warehouse ADD COLUMN sort INTEGER NOT NULL DEFAULT 0`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const posterminalCols = this.db.pragma('table_info("posterminal")').map((c) => c.name);
|
||||||
|
if (posterminalCols.length > 0 && !posterminalCols.includes('paired_at')) {
|
||||||
|
this.db.exec(`ALTER TABLE posterminal ADD COLUMN paired_at TEXT`);
|
||||||
|
}
|
||||||
|
if (posterminalCols.length > 0 && !posterminalCols.includes('clientserial')) {
|
||||||
|
this.db.exec(`ALTER TABLE posterminal ADD COLUMN clientserial TEXT`);
|
||||||
|
}
|
||||||
} catch {
|
} catch {
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ const queries = translateQueries(source, 'posterminal');
|
|||||||
export const {
|
export const {
|
||||||
CREATE, DELETE_BY_COMPANY_AND_ID, GET_BY_ID, LIST_BY_COMPANY,
|
CREATE, DELETE_BY_COMPANY_AND_ID, GET_BY_ID, LIST_BY_COMPANY,
|
||||||
LIST_CATEGORY_IDS, POSTERMINAL_IDS_BY_COMPANY, SET_OFF, SET_OFF_ALL, UPDATE,
|
LIST_CATEGORY_IDS, POSTERMINAL_IDS_BY_COMPANY, SET_OFF, SET_OFF_ALL, UPDATE,
|
||||||
|
FIND_BY_PAIRINGPIN, PAIR,
|
||||||
} = queries;
|
} = queries;
|
||||||
|
|
||||||
export const SET_ON = `
|
export const SET_ON = `
|
||||||
|
|||||||
@@ -533,6 +533,8 @@ CREATE TABLE IF NOT EXISTS posterminal (
|
|||||||
name TEXT NOT NULL,
|
name TEXT NOT NULL,
|
||||||
token TEXT,
|
token TEXT,
|
||||||
pairingpin TEXT NOT NULL,
|
pairingpin TEXT NOT NULL,
|
||||||
|
paired_at TEXT,
|
||||||
|
clientserial TEXT,
|
||||||
FOREIGN KEY (company_id) REFERENCES company(id) ON DELETE CASCADE
|
FOREIGN KEY (company_id) REFERENCES company(id) ON DELETE CASCADE
|
||||||
);
|
);
|
||||||
CREATE UNIQUE INDEX IF NOT EXISTS UQ_posterminal_token
|
CREATE UNIQUE INDEX IF NOT EXISTS UQ_posterminal_token
|
||||||
|
|||||||
22
src/store/posterminal/findByPairingpin.js
Normal file
22
src/store/posterminal/findByPairingpin.js
Normal 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;
|
||||||
|
};
|
||||||
|
}
|
||||||
34
src/store/posterminal/pair.js
Normal file
34
src/store/posterminal/pair.js
Normal 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,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -47,6 +47,8 @@ export default function upsert(provider) {
|
|||||||
}
|
}
|
||||||
const token = input.token ?? null;
|
const token = input.token ?? null;
|
||||||
const id = input.id ?? null;
|
const id = input.id ?? null;
|
||||||
|
const pairedAt = input.pairedAt ?? null;
|
||||||
|
const clientserial = input.clientserial ?? null;
|
||||||
|
|
||||||
const runner = makeRunner(provider, tx);
|
const runner = makeRunner(provider, tx);
|
||||||
const { companyId } = await access(googleAuthId, tx);
|
const { companyId } = await access(googleAuthId, tx);
|
||||||
@@ -64,9 +66,11 @@ export default function upsert(provider) {
|
|||||||
name,
|
name,
|
||||||
token,
|
token,
|
||||||
pairingpin,
|
pairingpin,
|
||||||
|
pairedAt,
|
||||||
|
clientserial,
|
||||||
});
|
});
|
||||||
|
|
||||||
return { id, name, token, pairingpin };
|
return { id, name, token, pairingpin, pairedAt, clientserial };
|
||||||
}
|
}
|
||||||
|
|
||||||
const created = await runner.query(createSql, {
|
const created = await runner.query(createSql, {
|
||||||
@@ -74,6 +78,8 @@ export default function upsert(provider) {
|
|||||||
name,
|
name,
|
||||||
token,
|
token,
|
||||||
pairingpin,
|
pairingpin,
|
||||||
|
pairedAt,
|
||||||
|
clientserial,
|
||||||
});
|
});
|
||||||
|
|
||||||
const row = created.rows[0] ?? {
|
const row = created.rows[0] ?? {
|
||||||
@@ -81,6 +87,8 @@ export default function upsert(provider) {
|
|||||||
name,
|
name,
|
||||||
token,
|
token,
|
||||||
pairingpin,
|
pairingpin,
|
||||||
|
pairedAt,
|
||||||
|
clientserial,
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -88,6 +96,8 @@ export default function upsert(provider) {
|
|||||||
name: row.name,
|
name: row.name,
|
||||||
token: row.token,
|
token: row.token,
|
||||||
pairingpin: row.pairingpin,
|
pairingpin: row.pairingpin,
|
||||||
|
pairedAt: row.pairedAt ?? null,
|
||||||
|
clientserial: row.clientserial ?? null,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user