diff --git a/README.md b/README.md index 9ba3281..be71b77 100644 --- a/README.md +++ b/README.md @@ -62,8 +62,8 @@ USAGE OPTIONS -b, --debug Debug - Exibe mais informações na execução - -c, --company=company (required) [default: ahgora] ID da empresa no sistema de ponto - -d, --date=date [default: 2020-09-27] Data relacionada a consulta de horas no padrão YYYY-MM-DD + -c, --company=company (required) ID da empresa no sistema de ponto + -d, --date=date [default: 2020-10-03] Data relacionada a consulta de horas no padrão YYYY-MM-DD -h, --help show CLI help -j, --journeytime=journeytime [default: 08:00] Quantidade de horas a serem trabalhadas por dia -p, --password=password (required) Senha do usuário no sistema @@ -76,7 +76,7 @@ EXAMPLES $ my-worktime check -u 321 -p 123 -s ahgora -c a22 -j 08:48 -d 2020-09-23 ``` -_See code: [src/commands/check.ts](https://github.com/carloshpds/my-worktime/blob/v1.0.2/src/commands/check.ts)_ +_See code: [src/commands/check.ts](https://github.com/carloshpds/my-worktime/blob/v1.1.0/src/commands/check.ts)_ ## `my-worktime help [COMMAND]` diff --git a/package-lock.json b/package-lock.json index a883044..504bc66 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "my-worktime", - "version": "1.0.2", + "version": "1.1.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 1b2a027..f7d59e3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "my-worktime", - "version": "1.0.2", + "version": "1.1.0", "author": "Carlos Henrique https://github.com/carloshpds", "contributors": [ "Matheus Soares https://github.com/Matheusss", diff --git a/src/commands/check.ts b/src/commands/check.ts index c3603bd..6591619 100644 --- a/src/commands/check.ts +++ b/src/commands/check.ts @@ -6,6 +6,8 @@ import Ahgora from '../providers/Ahgora' import WorktimeProvider from '../providers/WorktimeProvider' import * as ora from 'ora' import * as chalk from 'chalk' +import { DATE_FORMAT, DATE_REGEXP } from '../utils/dateFormat' +import {CLIError} from '@oclif/errors' export default class CheckCommand extends Command { static description = 'Checks your worktime' @@ -20,8 +22,8 @@ export default class CheckCommand extends Command { help: flags.help({char: 'h'}), user: flags.string({char: 'u', description: 'ID do usuário no sistema de ponto', required: true, env: 'MW_USER'}), password: flags.string({char: 'p', description: 'Senha do usuário no sistema', required: true, env: 'MW_PASS'}), - system: flags.string({char: 's', description: 'Nome do sistema de ponto', default: 'ahgora'}), - company: flags.string({char: 'c', description: 'ID da empresa no sistema de ponto', required: true, default: 'ahgora'}), + system: flags.string({char: 's', description: 'Nome do sistema de ponto', default: 'ahgora', env: 'MW_SYSTEM'}), + company: flags.string({char: 'c', description: 'ID da empresa no sistema de ponto', required: true, env: 'MW_COMPANY'}), date: flags.string({char: 'd', description: 'Data relacionada a consulta de horas no padrão YYYY-MM-DD', default: moment().format('YYYY-MM-DD')}), debug: flags.boolean({char: 'b', description: 'Debug - Exibe mais informações na execução', default: false}), journeytime: flags.string({char: 'j', description: 'Quantidade de horas a serem trabalhadas por dia', default: '08:00'}), @@ -31,19 +33,24 @@ export default class CheckCommand extends Command { const {flags} = this.parse(CheckCommand) const options: Partial = { - userId: flags.user || process.env.WORKTIME_USER, - password: flags.password || process.env.WORKTIME_PASSWORD, - systemId: flags.system || process.env.WORKTIME_SYSTEM, - companyId: flags.company || process.env.WORKTIME_COMPANY, - date: flags.date || process.env.WORKTIME_DATE, + userId: flags.user, + password: flags.password, + systemId: flags.system, + companyId: flags.company, + date: flags.date, debug: flags.debug, - journeyTime: flags.journeytime || process.env.WORKTIME_JOURNEYTIME, + journeyTime: flags.journeytime, } if (!options.userId || !options.password || !options.systemId || !options.companyId) { this.log('Não foi possível recuperar as credenciais do sistema de ponto') - this.log('Você pode definir as variáveis de ambiente "WORKTIME_USER" e "WORKTIME_PASSWORD"') - this.log('Use worktime -h para informar as credencias via linha de comando.') + this.log('Você pode definir as variáveis de ambiente "MW_USER" e "MW_PASS"') + this.log('Use my-worktime -h para informar as credencias via linha de comando.') + return + } + + if(!DATE_REGEXP.test(options.date as string) || !moment().isValid()){ + this.error(chalk.red(`Este formato de data é inválido, utilize o padrão ${DATE_FORMAT}`)) return } @@ -100,10 +107,17 @@ export default class CheckCommand extends Command { return `${markOnConsole}` }) + let workedMinutesUntilNowOnConsole = ClockHelper.humanizeMinutesToClock(worktimeDayResume.workedMinutesUntilNow) + + if(worktimeDayResume.isMissingPairMark){ + workedMinutesUntilNowOnConsole = chalk.yellow(workedMinutesUntilNowOnConsole) + } + console.log('') console.log(`🔢 Batidas: ${marksToConsole.join(' ')}`) + console.log(`⏸ Horas de pausas: ${ClockHelper.humanizeMinutesToClock(worktimeDayResume.breakMinutes)}`) console.log(`🆗 Horas registradas: ${ClockHelper.humanizeMinutesToClock(worktimeDayResume.registeredWorkedMinutes)}`) - console.log(`⏺ Horas trabalhadas até este momento: ${ClockHelper.humanizeMinutesToClock(worktimeDayResume.workedMinutesUntilNow)}`) + console.log(`⏺ Horas trabalhadas até este momento: ${workedMinutesUntilNowOnConsole}`) console.log('') } } diff --git a/src/utils/dateFormat.ts b/src/utils/dateFormat.ts new file mode 100644 index 0000000..2831dcd --- /dev/null +++ b/src/utils/dateFormat.ts @@ -0,0 +1,4 @@ + +export const DATE_REGEXP = /^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$/ + +export const DATE_FORMAT = 'YYYY-MM-DD' \ No newline at end of file