composite & deleted
This commit is contained in:
18
src/queries/composite-product-count.js
Normal file
18
src/queries/composite-product-count.js
Normal file
@@ -0,0 +1,18 @@
|
||||
import sql from 'mssql';
|
||||
import { getPool } from '../db.js';
|
||||
|
||||
const COMPOSITE_PRODUCT_COUNT_SQL = `
|
||||
SELECT COUNT(DISTINCT a.kArtikel) AS CompositeProductCount
|
||||
FROM dbo.tArtikel a
|
||||
INNER JOIN dbo.tStueckliste s ON s.kStueckliste = a.kStueckliste
|
||||
WHERE a.kStueckliste <> 0
|
||||
AND CONVERT(BIGINT, a.bRowversion) > @cursor;
|
||||
`;
|
||||
|
||||
export async function getCompositeProductCount({ cursor = 0 } = {}) {
|
||||
const result = await getPool()
|
||||
.request()
|
||||
.input('cursor', sql.BigInt, cursor)
|
||||
.query(COMPOSITE_PRODUCT_COUNT_SQL);
|
||||
return result.recordset[0]?.CompositeProductCount ?? 0;
|
||||
}
|
||||
30
src/queries/composite-product-list.js
Normal file
30
src/queries/composite-product-list.js
Normal file
@@ -0,0 +1,30 @@
|
||||
import sql from 'mssql';
|
||||
import { getPool } from '../db.js';
|
||||
|
||||
const COMPOSITE_PRODUCT_LIST_SQL = `
|
||||
SELECT TOP (@limit)
|
||||
s.kVaterArtikel AS productId,
|
||||
s.kArtikel AS productIdComponent,
|
||||
CONVERT(VARCHAR(20), s.fAnzahl, 2) AS quantity,
|
||||
CONVERT(BIGINT, a.bRowversion) AS lastChanged
|
||||
FROM dbo.tStueckliste s
|
||||
INNER JOIN dbo.tArtikel a ON a.kArtikel = s.kVaterArtikel
|
||||
WHERE a.kStueckliste <> 0
|
||||
AND CONVERT(BIGINT, a.bRowversion) > @cursor
|
||||
ORDER BY lastChanged ASC;
|
||||
`;
|
||||
|
||||
export async function getCompositeProductList({ cursor = 0, limit = 100 } = {}) {
|
||||
const result = await getPool()
|
||||
.request()
|
||||
.input('cursor', sql.BigInt, cursor)
|
||||
.input('limit', sql.Int, limit)
|
||||
.query(COMPOSITE_PRODUCT_LIST_SQL);
|
||||
|
||||
return result.recordset.map((row) => ({
|
||||
productId: String(row.productId),
|
||||
productIdComponent: String(row.productIdComponent),
|
||||
quantity: row.quantity,
|
||||
lastChanged: String(row.lastChanged),
|
||||
}));
|
||||
}
|
||||
16
src/queries/deleted-entity-count.js
Normal file
16
src/queries/deleted-entity-count.js
Normal file
@@ -0,0 +1,16 @@
|
||||
import sql from 'mssql';
|
||||
import { getPool } from '../db.js';
|
||||
|
||||
const DELETED_ENTITY_COUNT_SQL = `
|
||||
SELECT COUNT(*) AS DeletedEntityCount
|
||||
FROM Pos.vDeletedEntity
|
||||
WHERE CONVERT(BIGINT, vDeletedEntity.bLastChanged) > @cursor;
|
||||
`;
|
||||
|
||||
export async function getDeletedEntityCount({ cursor = 0 } = {}) {
|
||||
const result = await getPool()
|
||||
.request()
|
||||
.input('cursor', sql.BigInt, cursor)
|
||||
.query(DELETED_ENTITY_COUNT_SQL);
|
||||
return result.recordset[0]?.DeletedEntityCount ?? 0;
|
||||
}
|
||||
26
src/queries/deleted-entity-list.js
Normal file
26
src/queries/deleted-entity-list.js
Normal file
@@ -0,0 +1,26 @@
|
||||
import sql from 'mssql';
|
||||
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 } = {}) {
|
||||
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),
|
||||
}));
|
||||
}
|
||||
@@ -38,6 +38,7 @@ SELECT TOP (@limit)
|
||||
) AS categoryIds,
|
||||
a.nIstVater AS isParent,
|
||||
a.kVaterArtikel AS parentArticleId,
|
||||
CASE WHEN a.kStueckliste <> 0 THEN '1' ELSE '0' END AS isCompositeProduct,
|
||||
(
|
||||
SELECT TOP 1 pv.cVariantName
|
||||
FROM Pos.vProductVariant pv
|
||||
@@ -144,6 +145,7 @@ export async function getProductList({ cursor = 0, limit = 20 } = {}) {
|
||||
is_parent: product.isParent ? '1' : '0',
|
||||
parent: product.parentArticleId > 0 ? String(product.parentArticleId) : '0',
|
||||
variants: product.variantName ?? '',
|
||||
isCompositeProduct: product.isCompositeProduct,
|
||||
attributes: articleAttributes?.attributes ?? [],
|
||||
...(articleAttributes?.deposit ?? {}),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user