Skip to content

Commit

Permalink
feat: Support update user tracking codes (#489)
Browse files Browse the repository at this point in the history
* feat: Support update user tracking codes

* update codes

* fix typo
  • Loading branch information
congminh1254 committed Jan 31, 2024
1 parent 56badcd commit e3a24f7
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/users.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ OPTIONS
--timezone=timezone The user's timezone. Input format follows
tz database timezones
--tracking-codes=tracking-codes Comma-separated list of key-value pairs to associate with the user. Format is name=value,name=value
EXAMPLE
box users:create "John Doe" [email protected]
Expand Down Expand Up @@ -598,6 +599,7 @@ OPTIONS
--timezone=timezone The user's timezone. Input format follows
tz database timezones
--tracking-codes=tracking-codes Comma-separated list of key-value pairs to associate with the user. Format is name=value,name=value
EXAMPLE
box users:update 33333 --status inactive
Expand Down
14 changes: 14 additions & 0 deletions src/commands/users/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ class UsersCreateCommand extends BoxCommand {
if (flags['external-id']) {
options.external_app_user_id = flags['external-id'];
}
if (flags['tracking-codes']) {
options.tracking_codes = flags['tracking-codes'];
}

if (flags['app-user']) {
user = await this.client.enterprise.addAppUser(args.name, options);
Expand Down Expand Up @@ -146,6 +149,17 @@ UsersCreateCommand.flags = {
]
}),
timezone: flags.string({ description: 'The user\'s timezone. Input format follows tz database timezones' }),
'tracking-codes': flags.string({
description: 'Comma-separated list of key-value pairs to associate with the user. Format is name=value,name=value',
parse: input => input.split(',').map(pair => {
const [name, value] = pair.split('=');
return {
type: 'tracking_code',
name,
value
};
}),
}),
};

UsersCreateCommand.args = [
Expand Down
14 changes: 14 additions & 0 deletions src/commands/users/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ class UsersUpdateCommand extends BoxCommand {
if (flags['external-id']) {
updates.external_app_user_id = flags['external-id'];
}
if (flags['tracking-codes']) {
updates.tracking_codes = flags['tracking-codes'];
}

let user = await this.client.users.update(args.id, updates);
await this.output(user);
Expand Down Expand Up @@ -147,6 +150,17 @@ UsersUpdateCommand.flags = {
'external-id': flags.string({
description: 'External ID for app users',
}),
'tracking-codes': flags.string({
description: 'Comma-separated list of key-value pairs to associate with the user. Format is name=value,name=value',
parse: input => input.split(',').map(pair => {
const [name, value] = pair.split('=');
return {
type: 'tracking_code',
name,
value
};
}),
}),
};

UsersUpdateCommand.args = [
Expand Down
34 changes: 34 additions & 0 deletions test/commands/users.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,23 @@ describe('Users', () => {
'--timezone=America/Los_Angeles',
{timezone: 'America/Los_Angeles'}
],
'tracking codes': [
'--tracking-codes=name1=value1,name2=value2',
{
tracking_codes: [
{
type: 'tracking_code',
name: 'name1',
value: 'value1',
},
{
type: 'tracking_code',
name: 'name2',
value: 'value2',
},
],
}
]
}, function(flag, body) {

test
Expand Down Expand Up @@ -888,6 +905,23 @@ describe('Users', () => {
'external ID flag': [
'--external-id=foo',
{external_app_user_id: 'foo'}
],
'tracking codes': [
'--tracking-codes=name1=value1,name2=value2',
{
tracking_codes: [
{
type: 'tracking_code',
name: 'name1',
value: 'value1',
},
{
type: 'tracking_code',
name: 'name2',
value: 'value2',
},
],
}
]
}, function(flag, body) {

Expand Down

0 comments on commit e3a24f7

Please sign in to comment.