( org_id: number, actions: Action[], method: RequestMethod, slug: string[], )
| 74 | } |
| 75 | |
| 76 | export function getMatchingAction( |
| 77 | org_id: number, |
| 78 | actions: Action[], |
| 79 | method: RequestMethod, |
| 80 | slug: string[], |
| 81 | ): Action | null { |
| 82 | // Note: Assumes you have already filtered by request method |
| 83 | |
| 84 | const slugString = "/" + slug.join("/"); |
| 85 | |
| 86 | let matches = actions.filter((action) => { |
| 87 | return action.path && slugMatchesPath(action.path, slugString); |
| 88 | }); |
| 89 | |
| 90 | if (matches.length === 0) { |
| 91 | console.log( |
| 92 | `Could not match slug "${slugString}" with method "${method}" to any action in the database for organisation "${org_id}"`, |
| 93 | ); |
| 94 | return null; |
| 95 | } |
| 96 | |
| 97 | if (matches.length > 1) matches = processMultipleMatches(matches, slug); |
| 98 | |
| 99 | console.log( |
| 100 | `Successfully matched slug "${slugString}" to action with path "${matches[0].path}"`, |
| 101 | ); |
| 102 | |
| 103 | return matches[0]; |
| 104 | } |
| 105 | |
| 106 | export function getPathParameters( |
| 107 | path: string, |
no test coverage detected