Skip to content

Commit

Permalink
Update Task
Browse files Browse the repository at this point in the history
  • Loading branch information
ingalls committed Jun 14, 2024
1 parent 1fa97ed commit 15865d0
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default class Task extends ETL {
}

async controlLogin(layer: any): Promise<Number[]> {

Check warning on line 26 in task.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type

Check failure on line 26 in task.ts

View workflow job for this annotation

GitHub Actions / test

Don't use `Number` as a type. Use number instead
console.error('ok - Attempting Login');
const loginForm = new FormData();
loginForm.append('operation', 'login');
loginForm.append('post_data', JSON.stringify({
Expand Down Expand Up @@ -59,10 +60,13 @@ export default class Task extends ETL {

async control(): Promise<void> {
const layer = await this.fetchLayer();

let loginAttempted = false;

let filteredAgencies: Number[] = [];

Check failure on line 66 in task.ts

View workflow job for this annotation

GitHub Actions / test

Don't use `Number` as a type. Use number instead
if (!layer.environment.Token || !Array.isArray(layer.environment.Agencies) || !layer.environment.Agencies.length) {
filteredAgencies = await this.controlLogin(layer);
loginAttempted = true;
}

if (Array.isArray(layer.environment.Agencies) && layer.environment.Agencies.length) {
Expand All @@ -77,7 +81,8 @@ export default class Task extends ETL {
};

let errs: Error[] = [];

Check failure on line 83 in task.ts

View workflow job for this annotation

GitHub Actions / test

'errs' is never reassigned. Use 'const' instead
for (const agency of filteredAgencies) {
for (let i = 0; i < filteredAgencies.length; i++) {
const agency = filteredAgencies[i];
console.error(`ok - getting alerts from ${agency}`);

try {
Expand Down Expand Up @@ -105,7 +110,11 @@ export default class Task extends ETL {
}
});

if (loginAttempted) throw new Error('Login Attempted and bad response');

await this.controlLogin(layer)
loginAttempted = true;
i--;
continue;
}

Expand All @@ -117,6 +126,13 @@ export default class Task extends ETL {
)

if (alerts.result === 'error') {
if (!loginAttempted && alerts.message === 'Please log in') {
await this.controlLogin(layer);
loginAttempted = true;
i--;
continue;
}

throw new Error(alerts.message);
}

Expand Down

0 comments on commit 15865d0

Please sign in to comment.