61 lines
1.7 KiB
TypeScript
61 lines
1.7 KiB
TypeScript
import { pool } from './src/db/pool';
|
|
|
|
async function testGRN() {
|
|
console.log("1. Requesting Token...");
|
|
const tokenResponse = await fetch("http://localhost:8080/v1/auth/token", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({
|
|
grant_type: "client_credentials",
|
|
client_id: "jayam_web_ai",
|
|
client_secret: "my_secret_key"
|
|
})
|
|
});
|
|
const tokenData = await tokenResponse.json();
|
|
const token = tokenData.access_token;
|
|
|
|
if (!token) {
|
|
console.error("No token received", tokenData);
|
|
return;
|
|
}
|
|
|
|
const batchNo = "BAT-" + Date.now();
|
|
|
|
console.log(`2. Sending GRN for Losar 50 (prd_4410), Batch: ${batchNo}...`);
|
|
const grnResponse = await fetch("http://localhost:8080/v1/inventory/grn", {
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
"Authorization": `Bearer ${token}`,
|
|
"X-Actor-Id": "usr_ph_admin",
|
|
"idempotency-key": "idemp-" + Date.now()
|
|
},
|
|
body: JSON.stringify({
|
|
lines: [
|
|
{
|
|
batch_no: batchNo,
|
|
product_id: "prd_4410",
|
|
expiry: "2027-12-31",
|
|
qty: 500,
|
|
purchase_price: "50.00"
|
|
}
|
|
]
|
|
})
|
|
});
|
|
|
|
const grnData = await grnResponse.json();
|
|
console.log("GRN Response Status:", grnResponse.status);
|
|
console.log("GRN Response Data:", grnData);
|
|
|
|
console.log("\n3. Verifying Database...");
|
|
const batchRes = await pool.query("SELECT * FROM batches WHERE batch_no = $1", [batchNo]);
|
|
console.log("Batch in DB:", batchRes.rows);
|
|
|
|
const stockMoveRes = await pool.query("SELECT * FROM stock_movements WHERE batch_no = $1", [batchNo]);
|
|
console.log("Stock Movements in DB:", stockMoveRes.rows);
|
|
|
|
process.exit(0);
|
|
}
|
|
|
|
testGRN();
|