-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
653b742
commit faee0c9
Showing
1 changed file
with
10 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,31 @@ | ||
import axios from "axios"; | ||
import chalk from "chalk"; | ||
import ora from "ora"; | ||
import AddOnApiHelper from "../../../lib/addonApiHelper"; | ||
import { errorHandler } from "../../exceptions"; | ||
|
||
type listAdminsSchemaParams = { siteId: string }; | ||
export const listAdminsSchema = errorHandler<listAdminsSchemaParams>( | ||
async ({ siteId }: listAdminsSchemaParams) => { | ||
try { | ||
const spinner = ora("Retrieving admins...").start(); | ||
const result = await AddOnApiHelper.listAdmins(siteId); | ||
spinner.succeed(); | ||
console.log(JSON.stringify(result, null, 4)); | ||
} catch (e) { | ||
if (axios.isAxiosError(e) && e.response?.status === 404) { | ||
console.log(chalk.red(`\nSite ID not recognized`)); | ||
} else { | ||
throw e; | ||
} | ||
} | ||
const spinner = ora("Retrieving admins...").start(); | ||
const result = await AddOnApiHelper.listAdmins(siteId); | ||
spinner.succeed(); | ||
console.log(JSON.stringify(result, null, 4)); | ||
}, | ||
); | ||
|
||
type removeAdminSchemaParams = { siteId: string; email: string }; | ||
export const removeAdminSchema = errorHandler<removeAdminSchemaParams>( | ||
async ({ siteId, email }: removeAdminSchemaParams) => { | ||
try { | ||
const spinner = ora("Removing admin...").start(); | ||
await AddOnApiHelper.removeAdmin(siteId, email); | ||
spinner.succeed(); | ||
} catch (e) { | ||
if (axios.isAxiosError(e) && e.response?.status === 404) { | ||
console.log(chalk.red(`\nSite ID not recognized`)); | ||
} else { | ||
throw e; | ||
} | ||
} | ||
const spinner = ora("Removing admin...").start(); | ||
await AddOnApiHelper.removeAdmin(siteId, email); | ||
spinner.succeed(); | ||
}, | ||
); | ||
|
||
type addAdminSchemaParams = { siteId: string; email: string }; | ||
export const addAdminSchema = errorHandler<addAdminSchemaParams>( | ||
async ({ siteId, email }: addAdminSchemaParams) => { | ||
try { | ||
const spinner = ora("Adding admin...").start(); | ||
await AddOnApiHelper.addAdmin(siteId, email); | ||
spinner.succeed(); | ||
} catch (e) { | ||
if (axios.isAxiosError(e) && e.response?.status === 404) { | ||
console.log(chalk.red(`\nSite ID not recognized`)); | ||
} else { | ||
throw e; | ||
} | ||
} | ||
const spinner = ora("Adding admin...").start(); | ||
await AddOnApiHelper.addAdmin(siteId, email); | ||
spinner.succeed(); | ||
}, | ||
); |