/** * @license * Copyright 2024 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ function doGet(e) { const name = e.parameter.name; if (!name) { const errorResponse = { error: "未提供查詢姓名 (name 參數)。" }; return ContentService.createTextOutput( JSON.stringify(errorResponse) ).setMimeType(ContentService.MimeType.JSON); } const result = getCheckInStatus(name); return ContentService.createTextOutput(JSON.stringify(result)).setMimeType( ContentService.MimeType.JSON ); } function getCheckInStatus(name) { try { const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("彙總表"); if (!sheet) { throw new Error("找不到名為 '彙總表' 的工作表。"); } const data = sheet.getDataRange().getValues(); const headers = data[0]; const nameColumnIndex = headers.indexOf("姓名"); if (nameColumnIndex === -1) { throw new Error("在 '彙總表' 中找不到 '姓名' 欄位。"); } for (let i = 1; i < data.length; i++) { const row = data[i]; if (row[nameColumnIndex].trim() === name.trim()) { const checkInData = {}; for (let j = 1; j < headers.length; j++) { const date = headers[j]; if (!date) continue; const status = row[j]; checkInData[date] = status; } return { found: true, name: row[nameColumnIndex], data: checkInData, }; } } return { found: false }; } catch (e) { return { error: e.toString() }; } }