This commit is contained in:
seb
2026-10-22 14:39:45 +02:00
parent 9495ad51cc
commit e9b4ac5d79
31 changed files with 3405 additions and 3392 deletions

View File

@@ -127,11 +127,11 @@ import posterminalGetCustomerGroupList from './store/posterminal/getCustomerGrou
import posterminalGetCompositeProductCount from './store/posterminal/getCompositeProductCount.js';
import posterminalGetDeletedEntityCount from './store/posterminal/getDeletedEntityCount.js';
import posterminalGetDeletedEntityList from './store/posterminal/getDeletedEntityList.js';
import posterminalRecordTombstone from './store/posterminal/recordTombstone.js';
import posterminalRecordObituary from './store/posterminal/recordObituary.js';
import posterminalGetMaxOrderIdCount from './store/posterminal/getMaxOrderIdCount.js';
import posterminalGetCategoryList from './store/posterminal/getCategoryList.js';
import posterminalGetProductList from './store/posterminal/getProductList.js';
import posterminalSetMaxKnownTombstoneId from './store/posterminal/setMaxKnownTombstoneId.js';
import posterminalSetMaxKnownObituaryId from './store/posterminal/setMaxKnownObituaryId.js';
import posterminalTouchLastseen from './store/posterminal/touchLastseen.js';
import langCreate from './store/lang/create.js';
import langDelete from './store/lang/delete.js';
@@ -491,11 +491,11 @@ export default class LibDashStore {
getCompositeProductCount: posterminalGetCompositeProductCount(provider),
getDeletedEntityCount: posterminalGetDeletedEntityCount(provider),
getDeletedEntityList: posterminalGetDeletedEntityList(provider),
recordTombstone: posterminalRecordTombstone(provider),
recordObituary: posterminalRecordObituary(provider),
getMaxOrderIdCount: posterminalGetMaxOrderIdCount(provider),
getCategoryList: posterminalGetCategoryList(provider),
getProductList: posterminalGetProductList(provider),
setMaxKnownTombstoneId: posterminalSetMaxKnownTombstoneId(provider),
setMaxKnownObituaryId: posterminalSetMaxKnownObituaryId(provider),
touchLastseen: posterminalTouchLastseen(provider),
};

View File

