NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

/* jshint esversion: 8 */
/* istanbul ignore next */
const EmploymentNavigator = require('../employment.navigator');
const CustomMfaHandler = require('../mfa/emp_1xAN3ybyQbDlCPxZxbFTW1TOW2p.custom.handler');
const logger = require('../../lib/common/log').logger;
const PuppeteerHelper = require('../../lib/helper/puppeteer.helper');
const ItemIterator = require('../../lib/iterator/item-iterator');
const EMPLOYMENT_ITEM_TYPE = require('../../lib/common/constants').employmentItemTypes;
const Controller = require('../../lib/controller');
const ExtractorClassifier = require('../../lib/extractor/extractor-classifier');
const DownloadUtils = require('../../lib/utils/download-utils');

/**
* Defense Finance and Accounting Service
*/
// MFA is not tested
class Emp_1xAN3ybyQbDlCPxZxbFTW1TOW2p extends EmploymentNavigator {

async is_login_page(page) {

logger.debug('Emp_1xAN3ybyQbDlCPxZxbFTW1TOW2p -> is_login_page - started');

this.ph = new PuppeteerHelper(page);

const is_mfa_exist = await this.has_mfa(page);

if (is_mfa_exist) return false;

return await super.is_login_page(page);
}


async has_mfa(page) {
logger.debug('Emp_1xAN3ybyQbDlCPxZxbFTW1TOW2p -> has_mfa - started');

let customHandler = new CustomMfaHandler(this.session_id);

return await customHandler.has_mfa(page);
}

async navigate_to_paystub_file(page) {
logger.debug('Emp_1xAN3ybyQbDlCPxZxbFTW1TOW2p -> navigate_to_paystub_file - started');

this.ph = new PuppeteerHelper(page);

const paystub_url = 'https://mypay.dfas.mil/#/active/les';
const paystub_elements = ['//*[contains(text(), "Leave and Earnings Statement")]'];

await this.ph.goto(paystub_url, page, ['load'], 20000);

await this.ph.waitForXPath(elements[0], page);

await this.ph.waitForXpath(paystub_elements[0], page);

return page;
}

async get_iterator(page, type) {
if (type === EMPLOYMENT_ITEM_TYPE.paystub_file) {
return new Emp_1xAN3ybyQbDlCPxZxbFTW1TOW2p_Paystub_Iterator(page);
}

return await super.get_iterator(page, type);
}

async get_extractor(page, type) {
if (type === EMPLOYMENT_ITEM_TYPE.paystub_file) {
return new ExtractorClassifier(page).get_extractor('pdf', type);
}
return await super.get_extractor(page, type);
}
}

class Emp_1xAN3ybyQbDlCPxZxbFTW1TOW2p_Paystub_Iterator extends ItemIterator {

constructor(page) {
super(page);
this.elements = ['select[aria-label="LES History Select”]', 'button[class*="print-btn"]', 'cr-icon-button[id="download"]'];
}

async init() {
this.paystubs = await this.ph.getSelectOptions(this.elements[0], this.page);
this.paystubs = this.paystubs.filter(p => p.value !== '');

if (this.paystubs.length === 0) {
throw Controller.getError('general', 'notAvailable', EMPLOYMENT_ITEM_TYPE.paystub_file);
}

logger.info(`Paystubs Select Options => ${JSON.stringify(this.paystubs)}`);

this.num_of_items = this.paystubs.length;

logger.info(`Total Paystubs => ${this.num_of_items}`);

this.du = new DownloadUtils();
this.downloadPath = this.du.getDownloadPath(this.session_id);
await this.du.createDownloadDir(this.session_id);
await this.ph.downloadFileInitializer(this.downloadPath, this.page);
}

async removeDownloadedFiles() {
if (this.index > 0 && (this.num_of_items > this.index)) {
let files = await this.du.getDownloadFilesPath(this.session_id);
if (files.length > 0) {
await this.du.emptyDownloadDir(this.session_id);
}
}
}

async next() {
await this.removeDownloadedFiles();

//Select Month
await this.ph.waitForSelector(this.elements[0], this.page);
await this.ph.performSingleSelect(this.elements[0], this.paystubs[this.index++].value, this.page);

//click on Printer Friendly LES
try {
await this.ph.performClickAndNavigation(this.elements[1], this.page, {
timeout: 15000,
waitUntil: ['load']
});
} catch (e) {
logger.warn(e);
}

// click on download button
await this.ph.waitForSelector(this.elements[2], this.page);
try {
await this.ph.performClickAndNavigation(this.elements[2], this.page);
} catch (e) {
logger.warn(e);
}

let files = await this.du.getDownloadFilesPath(this.session_id);
if (files.length === 0) {
throw new Error('File is not available in the download path');
}

this.session.extract_file_path = files[0];
logger.debug(`session.extract_path => ${this.session.extract_file_path}`);


return this.page;
}

hasNext() {
return (this.index < this.num_of_items);
}
}

module.exports = Emp_1xAN3ybyQbDlCPxZxbFTW1TOW2p;
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.