UNPKG

@accounter/israeli-vat-scraper

Version:
44 lines (43 loc) 1.64 kB
import { newPageByMonth } from '../utils/browser-util.js'; import { getReportExpansionFixes } from '../utils/evaluation-functions.js'; import { waitForSelectorPlus } from '../utils/page-util.js'; export class MonthFixesHandler { config; prompt; location; index; page = null; constructor(config, prompt, location, index) { this.config = config; this.prompt = prompt; this.location = [...location, 'Fixes']; this.index = index; } handle = async (logger) => { this.prompt.update(this.location, 'Fetching...', logger); try { this.page = await newPageByMonth(this.config.visibleBrowser, this.location[0], this.index, logger); const button = await this.page .waitForSelector('#ContentUsersPage_lnkHeshboniotBeforeTikun') .catch(() => { return; }); if (!button) { this.prompt.update(this.location, 'Done - no data found', logger); return undefined; } await button.click(); // get fixes const fixesTable = await waitForSelectorPlus(this.page, '#ContentUsersPage_DgIskNosfu', logger); const fixes = (await fixesTable?.evaluate(getReportExpansionFixes)) ?? []; this.page.browser().close(); this.prompt.update(this.location, 'Done', logger); return fixes; } catch (e) { this.prompt.addError(this.location, e?.message || e, logger); this.page?.browser().close(); return undefined; } }; }