Skip to content

Commit 83b1049

Browse files
google-labs-jules[bot]jpoehneltgemini-code-assist[bot]
authored
fix(adminSDK): resolve type errors (#584)
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: Justin Poehnelt <jpoehnelt@google.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent 8520470 commit 83b1049

File tree

3 files changed

+50
-41
lines changed

3 files changed

+50
-41
lines changed

adminSDK/directory/quickstart.gs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,25 @@ function listUsers() {
2424
maxResults: 10,
2525
orderBy: 'email'
2626
};
27-
try {
28-
const response = AdminDirectory.Users.list(optionalArgs);
29-
const users = response.users;
30-
if (!users || users.length === 0) {
31-
console.log('No users found.');
32-
return;
33-
}
34-
// Print the list of user's full name and email
35-
console.log('Users:');
36-
for (const user of users) {
37-
console.log('%s (%s)', user.primaryEmail, user.name.fullName);
27+
if (!AdminDirectory || !AdminDirectory.Users) {
28+
throw new Error('Enable the AdminDirectory Advanced Service.');
29+
}
30+
const response = AdminDirectory.Users.list(optionalArgs);
31+
const users = response.users;
32+
if (!users || users.length === 0) {
33+
console.log('No users found.');
34+
return;
35+
}
36+
// Print the list of user's full name and email
37+
console.log('Users:');
38+
for (const user of users) {
39+
if (user.primaryEmail) {
40+
if (user.name?.fullName) {
41+
console.log('%s (%s)', user.primaryEmail, user.name.fullName);
42+
} else {
43+
console.log('%s', user.primaryEmail);
44+
}
3845
}
39-
} catch (err) {
40-
// TODO (developer)- Handle exception from the Directory API
41-
console.log('Failed with error %s', err.message);
4246
}
4347
}
4448
// [END admin_sdk_directory_quickstart]

adminSDK/reports/quickstart.gs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,23 @@ function listLogins() {
2424
const optionalArgs = {
2525
maxResults: 10
2626
};
27-
try {
28-
const response = AdminReports.Activities.list(userKey, applicationName, optionalArgs);
29-
const activities = response.items;
30-
if (!activities || activities.length === 0) {
31-
console.log('No logins found.');
32-
return;
33-
}
34-
// Print login events
35-
console.log('Logins:');
36-
for (const activity of activities) {
27+
if (!AdminReports || !AdminReports.Activities) {
28+
throw new Error('Enable the AdminReports Advanced Service.');
29+
}
30+
const response = AdminReports.Activities.list(
31+
userKey, applicationName, optionalArgs);
32+
const activities = response.items;
33+
if (!activities || activities.length === 0) {
34+
console.log('No logins found.');
35+
return;
36+
}
37+
// Print login events
38+
console.log('Logins:');
39+
for (const activity of activities) {
40+
if (activity.id?.time && activity.actor?.email && activity.events?.[0]?.name) {
3741
console.log('%s: %s (%s)', activity.id.time, activity.actor.email,
3842
activity.events[0].name);
3943
}
40-
} catch (err) {
41-
// TODO (developer)- Handle exception from the Report API
42-
console.log('Failed with error %s', err.message);
4344
}
4445
}
4546
// [END admin_sdk_reports_quickstart]

adminSDK/reseller/quickstart.gs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,25 @@ function listSubscriptions() {
2222
const optionalArgs = {
2323
maxResults: 10
2424
};
25-
try {
26-
const response = AdminReseller.Subscriptions.list(optionalArgs);
27-
const subscriptions = response.subscriptions;
28-
if (!subscriptions || subscriptions.length === 0) {
29-
console.log('No subscriptions found.');
30-
return;
31-
}
32-
console.log('Subscriptions:');
33-
for (const subscription of subscriptions) {
34-
console.log('%s (%s, %s)', subscription.customerId, subscription.skuId,
35-
subscription.plan.planName);
25+
if (!AdminReseller || !AdminReseller.Subscriptions) {
26+
throw new Error('Enable the AdminReseller Advanced Service.');
27+
}
28+
const response = AdminReseller.Subscriptions.list(optionalArgs);
29+
const subscriptions = response.subscriptions;
30+
if (!subscriptions || subscriptions.length === 0) {
31+
console.log('No subscriptions found.');
32+
return;
33+
}
34+
console.log('Subscriptions:');
35+
for (const subscription of subscriptions) {
36+
if (subscription.customerId && subscription.skuId) {
37+
if (subscription.plan?.planName) {
38+
console.log('%s (%s, %s)', subscription.customerId, subscription.skuId,
39+
subscription.plan.planName);
40+
} else {
41+
console.log('%s (%s)', subscription.customerId, subscription.skuId);
42+
}
3643
}
37-
} catch (err) {
38-
// TODO (developer)- Handle exception from the Reseller API
39-
console.log('Failed with error %s', err.message);
4044
}
4145
}
4246
// [END admin_sdk_reseller_quickstart]

0 commit comments

Comments
 (0)