@@ -6,7 +6,7 @@ SELECT
pairingpin,
paired_at AS pairedAt,
clientserial AS clientserial,
maxknowntombstoneid AS maxknowntombstoneid,
maxknownobituaryid AS maxknownobituaryid,
root_category_id AS rootCategoryId,
sync_root_articles AS syncRootArticles,
lastseen_at AS lastseenAt,
@@ -25,7 +25,7 @@ SELECT
pairingpin,
paired_at AS pairedAt,
clientserial AS clientserial,
maxknowntombstoneid AS maxknowntombstoneid,
maxknownobituaryid AS maxknownobituaryid,
root_category_id AS rootCategoryId,
sync_root_articles AS syncRootArticles,
lastseen_at AS lastseenAt,
@@ -43,7 +43,7 @@ SELECT
pairingpin,
paired_at AS pairedAt,
clientserial AS clientserial,
maxknowntombstoneid AS maxknowntombstoneid,
maxknownobituaryid AS maxknownobituaryid,
root_category_id AS rootCategoryId,
sync_root_articles AS syncRootArticles,
lastseen_at AS lastseenAt,
@@ -59,14 +59,14 @@ WHERE id = @id
`;
export const CREATE = `
INSERT INTO posterminal (company_id, name, token, pairingpin, paired_at, clientserial, maxknowntombstoneid, root_category_id, sync_root_articles, lastseen_at, updated_at)
OUTPUT INSERTED.id, INSERTED.name, INSERTED.token, INSERTED.pairingpin, INSERTED.paired_at AS pairedAt, INSERTED.clientserial AS clientserial, INSERTED.maxknowntombstoneid AS maxknowntombstoneid, INSERTED.root_category_id AS rootCategoryId, INSERTED.sync_root_articles AS syncRootArticles, INSERTED.lastseen_at AS lastseenAt, INSERTED.updated_at AS updatedAt
VALUES (@companyId, @name, @token, @pairingpin, @pairedAt, @clientserial, @maxknowntombstoneid, @rootCategoryId, @syncRootArticles, @lastseenAt, SYSUTCDATETIME())
INSERT INTO posterminal (company_id, name, token, pairingpin, paired_at, clientserial, maxknownobituaryid, root_category_id, sync_root_articles, lastseen_at, updated_at)
OUTPUT INSERTED.id, INSERTED.name, INSERTED.token, INSERTED.pairingpin, INSERTED.paired_at AS pairedAt, INSERTED.clientserial AS clientserial, INSERTED.maxknownobituaryid AS maxknownobituaryid, INSERTED.root_category_id AS rootCategoryId, INSERTED.sync_root_articles AS syncRootArticles, INSERTED.lastseen_at AS lastseenAt, INSERTED.updated_at AS updatedAt
VALUES (@companyId, @name, @token, @pairingpin, @pairedAt, @clientserial, @maxknownobituaryid, @rootCategoryId, @syncRootArticles, @lastseenAt, SYSUTCDATETIME())
`;
export const UPDATE = `
UPDATE posterminal
SET name = @name, token = @token, pairingpin = @pairingpin, paired_at = @pairedAt, clientserial = @clientserial, maxknowntombstoneid = @maxknowntombstoneid, root_category_id = @rootCategoryId, sync_root_articles = @syncRootArticles, lastseen_at = @lastseenAt, updated_at = SYSUTCDATETIME()
SET name = @name, token = @token, pairingpin = @pairingpin, paired_at = @pairedAt, clientserial = @clientserial, maxknownobituaryid = @maxknownobituaryid, root_category_id = @rootCategoryId, sync_root_articles = @syncRootArticles, lastseen_at = @lastseenAt, updated_at = SYSUTCDATETIME()
WHERE id = @id AND company_id = @companyId
`;
@@ -76,9 +76,9 @@ SET lastseen_at = SYSUTCDATETIME()
WHERE id = @id
`;
export const SET_MAX_KNOWN_TOMBSTONE_ID = `
export const SET_MAX_KNOWN_OBITUARY_ID = `
UPDATE posterminal
SET maxknowntombstoneid = @maxknowntombstoneid
SET maxknownobituaryid = @maxknownobituaryid
WHERE id = @id
`;
@@ -150,7 +150,7 @@ SELECT
pairingpin,
paired_at AS pairedAt,
clientserial AS clientserial,
maxknowntombstoneid AS maxknowntombstoneid,
maxknownobituaryid AS maxknownobituaryid,
root_category_id AS rootCategoryId,
sync_root_articles AS syncRootArticles,
lastseen_at AS lastseenAt,
@@ -483,8 +483,8 @@ WHERE pr.minmultiplier = 1
GROUP BY pr.article_id, pr.customergroup_id
`;
export const RECORD_TOMBSTONE = `
INSERT INTO posterminaltombstone (posterminal_id, entity_type, entity_id)
export const RECORD_OBITUARY = `
INSERT INTO posterminalobituary (posterminal_id, entity_type, entity_id)
SELECT pt.id, @entityType, @entityId
FROM posterminal pt
WHERE pt.company_id = @companyId AND pt.token IS NOT NULL
@@ -492,7 +492,7 @@ WHERE pt.company_id = @companyId AND pt.token IS NOT NULL
export const COUNT_DELETED_ENTITIES = `
SELECT COUNT(*) AS count
FROM posterminaltombstone
FROM posterminalobituary
WHERE posterminal_id = @posterminalId AND id > @cursor
`;
@@ -501,7 +501,7 @@ SELECT TOP (@limit)
id,
entity_type AS entityType,
entity_id AS entityId
FROM posterminaltombstone
FROM posterminalobituary
WHERE posterminal_id = @posterminalId AND id > @cursor
ORDER BY id ASC
`;

View File

@@ -392,20 +392,20 @@ BEGIN
END
`;
export const INIT_POSTERMINALTOMBSTONE = `
IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'posterminaltombstone')
export const INIT_POSTERMINALOBITUARY = `
IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'posterminalobituary')
BEGIN
CREATE TABLE posterminaltombstone (
CREATE TABLE posterminalobituary (
id INT IDENTITY(1,1) PRIMARY KEY,
posterminal_id INT NOT NULL,
entity_type NVARCHAR(50) NOT NULL,
entity_id INT NOT NULL,
created_at DATETIME2 NOT NULL CONSTRAINT DF_posterminaltombstone_created_at DEFAULT SYSUTCDATETIME(),
CONSTRAINT FK_posterminaltombstone_posterminal FOREIGN KEY (posterminal_id) REFERENCES posterminal(id) ON DELETE CASCADE
created_at DATETIME2 NOT NULL CONSTRAINT DF_posterminalobituary_created_at DEFAULT SYSUTCDATETIME(),
CONSTRAINT FK_posterminalobituary_posterminal FOREIGN KEY (posterminal_id) REFERENCES posterminal(id) ON DELETE CASCADE
);
CREATE INDEX IX_posterminaltombstone_posterminal_id
ON posterminaltombstone (posterminal_id, id);
CREATE INDEX IX_posterminalobituary_posterminal_id
ON posterminalobituary (posterminal_id, id);
END
`;
@@ -894,7 +894,7 @@ BEGIN
pairingpin NVARCHAR(50) NULL,
paired_at DATETIME2 NULL,
clientserial NVARCHAR(255) NULL,
maxknowntombstoneid INT NULL,
maxknownobituaryid INT NULL,
root_category_id INT NULL,
sync_root_articles BIT NOT NULL CONSTRAINT DF_posterminal_sync_root_articles DEFAULT 1,
lastseen_at DATETIME2 NULL,
@@ -1503,7 +1503,7 @@ export const SCHEMA_SCRIPTS = [
INIT_COMPANYSETTING,
INIT_POSTERMINAL,
INIT_POSTERMINALCATEGORY,
INIT_POSTERMINALTOMBSTONE,
INIT_POSTERMINALOBITUARY,
INIT_PRINTER,
INIT_LABELTEMPLATE,
INIT_FILE,

View File

@@ -479,8 +479,8 @@ export class BetterSqlite3Provider extends BetterSqlite3Executor {
if (posterminalCols.length > 0 && !posterminalCols.includes('clientserial')) {
this.db.exec(`ALTER TABLE posterminal ADD COLUMN clientserial TEXT`);
}
if (posterminalCols.length > 0 && !posterminalCols.includes('maxknowntombstoneid')) {
this.db.exec(`ALTER TABLE posterminal ADD COLUMN maxknowntombstoneid INTEGER`);
if (posterminalCols.length > 0 && !posterminalCols.includes('maxknownobituaryid')) {
this.db.exec(`ALTER TABLE posterminal ADD COLUMN maxknownobituaryid INTEGER`);
}
const propertynameCols = this.db.pragma('table_info("propertyname")').map((c) => c.name);

View File

@@ -5,11 +5,11 @@ const queries = translateQueries(source, 'posterminal');
export const {
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,
FIND_BY_PAIRINGPIN, PAIR, SET_MAX_KNOWN_TOMBSTONE_ID,
FIND_BY_PAIRINGPIN, PAIR, SET_MAX_KNOWN_OBITUARY_ID,
FIND_BY_TOKEN, COUNT_PRODUCTS, COUNT_CATEGORIES, COUNT_CUSTOMERS,
COUNT_CUSTOMER_GROUPS, COUNT_COMPOSITE_PRODUCTS, MAX_ORDER_ID,
LIST_POS_PRODUCT_CATEGORIES, LIST_POS_CUSTOMER_GROUP_IDS, LIST_POS_PRODUCT_PRICES,
TOUCH_LASTSEEN, RECORD_TOMBSTONE, COUNT_DELETED_ENTITIES,
TOUCH_LASTSEEN, RECORD_OBITUARY, COUNT_DELETED_ENTITIES,
} = queries;
export const SET_ON = `
@@ -269,7 +269,7 @@ SELECT
id,
entity_type AS entityType,
entity_id AS entityId
FROM posterminaltombstone
FROM posterminalobituary
WHERE posterminal_id = @posterminalId AND id > @cursor
ORDER BY id ASC
LIMIT @limit

View File

@@ -608,7 +608,7 @@ CREATE TABLE IF NOT EXISTS posterminal (
pairingpin TEXT,
paired_at TEXT,
clientserial TEXT,
maxknowntombstoneid INTEGER,
maxknownobituaryid INTEGER,
root_category_id INTEGER,
sync_root_articles INTEGER NOT NULL DEFAULT 1,
lastseen_at TEXT,
@@ -631,8 +631,8 @@ CREATE TABLE IF NOT EXISTS posterminalcategory (
);
`;
export const INIT_POSTERMINALTOMBSTONE = `
CREATE TABLE IF NOT EXISTS posterminaltombstone (
export const INIT_POSTERMINALOBITUARY = `
CREATE TABLE IF NOT EXISTS posterminalobituary (
id INTEGER PRIMARY KEY AUTOINCREMENT,
posterminal_id INTEGER NOT NULL,
entity_type TEXT NOT NULL,
@@ -640,8 +640,8 @@ CREATE TABLE IF NOT EXISTS posterminaltombstone (
created_at TEXT NOT NULL DEFAULT (${UTC_NOW}),
FOREIGN KEY (posterminal_id) REFERENCES posterminal(id) ON DELETE CASCADE
);
CREATE INDEX IF NOT EXISTS IX_posterminaltombstone_posterminal_id
ON posterminaltombstone (posterminal_id, id);
CREATE INDEX IF NOT EXISTS IX_posterminalobituary_posterminal_id
ON posterminalobituary (posterminal_id, id);
`;
export const INIT_PRINTER = `
@@ -1119,7 +1119,7 @@ export const SCHEMA_SCRIPTS = [
INIT_COMPANYSETTING,
INIT_POSTERMINAL,
INIT_POSTERMINALCATEGORY,
INIT_POSTERMINALTOMBSTONE,
INIT_POSTERMINALOBITUARY,
INIT_PRINTER,
INIT_LABELTEMPLATE,
INIT_FILE,

View File

@@ -3,12 +3,12 @@ import * as sqliteQueries from '../../providers/sqlite3/queries/articleDelete.js
import * as mssqlArticle from '../../providers/mssql/queries/article.js';
import * as sqliteArticle from '../../providers/sqlite3/queries/article.js';
import resolveArticleBySku from './resolveArticleBySku.js';
import recordTombstone from '../posterminal/recordTombstone.js';
import recordObituary from '../posterminal/recordObituary.js';
import makeRunner from '../runner.js';
export default function del(provider) {
const resolve = resolveArticleBySku(provider);
const tombstone = recordTombstone(provider);
const recordObit = recordObituary(provider);
const isSqlite = provider?.dialect === 'sqlite3';
const queries = isSqlite ? sqliteQueries : mssqlQueries;
const articleQueries = isSqlite ? sqliteArticle : mssqlArticle;
@@ -45,7 +45,7 @@ export default function del(provider) {
const listIds = await runner.query(queries.GET_LIST_IDS, { articleId: id });
const { articlelistId, optionslistId } = listIds.rows[0] ?? {};
await tombstone({ companyId, entityType: 'article', entityId: id }, runner);
await recordObit({ companyId, entityType: 'article', entityId: id }, runner);
await runner.query(queries.DELETE_PICS_BY_ARTICLE, { articleId: id });

View File

@@ -5,12 +5,12 @@ import * as sqliteArticleDelete from '../../providers/sqlite3/queries/articleDel
import * as mssqlArticle from '../../providers/mssql/queries/article.js';
import * as sqliteArticle from '../../providers/sqlite3/queries/article.js';
import resolveCategoryAccess from './resolveCategoryAccess.js';
import recordTombstone from '../posterminal/recordTombstone.js';
import recordObituary from '../posterminal/recordObituary.js';
import makeRunner from '../runner.js';
export default function del(provider) {
const access = resolveCategoryAccess(provider);
const tombstone = recordTombstone(provider);
const recordObit = recordObituary(provider);
const isSqlite = provider?.dialect === 'sqlite3';
const sql = isSqlite ? SQLITE_DELETE : MSSQL_DELETE;
const articleDeleteQueries = isSqlite ? sqliteArticleDelete : mssqlArticleDelete;
@@ -67,7 +67,7 @@ export default function del(provider) {
try {
await runner.query(sql, { id });
await tombstone({ companyId, entityType: 'category', entityId: id }, runner);
await recordObit({ companyId, entityType: 'category', entityId: id }, runner);
} catch (err) {
if (
err.message?.includes('FOREIGN KEY constraint failed') ||
@@ -149,7 +149,7 @@ export default function del(provider) {
const listIds = await runner.query(articleDeleteQueries.GET_LIST_IDS, { articleId: artId });
const { articlelistId, optionslistId } = listIds.rows[0] ?? {};
await tombstone({ companyId, entityType: 'article', entityId: artId }, runner);
await recordObit({ companyId, entityType: 'article', entityId: artId }, runner);
await runner.query(articleDeleteQueries.DELETE_PICS_BY_ARTICLE, { articleId: artId });
const deleted = await runner.query(articleDeleteQueries.DELETE_BY_ID, { articleId: artId });
@@ -218,7 +218,7 @@ export default function del(provider) {
const reversedIds = [...subtreeIds].reverse();
for (const catId of reversedIds) {
await runner.query(sql, { id: catId });
await tombstone({ companyId, entityType: 'category', entityId: catId }, runner);
await recordObit({ companyId, entityType: 'category', entityId: catId }, runner);
}
};

View File

@@ -2,12 +2,12 @@ import { DELETE_BY_COMPANY_AND_ID as MSSQL_DELETE_BY_COMPANY_AND_ID } from '../.
import { DELETE_BY_COMPANY_AND_ID as SQLITE_DELETE_BY_COMPANY_AND_ID } from '../../providers/sqlite3/queries/customergroup.js';
import { isForeignKeyConstraintError } from '../../providers/provider.js';
import resolveSelectedCompanyAccess from '../companyuser/resolveSelectedCompanyAccess.js';
import recordTombstone from '../posterminal/recordTombstone.js';
import recordObituary from '../posterminal/recordObituary.js';
import makeRunner from '../runner.js';
export default function del(provider) {
const access = resolveSelectedCompanyAccess(provider);
const tombstone = recordTombstone(provider);
const recordObit = recordObituary(provider);
const sql =
provider?.dialect === 'sqlite3'
? SQLITE_DELETE_BY_COMPANY_AND_ID
@@ -43,7 +43,7 @@ export default function del(provider) {
throw new Error('Customer group not found');
}
await tombstone({ companyId, entityType: 'customergroup', entityId: id }, runner);
await recordObit({ companyId, entityType: 'customergroup', entityId: id }, runner);
} catch (err) {
if (isForeignKeyConstraintError(err)) {
throw new Error('Customer group in use');

View File

@@ -9,12 +9,12 @@ import {
GET_BY_COMPANY_AND_ID as SQLITE_GET_BY_ID,
} from '../../providers/sqlite3/queries/entity.js';
import resolveSelectedCompanyAccess from '../companyuser/resolveSelectedCompanyAccess.js';
import recordTombstone from '../posterminal/recordTombstone.js';
import recordObituary from '../posterminal/recordObituary.js';
import makeRunner from '../runner.js';
export default function del(provider) {
const access = resolveSelectedCompanyAccess(provider);
const tombstone = recordTombstone(provider);
const recordObit = recordObituary(provider);
const isSqlite = provider?.dialect === 'sqlite3';
const sql = isSqlite ? SQLITE_DELETE : MSSQL_DELETE;
const checkInUseSql = isSqlite ? SQLITE_CHECK_IN_USE : MSSQL_CHECK_IN_USE;
@@ -66,7 +66,7 @@ export default function del(provider) {
throw new Error('Entity not found');
}
await tombstone({ companyId, entityType: 'customer', entityId: numericId }, runner);
await recordObit({ companyId, entityType: 'customer', entityId: numericId }, runner);
};
}

View File

@@ -10,7 +10,7 @@ export default function findByPairingpin(provider) {
*
* @param {string} pairingpin - The pairing pin to search for.
* @param {object} [tx] - Optional transaction to run within.
* @returns {Promise<{id: number, companyId: number, name: string, token: string|null, pairingpin: string|null, pairedAt: string|null, clientserial: string|null, maxknowntombstoneid: number|null, rootCategoryId: number|null, syncRootArticles: boolean|number, lastseenAt: string|null, updatedAt: string}|null>} The posterminal, or null if not found.
* @returns {Promise<{id: number, companyId: number, name: string, token: string|null, pairingpin: string|null, pairedAt: string|null, clientserial: string|null, maxknownobituaryid: number|null, rootCategoryId: number|null, syncRootArticles: boolean|number, lastseenAt: string|null, updatedAt: string}|null>} The posterminal, or null if not found.
*/
return async (pairingpin, tx) => {
if (!pairingpin) return null;

View File

@@ -10,7 +10,7 @@ export default function findByToken(provider) {
*
* @param {string} token - The auth token to search for.
* @param {object} [tx] - Optional transaction to run within.
* @returns {Promise<{id: number, companyId: number, name: string, token: string|null, pairingpin: string|null, pairedAt: string|null, clientserial: string|null, maxknowntombstoneid: number|null, rootCategoryId: number|null, syncRootArticles: boolean|number, lastseenAt: string|null, updatedAt: string}|null>} The posterminal, or null if not found.
* @returns {Promise<{id: number, companyId: number, name: string, token: string|null, pairingpin: string|null, pairedAt: string|null, clientserial: string|null, maxknownobituaryid: number|null, rootCategoryId: number|null, syncRootArticles: boolean|number, lastseenAt: string|null, updatedAt: string}|null>} The posterminal, or null if not found.
*/
return async (token, tx) => {
const trimmed = String(token ?? '').trim();

View File

@@ -10,7 +10,7 @@ export default function getDeletedEntityCount(provider) {
*
* @param {object} input
* @param {number} input.posterminalId - The POS terminal id.
* @param {number} [input.cursor=0] - The highest synced tombstone ID.
* @param {number} [input.cursor=0] - The highest synced obituary ID.
* @param {object} [tx] - Optional transaction.
* @returns {Promise<number>} Count of deleted entities.
*/

View File

@@ -10,7 +10,7 @@ export default function getDeletedEntityList(provider) {
*
* @param {object} input
* @param {number} input.posterminalId - The POS terminal id.
* @param {number} [input.cursor=0] - The highest synced tombstone ID.
* @param {number} [input.cursor=0] - The highest synced obituary ID.
* @param {number} [input.limit=200] - Max items to return.
* @param {object} [tx] - Optional transaction.
* @returns {Promise<Array<{id: number, entityType: string, entityId: number}>>}

View File

@@ -12,11 +12,11 @@ export default function list(provider) {
*
* @param {number} googleAuthId - The id of the Google auth user.
* @param {object} [tx] - Optional transaction to run within.
* @returns {Promise<Array<{id: number, name: string, token: string|null, pairingpin: string|null, pairedAt: string|null, clientserial: string|null, maxknowntombstoneid: number|null, rootCategoryId: number|null, syncRootArticles: boolean|number, lastseenAt: string|null, updatedAt: string}>>} The posterminals.
* @returns {Promise<Array<{id: number, name: string, token: string|null, pairingpin: string|null, pairedAt: string|null, clientserial: string|null, maxknownobituaryid: number|null, rootCategoryId: number|null, syncRootArticles: boolean|number, lastseenAt: string|null, updatedAt: string}>>} The posterminals.
*
* @example
* const terminals = await store.posterminal.list(42);
* // => [{ id, name, token, pairingpin, pairedAt, clientserial, maxknowntombstoneid, rootCategoryId, syncRootArticles, lastseenAt, updatedAt }]
* // => [{ id, name, token, pairingpin, pairedAt, clientserial, maxknownobituaryid, rootCategoryId, syncRootArticles, lastseenAt, updatedAt }]
*/
return async (googleAuthId, tx) => {
const { companyId } = await access(googleAuthId, tx);

View File

@@ -1,12 +1,12 @@
import { RECORD_TOMBSTONE as MSSQL_SQL } from '../../providers/mssql/queries/posterminal.js';
import { RECORD_TOMBSTONE as SQLITE_SQL } from '../../providers/sqlite3/queries/posterminal.js';
import { RECORD_OBITUARY as MSSQL_SQL } from '../../providers/mssql/queries/posterminal.js';
import { RECORD_OBITUARY as SQLITE_SQL } from '../../providers/sqlite3/queries/posterminal.js';
import makeRunner from '../runner.js';
export default function recordTombstone(provider) {
export default function recordObituary(provider) {
const sql = provider?.dialect === 'sqlite3' ? SQLITE_SQL : MSSQL_SQL;
/**
* Records a tombstone for all active paired POS terminals of a company.
* Records an obituary for all active paired POS terminals of a company.
*
* @param {object} input
* @param {number} input.companyId - The company id.

View File

@@ -0,0 +1,27 @@
import { SET_MAX_KNOWN_OBITUARY_ID as MSSQL_SET } from '../../providers/mssql/queries/posterminal.js';
import { SET_MAX_KNOWN_OBITUARY_ID as SQLITE_SET } from '../../providers/sqlite3/queries/posterminal.js';
import makeRunner from '../runner.js';
export default function setMaxKnownObituaryId(provider) {
const sql = provider?.dialect === 'sqlite3' ? SQLITE_SET : MSSQL_SET;
/**
* Updates the max known obituary ID for a POS terminal.
*
* @param {number} id - The posterminal id.
* @param {number|null} maxknownobituaryid - The highest synced obituary ID.
* @param {object} [tx] - Optional transaction to run within.
* @returns {Promise<{id: number, maxknownobituaryid: number|null}>}
*/
return async (id, maxknownobituaryid, tx) => {
await makeRunner(provider, tx).query(sql, {
id,
maxknownobituaryid: maxknownobituaryid != null ? Number(maxknownobituaryid) : null,
});
return {
id,
maxknownobituaryid: maxknownobituaryid != null ? Number(maxknownobituaryid) : null,
};
};
}

View File

@@ -1,27 +0,0 @@
import { SET_MAX_KNOWN_TOMBSTONE_ID as MSSQL_SET } from '../../providers/mssql/queries/posterminal.js';
import { SET_MAX_KNOWN_TOMBSTONE_ID as SQLITE_SET } from '../../providers/sqlite3/queries/posterminal.js';
import makeRunner from '../runner.js';
export default function setMaxKnownTombstoneId(provider) {
const sql = provider?.dialect === 'sqlite3' ? SQLITE_SET : MSSQL_SET;
/**
* Updates the max known tombstone ID for a POS terminal.
*
* @param {number} id - The posterminal id.
* @param {number|null} maxknowntombstoneid - The highest synced tombstone ID.
* @param {object} [tx] - Optional transaction to run within.
* @returns {Promise<{id: number, maxknowntombstoneid: number|null}>}
*/
return async (id, maxknowntombstoneid, tx) => {
await makeRunner(provider, tx).query(sql, {
id,
maxknowntombstoneid: maxknowntombstoneid != null ? Number(maxknowntombstoneid) : null,
});
return {
id,
maxknowntombstoneid: maxknowntombstoneid != null ? Number(maxknowntombstoneid) : null,
};
};
}

View File

@@ -21,13 +21,13 @@ export default function setOff(provider) {
? SQLITE_LIST_CATEGORY_IDS
: MSSQL_LIST_CATEGORY_IDS;
const addCategoryTombstoneSql = `
INSERT INTO posterminaltombstone (posterminal_id, entity_type, entity_id)
const addCategoryObituarySql = `
INSERT INTO posterminalobituary (posterminal_id, entity_type, entity_id)
VALUES (@posterminalId, 'category', @categoryId)
`;
const addArticleTombstonesSql = `
INSERT INTO posterminaltombstone (posterminal_id, entity_type, entity_id)
const addArticleObituariesSql = `
INSERT INTO posterminalobituary (posterminal_id, entity_type, entity_id)
SELECT DISTINCT @posterminalId, 'article', ca.article_id
FROM categoryarticle ca
WHERE ca.category_id = @categoryId
@@ -69,12 +69,12 @@ export default function setOff(provider) {
throw new Error('Posterminal not found');
}
await runner.query(addCategoryTombstoneSql, {
await runner.query(addCategoryObituarySql, {
posterminalId,
categoryId,
});
await runner.query(addArticleTombstonesSql, {
await runner.query(addArticleObituariesSql, {
posterminalId,
categoryId,
});

View File

@@ -21,15 +21,15 @@ export default function setOffAll(provider) {
? SQLITE_LIST_CATEGORY_IDS
: MSSQL_LIST_CATEGORY_IDS;
const addCategoryTombstonesSql = `
INSERT INTO posterminaltombstone (posterminal_id, entity_type, entity_id)
const addCategoryObituariesSql = `
INSERT INTO posterminalobituary (posterminal_id, entity_type, entity_id)
SELECT posterminal_id, 'category', category_id
FROM posterminalcategory
WHERE posterminal_id = @posterminalId
`;
const addArticleTombstonesSql = `
INSERT INTO posterminaltombstone (posterminal_id, entity_type, entity_id)
const addArticleObituariesSql = `
INSERT INTO posterminalobituary (posterminal_id, entity_type, entity_id)
SELECT DISTINCT pc.posterminal_id, 'article', ca.article_id
FROM posterminalcategory pc
INNER JOIN categoryarticle ca ON ca.category_id = pc.category_id
@@ -64,8 +64,8 @@ export default function setOffAll(provider) {
throw new Error('Posterminal not found');
}
await runner.query(addCategoryTombstonesSql, { posterminalId });
await runner.query(addArticleTombstonesSql, { posterminalId });
await runner.query(addCategoryObituariesSql, { posterminalId });
await runner.query(addArticleObituariesSql, { posterminalId });
await runner.query(setOffAllSql, { posterminalId });

View File

@@ -35,8 +35,8 @@ export default function setOn(provider) {
SELECT ca.article_id FROM categoryarticle ca WHERE ca.category_id = @categoryId
)`;
const clearTombstonesSql = `
DELETE FROM posterminaltombstone
const clearObituariesSql = `
DELETE FROM posterminalobituary
WHERE posterminal_id = @posterminalId
AND (
(entity_type = 'category' AND entity_id = @categoryId)
@@ -79,7 +79,7 @@ export default function setOn(provider) {
categoryId,
});
await runner.query(clearTombstonesSql, {
await runner.query(clearObituariesSql, {
posterminalId,
categoryId,
});

View File

@@ -47,8 +47,8 @@ export default function setOnAll(provider) {
SET updated_at = SYSUTCDATETIME()
WHERE company_id = @companyId`;
const clearTombstonesSql = `
DELETE FROM posterminaltombstone
const clearObituariesSql = `
DELETE FROM posterminalobituary
WHERE posterminal_id = @posterminalId
AND entity_type IN ('category', 'article')
`;
@@ -94,7 +94,7 @@ export default function setOnAll(provider) {
rootCategoryId,
});
await runner.query(clearTombstonesSql, {
await runner.query(clearObituariesSql, {
posterminalId,
});

View File

@@ -63,10 +63,10 @@ export default function upsert(provider) {
? (input.pairingpin ? String(input.pairingpin).trim() : null)
: (existing.rows[0].pairingpin ?? null);
const maxknowntombstoneid =
input.maxknowntombstoneid !== undefined
? input.maxknowntombstoneid
: (existing.rows[0].maxknowntombstoneid ?? null);
const maxknownobituaryid =
input.maxknownobituaryid !== undefined
? input.maxknownobituaryid
: (existing.rows[0].maxknownobituaryid ?? null);
const rootCategoryId =
input.rootCategoryId !== undefined
@@ -91,7 +91,7 @@ export default function upsert(provider) {
pairingpin,
pairedAt,
clientserial,
maxknowntombstoneid,
maxknownobituaryid,
rootCategoryId,
syncRootArticles,
lastseenAt,
@@ -104,7 +104,7 @@ export default function upsert(provider) {
pairingpin,
pairedAt,
clientserial,
maxknowntombstoneid,
maxknownobituaryid,
rootCategoryId,
syncRootArticles,
lastseenAt,
@@ -112,7 +112,7 @@ export default function upsert(provider) {
}
const pairingpin = input.pairingpin ? String(input.pairingpin).trim() : null;
const maxknowntombstoneid = input.maxknowntombstoneid ?? null;
const maxknownobituaryid = input.maxknownobituaryid ?? null;
const rootCategoryId = input.rootCategoryId != null ? Number(input.rootCategoryId) : null;
const syncRootArticles = input.syncRootArticles !== undefined ? (input.syncRootArticles ? 1 : 0) : 1;
const lastseenAt = input.lastseenAt ?? null;
@@ -124,7 +124,7 @@ export default function upsert(provider) {
pairingpin,
pairedAt,
clientserial,
maxknowntombstoneid,
maxknownobituaryid,
rootCategoryId,
syncRootArticles,
lastseenAt,
@@ -137,7 +137,7 @@ export default function upsert(provider) {
pairingpin,
pairedAt,
clientserial,
maxknowntombstoneid,
maxknownobituaryid,
rootCategoryId,
syncRootArticles,
lastseenAt,
@@ -150,7 +150,7 @@ export default function upsert(provider) {
pairingpin: row.pairingpin ?? null,
pairedAt: row.pairedAt ?? null,
clientserial: row.clientserial ?? null,
maxknowntombstoneid: row.maxknowntombstoneid ?? null,
maxknownobituaryid: row.maxknownobituaryid ?? null,
rootCategoryId: row.rootCategoryId ?? null,
syncRootArticles: row.syncRootArticles !== undefined ? (row.syncRootArticles ? 1 : 0) : 1,
lastseenAt: row.lastseenAt ?? null,