@craibuc/adp-workforce-now
Version:
Node.js library to interact with ADP's Workforce Now API.
86 lines (67 loc) • 2.79 kB
JavaScript
(async() => {
require('dotenv').config()
const Adp = require('./lib')
try {
const client = new Adp.Client(process.env.ADP_CERTIFICATE, process.env.ADP_PRIVATE_KEY)
const credentials = await client.authenticate(process.env.ADP_CLIENT_ID, process.env.ADP_CLIENT_SECRET)
process.env.ADP_ACCESS_TOKEN = credentials.access_token
const associateOID = 'G3BJDMRVTTP9GTMX'
// let me = await client.worker.one(associateOID)
// console.log('legalName',me.person.legalName.formattedName)
// console.log('positionID',me.workAssignments[0].positionID)
const hire = await client.worker.hire({
givenName: 'Duck',
familyName: 'Donald',
birthDate: '1900-01-01',
genderCode: 'M',
ssn: '222-33-4444',
lineOne: '123 Main Street',
lineTwo: '#1',
cityName: 'Minneapolis',
stateCode: 'MN',
postalCode: '55555',
hireDate: new Date().toISOString().split('T')[0],
payrollGroupCode: 'K4P'
});
console.log('hire',hire)
// const terminate = await client.worker.terminate({
// workAssignmentID: me.workAssignments[0].positionID,
// terminationDate: new Date().toISOString().split('T')[0],
// comments: 'testing',
// reasonCode: 'T'
// });
// const rehire = await client.worker.rehire({
// associateOID: associateOID,
// rehireDate: new Date().toISOString().split('T')[0],
// effectiveDate: new Date().toISOString().split('T')[0],
// reasonCode: 'IMPORT'
// });
// all workers
// let workers = await client.worker.all()
// workers.forEach(w => {
// console.log(w.person.legalName.formattedName)
// });
// let ssn = workers.filter( w => w.person.governmentIDs[0].idValue == process.env.VALID_WORKER_SSN)[0]
// console.log('me',ssn)
// console.log('legalName',ssn.person.legalName.formattedName)
// let meta = await client.worker.hire_meta()
// console.log('meta',meta)
}
catch (e) {
if (e instanceof Adp.BadRequestError) {
console.log(`A: ${e.name} - ${e.message}`)
}
else if (e instanceof Adp.ForbiddenError) {
console.log(`B: ${e.name} - ${e.message}`)
}
else if (e instanceof Adp.NotFoundError) {
console.log(`C: ${e.name} - ${e.message}`)
}
else if (e instanceof Adp.UnauthorizedError) {
console.log(`D: ${e.name} - ${e.message}`)
}
else {
console.log(`E: ${e.name} - ${e.message}`)
}
}
})()