auth fix 5

This commit is contained in:
Kallesh B S 2025-09-27 17:56:39 +05:30
parent 59c51fb817
commit 7d27c9a0ff

View File

@ -206,29 +206,23 @@ export class CarnetApplicationService {
await client.query('BEGIN'); await client.query('BEGIN');
function escapePostgresString(str: string): string { function escapePostgresCompositeField(str: string): string {
if (str == null) return ''; if (str == null) return '';
return `"${str.replace(/\\/g, '\\\\').replace(/"/g, '""')}"`; return str.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
}
function escapePostgresValue(val: any): string {
if (val == null || val === '') return ''; // NULL or empty becomes empty string
if (typeof val === 'number') return String(val); // pass numbers as-is
return escapePostgresString(String(val)); // quote and escape strings
} }
const contactLiterals = body.P_GLTABLE.map(c => { const contactLiterals = body.P_GLTABLE.map(c => {
const fields = [ const fields = [
escapePostgresValue(c.ITEMNO), c.ITEMNO ?? '',
escapePostgresValue(c.ITEMDESCRIPTION), c.ITEMDESCRIPTION ?? '',
escapePostgresValue(c.ITEMVALUE), c.ITEMVALUE ?? '',
escapePostgresValue(c.NOOFPIECES), c.NOOFPIECES ?? '',
escapePostgresValue(c.ITEMWEIGHT), c.ITEMWEIGHT ?? '',
escapePostgresValue(c.ITEMWEIGHTUOM), c.ITEMWEIGHTUOM ?? '',
escapePostgresValue(c.GOODSORIGINCOUNTRY), c.GOODSORIGINCOUNTRY ?? '',
]; ].map(field => escapePostgresCompositeField(String(field))).join(',');
return `"(${fields.join(',')})"`; // ✅ double quotes for composite return `"(${fields})"`; // ✅ Wrap entire composite in double quotes
}); });
const pgArrayLiteral = `{${contactLiterals.join(',')}}`; const pgArrayLiteral = `{${contactLiterals.join(',')}}`;
@ -236,8 +230,10 @@ export class CarnetApplicationService {
const callProcQuery = ` const callProcQuery = `
CALL "CARNETSYS".carnetapplication_pkg_addgenerallistitems($1, $2::"CARNETSYS".gltable[], $3, $4) CALL "CARNETSYS".carnetapplication_pkg_addgenerallistitems($1, $2::"CARNETSYS".gltable[], $3, $4)
`; `;
await client.query(callProcQuery, [body.P_HEADERID, pgArrayLiteral, body.P_USERID, cursorName]); await client.query(callProcQuery, [body.P_HEADERID, pgArrayLiteral, body.P_USERID, cursorName]);
// 🚫 DON'T quote the cursor name in FETCH // 🚫 DON'T quote the cursor name in FETCH
const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`); const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`);