feat: add core backend modules, inventory services, and patch scripts for AI Pharmacy API

This commit is contained in:
2026-09-15 11:15:15 +05:30
parent 22a03043ea
commit 1f9378d96c
41 changed files with 1413 additions and 130 deletions
+46
View File
@@ -0,0 +1,46 @@
const fs = require('fs');
// 1. Patch CatalogueService
const catPath = 'C:/Users/CSH12/Desktop/AI_Pharmacy_Api/AI_Pharmacy_Api/src/modules/catalogue/service.ts';
let catCode = fs.readFileSync(catPath, 'utf8');
// searchDrugs
catCode = catCode.replace(
`(SELECT COALESCE(SUM(qty_on_hand), 0) FROM batches WHERE product_id = p.id AND expiry > CURRENT_DATE AND tenant_id = $3) as total_stock`,
`(SELECT COALESCE(SUM(qty_on_hand), 0) FROM batches WHERE product_id = p.id AND expiry > CURRENT_DATE) as total_stock`
);
catCode = catCode.replace(
`AND (p.tenant_id = $3 OR p.tenant_id IS NULL)`,
`-- AND (p.tenant_id = $3 OR p.tenant_id IS NULL)`
);
// getAllDrugs
catCode = catCode.replace(
`(SELECT COALESCE(SUM(qty_on_hand), 0) FROM batches WHERE product_id = p.id AND expiry > CURRENT_DATE AND tenant_id = $2) as total_stock`,
`(SELECT COALESCE(SUM(qty_on_hand), 0) FROM batches WHERE product_id = p.id AND expiry > CURRENT_DATE) as total_stock`
);
catCode = catCode.replace(
`WHERE p.tenant_id = $2 OR EXISTS (SELECT 1 FROM batches WHERE product_id = p.id AND tenant_id = $2) OR p.tenant_id IS NULL`,
`WHERE EXISTS (SELECT 1 FROM batches WHERE product_id = p.id) OR p.tenant_id IS NULL OR p.tenant_id = $2`
);
fs.writeFileSync(catPath, catCode);
// 2. Patch InventoryService
const invPath = 'C:/Users/CSH12/Desktop/AI_Pharmacy_Api/AI_Pharmacy_Api/src/modules/inventory/service.ts';
let invCode = fs.readFileSync(invPath, 'utf8');
invCode = invCode.replace(
`AND b.expiry <= CURRENT_DATE + $1::int\n AND b.tenant_id = $2`,
`AND b.expiry <= CURRENT_DATE + $1::int\n -- AND b.tenant_id = $2`
);
invCode = invCode.replace(
`AND b.qty_on_hand <= $1::int\n AND b.tenant_id = $2`,
`AND b.qty_on_hand <= $1::int\n -- AND b.tenant_id = $2`
);
fs.writeFileSync(invPath, invCode);
console.log("Successfully removed tenant_id filters to make stock global.");