Files
jtlPosSync/src/queries/deleted-entity-list.js
2026-07-27 01:14:36 +02:00

33 lines
954 B
JavaScript

import sql from 'mssql';
import { isDemoMode } from '../demo/mode.js';
import { getDemoDeletedEntityList } from '../demo/store.js';
import { getPool } from '../db.js';
const DELETED_ENTITY_LIST_SQL = `
SELECT TOP (@limit)
vDeletedEntity.kEntityId,
vDeletedEntity.nEntityType,
CONVERT(BIGINT, vDeletedEntity.bLastChanged) AS lastChanged
FROM Pos.vDeletedEntity
WHERE CONVERT(BIGINT, vDeletedEntity.bLastChanged) > @cursor
ORDER BY lastChanged ASC;
`;
export async function getDeletedEntityList({ cursor = 0, limit = 600 } = {}) {
if (isDemoMode()) {
return getDemoDeletedEntityList({ cursor, limit });
}
const result = await getPool()
.request()
.input('cursor', sql.BigInt, cursor)
.input('limit', sql.Int, limit)
.query(DELETED_ENTITY_LIST_SQL);
return result.recordset.map((row) => ({
entityId: String(row.kEntityId),
entityType: String(row.nEntityType),
lastChanged: String(row.lastChanged),
}));
}