auth fix 8
This commit is contained in:
parent
570037c6d9
commit
8050870b0b
@ -365,33 +365,34 @@ export class CarnetApplicationService {
|
||||
|
||||
await client.query('BEGIN');
|
||||
|
||||
function escapePostgresString(str: string): string {
|
||||
function escapePostgresCompositeField(str: string): string {
|
||||
if (str == null) return '';
|
||||
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
|
||||
return str.replace(/\\/g, '\\\\').replace(/"/g, '""'); // PostgreSQL-compliant
|
||||
}
|
||||
|
||||
const contactLiterals = body.P_COUNTRYTABLE.map(c => {
|
||||
const fields = [
|
||||
escapePostgresValue(c.P_VISISTTRANSITIND), // integer
|
||||
escapePostgresValue(c.COUNTRYCODE), // varchar
|
||||
escapePostgresValue(c.NOOFTIMESENTLEAVE), // numeric
|
||||
];
|
||||
c.P_VISISTTRANSITIND ?? '',
|
||||
c.COUNTRYCODE ?? '',
|
||||
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 callProcQuery = `
|
||||
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
|
||||
const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user