Whiskee

Challange for Flock

Oct 9th, 2021 (edited)
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const routes = [
  2.   {
  3.     routeName: '/forms',
  4.     async method ({ response, activeUser }) {
  5.       try {
  6.         // anonymised
  7.       } catch (err) {
  8.         console.error(err)
  9.       }
  10.     }
  11.   },
  12.   {
  13.     routeName: '/forms',
  14.     reqMethod: 'POST',
  15.     async method ({ response, activeUser, bodyData }) {
  16.       // anonymised
  17.  
  18.       try {
  19.         // anonymised
  20.       } catch (err) {
  21.         console.error(err)
  22.       }
  23.     }
  24.   },
  25.   {
  26.     routeName: '/forms/:id',
  27.     reqMethod: 'POST',
  28.     async method ({ response, activeUser, bodyData, params }) {
  29.       // anonymised
  30.       try {
  31.         // anonymised
  32.  
  33.       } catch (err) {
  34.         console.error(err)
  35.       }
  36.     }
  37.   },
  38.   {
  39.     routeName: '/forms/types',
  40.     async method ({ response }) {
  41.       try {
  42.         // anonymised
  43.       } catch (err) {
  44.         console.error(err)
  45.       }
  46.     }
  47.   }
  48. ]
  49.  
  50. function matchRoute (routeName) {
  51.   // match and return the matched object (dict) here, as well as the params
  52.  
  53.  
  54.   // return { route, params }
  55. }
  56.  
  57. const routesThatShouldMatch = [
  58.   '/forms',
  59.   '/forms/72',
  60.   '/forms/types'
  61. ]
  62.  
  63. routesThatShouldMatch.forEach(routeName => {
  64.   const matchedRoute = matchRoute(routeName)
  65.  
  66.   console.log({
  67.     route: matchedRoute.route,
  68.     params: matchedRoute.params
  69.   })
  70. })
Add Comment
Please, Sign In to add comment