37 lines
1.1 KiB
JavaScript
37 lines
1.1 KiB
JavaScript
const { pool } = require('./src/db/pool');
|
|
|
|
async function test() {
|
|
const actorId = 'act_admin';
|
|
console.log("Checking for actorId:", actorId);
|
|
|
|
// Pharmacy Drugs (CatalogueService)
|
|
const query1 = `
|
|
SELECT p.brand_name,
|
|
(SELECT COALESCE(SUM(qty_on_hand), 0) FROM batches WHERE product_id = p.id AND expiry > CURRENT_DATE AND tenant_id = $1) as total_stock
|
|
FROM products p
|
|
JOIN drugs d ON p.drug_id = d.id
|
|
WHERE p.tenant_id = $1 OR EXISTS (SELECT 1 FROM batches WHERE product_id = p.id AND tenant_id = $1) OR p.tenant_id IS NULL
|
|
`;
|
|
const res1 = await pool.query(query1, [actorId]);
|
|
console.log("Pharmacy Drugs stock:");
|
|
console.log(res1.rows);
|
|
|
|
// Inventory (InventoryService)
|
|
const query2 = `
|
|
SELECT p.brand_name, SUM(b.qty_on_hand) as sum_stock
|
|
FROM batches b
|
|
JOIN products p ON b.product_id = p.id
|
|
WHERE b.qty_on_hand > 0
|
|
AND b.expiry <= CURRENT_DATE + 3650
|
|
AND b.tenant_id = $1
|
|
GROUP BY p.brand_name
|
|
`;
|
|
const res2 = await pool.query(query2, [actorId]);
|
|
console.log("Inventory Stock:");
|
|
console.log(res2.rows);
|
|
|
|
process.exit();
|
|
}
|
|
|
|
test();
|