Skip to content

Commit

Permalink
feat(amend): adds user-id option to change assigend user
Browse files Browse the repository at this point in the history
  • Loading branch information
Ephigenia committed Sep 1, 2020
1 parent 0825690 commit 8444405
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
9 changes: 8 additions & 1 deletion source/lib/auto-complete/completions/amend.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const {
getMyRecentTimeEntriesOptions,
getProjectOptions,
getServiceOptions,
getUserIdOptions,
removeAlreadyUsedOptions,
} = require('../helpers');

Expand All @@ -27,7 +28,11 @@ const defaults = [
},
{
name: '--service-id',
description: 'id of the service the entry should be assigned to'
description: 'id of the service the entry should be assigned to'
},
{
name: '--user-id',
description: 'id of the user that should get assigned'
}
];

Expand All @@ -49,6 +54,8 @@ module.exports = async ({ line, prev }) => {
return getProjectOptions({ archived: false });
case '--service-id':
return getServiceOptions({ archived: false });
case '--user-id':
return getUserIdOptions();
case '--duration':
return ['0\\:00'];
}
Expand Down
18 changes: 16 additions & 2 deletions source/mite-amend.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ has the required permissions to do it.`,
'--service-id <id>',
'the service id which should be set'
)
.option(
'--user-id <id>',
'change the user who owns the time-entry (requires admin account)'
)
.on('--help', () => console.log(`
Examples:
Expand Down Expand Up @@ -84,8 +88,11 @@ Examples:
Change the tracked time to 4 hours and 12 minutes
mite amend 12345678 --duration 4:12
Change the user of entry 81713
mite amend --user-id 128731 81713
Change the time and add 20 minutes
mite amend 12345678 --duration +4:12
mite amend 12345678 --duration +4:12
`));

const mite = miteApi(config.get());
Expand Down Expand Up @@ -137,6 +144,7 @@ async function getUpdatedTimeEntryData(program, note, timeEntry) {
...(program.date && { date_at: program.date }),
...(program.projectId && { project_id: program.projectId }),
...(program.serviceId && { service_id: program.serviceId }),
...(program.userId && { user_id: program.userId }),
};

// substract, add or set minutes directly using the --duration option
Expand All @@ -161,7 +169,13 @@ async function getUpdatedTimeEntryData(program, note, timeEntry) {
updateData.note = editorContent;
return updateData;
});
} else if (!note && !program.projectId && !program.serviceId && !program.duration) {
} else if (
!note &&
!program.projectId &&
!program.serviceId &&
!program.duration &&
!program.userId
) {
// ask for note only when no note was passed to cli
return inquireNote(updateData, updateData.note || timeEntry.note);
}
Expand Down

0 comments on commit 8444405

Please sign in to comment.