Skip to content

Commit

Permalink
feat(lock): adds sub-command to lock single time entries
Browse files Browse the repository at this point in the history
  • Loading branch information
Ephigenia committed Apr 19, 2019
1 parent 356c09b commit 38ec3e0
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
61 changes: 61 additions & 0 deletions source/mite-lock.js
Original file line number Diff line number Diff line change
@@ -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('<timeEntryId>')
.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();
}
1 change: 1 addition & 0 deletions source/mite.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 38ec3e0

Please sign in to comment.