Skip to content

Commit

Permalink
Update functions list route on CLI (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
uditdc authored Jun 13, 2023
1 parent 8cb4472 commit a237ba1
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
5 changes: 3 additions & 2 deletions src/commands/function/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ const deleteFunction = async (data: any) => {
console.log(Chalk.yellow(`Deleting ${functionName} ...`))
console.log('')

const { data } = await consoleClient.post(`/api/modules/mine`, {})
const { data } = await consoleClient.get(`/api/modules/mine`, {})
const functions = data.docs ? data.docs : []

// Sort all matching functions by name and select the last matching function
// TODO: Ensure all functions have unique names under a user's scope
const matchingFunctions = data.filter((f: any) =>
const matchingFunctions = functions.filter((f: any) =>
normalizeFunctionName(f.functionName) === normalizeFunctionName(functionName))

if (matchingFunctions && matchingFunctions.length > 0) {
Expand Down
5 changes: 3 additions & 2 deletions src/commands/function/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,12 @@ const deployFunction = async (functionName: string, functionData: any, options:

// Find all matching functions, warn users if they are overwriting a deployed function
try {
const { data } = await consoleClient.post(`/api/modules/mine`, {})
const { data } = await consoleClient.get(`/api/modules/mine`, {})
const functions = data.docs ? data.docs : []

// Sort all matching functions by name and select the last matching function
// TODO: Ensure all functions have unique names under a user's scope
const matchingFunctions = data.filter((f: any) =>
const matchingFunctions = functions.filter((f: any) =>
normalizeFunctionName(f.functionName) === normalizeFunctionName(functionName))

if (matchingFunctions && matchingFunctions.length > 0) {
Expand Down
9 changes: 5 additions & 4 deletions src/commands/function/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@ import { logger } from "../../lib/logger"

export const run = async () => {
try {
const { data } = await consoleClient.post(`/api/modules/mine`, {})
const { data } = await consoleClient.get(`/api/modules/mine`, {})
const functions = data.docs ? data.docs : []

logger.log('List of Functions:')
logger.log('-----------------------------------')

if (data && data.length > 0) {
data.forEach && data.forEach((f: any) => {
if (functions && functions.length > 0) {
functions.forEach && functions.forEach((f: any) => {
logger.log('')
logger.log(`${Chalk.blue('Name:')} ${f.functionName}`)
logger.log(`${Chalk.blue('CID:')} ${f.functionId}`)
logger.log(`${Chalk.blue('Status:')} ${f.status === 'stopped' ? Chalk.red(f.status) : f.status === 'deployed' ? Chalk.green(f.status) : f.status}`)
})

logger.log('')
logger.log(`Total Functions: ${data.length}`)
logger.log(`Total Functions: ${functions.length}`)
} else {
logger.log('')
logger.log('You have no functions.')
Expand Down
5 changes: 3 additions & 2 deletions src/commands/function/stop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ const stopFunction = async (data: any) => {
console.log(Chalk.yellow(`Stopping ${functionName} ...`))
console.log('')

const { data } = await consoleClient.post(`/api/modules/mine`, {})
const { data } = await consoleClient.get(`/api/modules/mine`, {})
const functions = data.docs ? data.docs : []

// Sort all matching functions by name and select the last matching function
// TODO: Ensure all functions have unique names under a user's scope
const matchingFunctions = data.filter((f: any) =>
const matchingFunctions = functions.filter((f: any) =>
normalizeFunctionName(f.functionName) === normalizeFunctionName(functionName))

if (matchingFunctions && matchingFunctions.length > 0) {
Expand Down
5 changes: 3 additions & 2 deletions src/commands/function/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,12 @@ const updateFunction = async (data: any) => {

// Find all matching functions, warn users if they are updating a function that is not deployed
try {
const { data } = await consoleClient.post(`/api/modules/mine`, {})
const { data } = await consoleClient.get(`/api/modules/mine`, {})
const functions = data.docs ? data.docs : []

// Sort all matching functions by name and select the last matching function
// TODO: Ensure all functions have unique names under a user's scope
const matchingFunctions = data.filter((f: any) =>
const matchingFunctions = functions.filter((f: any) =>
normalizeFunctionName(f.functionName) === normalizeFunctionName(functionName))

if (matchingFunctions && matchingFunctions.length > 0) {
Expand Down

0 comments on commit a237ba1

Please sign in to comment.