Refactor getAllExecutorNames function to accept sourceSheet as a parameter, ensuring proper data retrieval and enhancing error handling for empty sheets in completed tasks report.

This commit is contained in:
Dmitriy_Kravchenko 2026-10-20 16:03:55 +03:00
parent 157f452b60
commit fdc95aeee0
1 changed files with 4 additions and 3 deletions

View File

@ -74,8 +74,9 @@ function findSingleTodayReport(prefix: string) {
return found[0];
}
function getAllExecutorNames(): any[] {
const sourceSheet = getSourceSheet();
function getAllExecutorNames(sourceSheet: GoogleAppsScript.Spreadsheet.Sheet): any[] {
if (!sourceSheet) return [];
const dataRange = sourceSheet.getDataRange();
const sourceSheetHeader = sourceSheet.getRange(1, 1, 1, dataRange.getNumColumns()).getValues()[0];
const executorColumnIndex = sourceSheetHeader.indexOf('Исполнитель');
@ -125,7 +126,7 @@ function loadCompletedTasks(afterDate: Date) {
throw new Error('На листе выгрузки завершенных задач не найдены колонки: ' + missingColumns.join(', '));
}
const performerNames = getAllExecutorNames().map(name => String(name ?? '').trim()).filter(Boolean);
const performerNames = getAllExecutorNames(sheet).map(name => String(name ?? '').trim()).filter(Boolean);
const result = new Map<string, any[]>();
performerNames.forEach(name => result.set(name, []));