auth fix 8
This commit is contained in:
parent
570037c6d9
commit
8050870b0b
@ -365,33 +365,34 @@ 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, '""'); // PostgreSQL-compliant
|
||||||
}
|
|
||||||
|
|
||||||
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_COUNTRYTABLE.map(c => {
|
const contactLiterals = body.P_COUNTRYTABLE.map(c => {
|
||||||
const fields = [
|
const fields = [
|
||||||
escapePostgresValue(c.P_VISISTTRANSITIND), // integer
|
c.P_VISISTTRANSITIND ?? '',
|
||||||
escapePostgresValue(c.COUNTRYCODE), // varchar
|
c.COUNTRYCODE ?? '',
|
||||||
escapePostgresValue(c.NOOFTIMESENTLEAVE), // numeric
|
c.NOOFTIMESENTLEAVE ?? '',
|
||||||
];
|
].map(field => escapePostgresCompositeField(String(field))).join(',');
|
||||||
|
|
||||||
return `(${fields.join(',')})`; // composite literal without outer double quotes
|
return `"(${fields})"`; // ✅ wrap entire composite in double quotes
|
||||||
});
|
});
|
||||||
|
|
||||||
const pgArrayLiteral = `{${contactLiterals.join(',')}}`;
|
const pgArrayLiteral = `{${contactLiterals.join(',')}}`;
|
||||||
|
|
||||||
const callProcQuery = `
|
const callProcQuery = `
|
||||||
CALL "CARNETSYS".carnetapplication_pkg_addcountries($1, $2, $3::"CARNETSYS".carnetcountrytable[], $4, $5)
|
CALL "CARNETSYS".carnetapplication_pkg_addcountries($1, $2, $3::"CARNETSYS".carnetcountrytable[], $4, $5)
|
||||||
`;
|
`;
|
||||||
await client.query(callProcQuery, [body.P_HEADERID, body.P_USSETS, pgArrayLiteral, body.P_USERID, cursorName]);
|
|
||||||
|
await client.query(callProcQuery, [
|
||||||
|
body.P_HEADERID,
|
||||||
|
body.P_USSETS,
|
||||||
|
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}`);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user