Whiskee icon

Challange for Flock

Whiskee | PRO | 10/09/21 10:59:01 PM UTC (Edited) | 0 ⭐ | 398 👁️ | Never ⏰ | []
JavaScript |

1.28 KB

|

None

|

0 👍

/

0 👎

const routes = [
  {
    routeName: '/forms',
    async method ({ response, activeUser }) {
      try {
        // anonymised
      } catch (err) {
        console.error(err)
      }
    }
  },
  {
    routeName: '/forms',
    reqMethod: 'POST',
    async method ({ response, activeUser, bodyData }) {
      // anonymised
 
      try {
        // anonymised
      } catch (err) {
        console.error(err)
      }
    }
  },
  {
    routeName: '/forms/:id',
    reqMethod: 'POST',
    async method ({ response, activeUser, bodyData, params }) {
      // anonymised
      try {
        // anonymised
 
      } catch (err) {
        console.error(err)
      }
    }
  },
  {
    routeName: '/forms/types',
    async method ({ response }) {
      try {
        // anonymised
      } catch (err) {
        console.error(err)
      }
    }
  }
]
 
function matchRoute (routeName) {
  // match and return the matched object (dict) here, as well as the params
 
 
  // return { route, params }
}
 
const routesThatShouldMatch = [
  '/forms',
  '/forms/72',
  '/forms/types'
]
 
routesThatShouldMatch.forEach(routeName => {
  const matchedRoute = matchRoute(routeName)
 
  console.log({
    route: matchedRoute.route,
    params: matchedRoute.params
  })
})

Comments