From 38ec3e0a67263746a7f73c8b0725cfe4ad61caa8 Mon Sep 17 00:00:00 2001 From: Ephigenia Date: Fri, 19 Apr 2019 12:28:10 +0200 Subject: [PATCH] feat(lock): adds sub-command to lock single time entries --- source/mite-lock.js | 61 +++++++++++++++++++++++++++++++++++++++++++++ source/mite.js | 1 + 2 files changed, 62 insertions(+) create mode 100644 source/mite-lock.js diff --git a/source/mite-lock.js b/source/mite-lock.js new file mode 100644 index 0000000..f806f95 --- /dev/null +++ b/source/mite-lock.js @@ -0,0 +1,61 @@ +#!/usr/bin/env node +'use strict'; + +const program = require('commander'); +const miteApi = require('mite-api'); +const util = require('util'); + +const pkg = require('./../package.json'); +const config = require('./config.js'); + +program + .version(pkg.version) + .description( + 'Locks a specific time-entry identified by it’s id. ' + + 'The time-entry must either be owned by the requesting user or the ' + + 'requesting user must be an admin or owner. In that case the time entry ' + + 'can only be unlocked by an admin or owner.', + // object hash containing description of arguments + { + timeEntryId: 'The id of the time entry which should be locked' + }) + .arguments('') + .option( + '--force', + 'bypass user id or role restrictions as a admin or owner' + ) + .on('--help', function() { + console.log(` + Examples: + + Lock a single entry identified by it’s id: + $ mite delete 1283761 + + Lock multiple entries selected by using mite list: + $ mite list this_month --search="query" --columns id --format=text | xargs -0 mite lock +`); + }) + .action((timeEntryId) => { + const mite = miteApi(config.get()); + + const data = { + locked: true + }; + if (program.force) { + data.force = program.force; + } + return util.promisify(mite.updateTimeEntry)(timeEntryId, data) + .then(() => { + console.log('Successfully locked time entry (id: %s)', timeEntryId); + }) + .catch(err => { + console.error(err); + process.exit(0); + }); + }) + .parse(process.argv); + +if (!program.args.length) { + program.help(); + process.exit(); +} diff --git a/source/mite.js b/source/mite.js index 613b8cc..aecdb38 100755 --- a/source/mite.js +++ b/source/mite.js @@ -18,6 +18,7 @@ program .alias('ls') .alias('status') .alias('st') + .command('lock', 'lock a single time entry') .command('new', 'create a new time entry') .alias('create') .command('open', 'open the given time entry in browser')