diff --git a/functions/src/dooraccess/essl.ts b/functions/src/dooraccess/essl.ts index ff26ad3..5e49730 100644 --- a/functions/src/dooraccess/essl.ts +++ b/functions/src/dooraccess/essl.ts @@ -207,10 +207,10 @@ function createGetEmployeePunchLogsRequest(username: string, password: string, - cosqclient - 3bbb58d5 - 1 - 2025-05-24 + ${escapeXml(username)} + ${escapeXml(password)} + ${escapeXml(employeeCode)} + ${escapeXml(attendanceDate)} `; @@ -232,9 +232,15 @@ function parseGetEmployeePunchLogsResponse(soapResponse: string, attendanceDate: const xmlDoc = parser.parseFromString(soapResponse, "text/xml"); const currentElement = xmlDoc.documentElement.firstChild as HTMLElement; const resultText = currentElement.textContent; + if (!resultText || resultText.trim() === '' || resultText.trim() === ';;' || resultText.trim() === ';') { + return []; + } const punchLogs: Date[] = []; - const parts = resultText!.split(';'); + const parts = resultText.split(';'); for (const part of parts) { + if (!part || part.trim() === '') { + continue; + } try { const logDateTime = new Date(part); if (isNaN(logDateTime.getTime())) { @@ -245,8 +251,12 @@ function parseGetEmployeePunchLogsResponse(soapResponse: string, attendanceDate: try { const timeParts = part.split(','); for (const timePart of timeParts) { + if (!timePart || timePart.trim() === '') { + continue; + } + try { - const logDateTime = createDateFromTime(rootDate, timePart); + const logDateTime = createDateFromTime(rootDate, timePart.trim()); punchLogs.push(logDateTime); } catch { continue; @@ -261,6 +271,7 @@ function parseGetEmployeePunchLogsResponse(soapResponse: string, attendanceDate: return sortedLogs; } + async function sendSoapRequest(soapRequest: string, endpoint: string) { try { const headers: any = {