Skip to content

Commit

Permalink
fix: fixes slug id route issue
Browse files Browse the repository at this point in the history
  • Loading branch information
aviemet committed Jul 16, 2024
1 parent a738981 commit 07e6490
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion app/controllers/api/commands_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def show
render json: command.render(view: :show), staus: :ok
end

# @route PUT /api/command/:id/execute (api_execute_command)
# @route PUT /api/command/:slug/execute (api_execute_command)
def execute
authorize command

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/protocols_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def options
render json: protocols.render(view: :options), status: :ok
end

# @route PUT /api/protocol/:id/execute (api_execute_protocol)
# @route PUT /api/protocol/:slug/execute (api_execute_protocol)
def execute
authorize protocol

Expand Down
4 changes: 2 additions & 2 deletions app/frontend/Features/Control/lib.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Routes } from '@/lib'

export const controlRoute = (control: Partial<Schema.Control>) => {
if(control.protocol_id) {
return Routes.apiExecuteProtocol(control.protocol_id)
if(control?.protocol?.slug) {
return Routes.apiExecuteProtocol(control.protocol.slug)
} else if(control.command_id) {
return Routes.apiExecuteCommand(control.command_id)
} else {
Expand Down
12 changes: 6 additions & 6 deletions app/frontend/types/routes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,25 +150,25 @@ export const apiControlsOptions: ((

/**
* Generates rails route to
* /api/command/:id/execute(.:format)
* @param {any} id
* /api/command/:slug/execute(.:format)
* @param {any} slug
* @param {object | undefined} options
* @returns {string} route path
*/
export const apiExecuteCommand: ((
id: RequiredRouteParameter,
slug: RequiredRouteParameter,
options?: {format?: OptionalRouteParameter} & RouteOptions
) => string) & RouteHelperExtras;

/**
* Generates rails route to
* /api/protocol/:id/execute(.:format)
* @param {any} id
* /api/protocol/:slug/execute(.:format)
* @param {any} slug
* @param {object | undefined} options
* @returns {string} route path
*/
export const apiExecuteProtocol: ((
id: RequiredRouteParameter,
slug: RequiredRouteParameter,
options?: {format?: OptionalRouteParameter} & RouteOptions
) => string) & RouteHelperExtras;

Expand Down
12 changes: 6 additions & 6 deletions app/frontend/types/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -585,21 +585,21 @@ export const apiControlsOptions = /*#__PURE__*/ __jsr.r({"format":{}}, [2,[7,"/"

/**
* Generates rails route to
* /api/command/:id/execute(.:format)
* @param {any} id
* /api/command/:slug/execute(.:format)
* @param {any} slug
* @param {object | undefined} options
* @returns {string} route path
*/
export const apiExecuteCommand = /*#__PURE__*/ __jsr.r({"id":{"r":true},"format":{}}, [2,[7,"/"],[2,[6,"api"],[2,[7,"/"],[2,[6,"command"],[2,[7,"/"],[2,[3,"id"],[2,[7,"/"],[2,[6,"execute"],[1,[2,[8,"."],[3,"format"]]]]]]]]]]]);
export const apiExecuteCommand = /*#__PURE__*/ __jsr.r({"slug":{"r":true},"format":{}}, [2,[7,"/"],[2,[6,"api"],[2,[7,"/"],[2,[6,"command"],[2,[7,"/"],[2,[3,"slug"],[2,[7,"/"],[2,[6,"execute"],[1,[2,[8,"."],[3,"format"]]]]]]]]]]]);

/**
* Generates rails route to
* /api/protocol/:id/execute(.:format)
* @param {any} id
* /api/protocol/:slug/execute(.:format)
* @param {any} slug
* @param {object | undefined} options
* @returns {string} route path
*/
export const apiExecuteProtocol = /*#__PURE__*/ __jsr.r({"id":{"r":true},"format":{}}, [2,[7,"/"],[2,[6,"api"],[2,[7,"/"],[2,[6,"protocol"],[2,[7,"/"],[2,[3,"id"],[2,[7,"/"],[2,[6,"execute"],[1,[2,[8,"."],[3,"format"]]]]]]]]]]]);
export const apiExecuteProtocol = /*#__PURE__*/ __jsr.r({"slug":{"r":true},"format":{}}, [2,[7,"/"],[2,[6,"api"],[2,[7,"/"],[2,[6,"protocol"],[2,[7,"/"],[2,[3,"slug"],[2,[7,"/"],[2,[6,"execute"],[1,[2,[8,"."],[3,"format"]]]]]]]]]]]);

/**
* Generates rails route to
Expand Down
4 changes: 2 additions & 2 deletions config/routes/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

resources :servers, except: [:edit, :new]

put "protocol/:id/execute", to: "protocols#execute", as: :execute_protocol
put "protocol/:slug/execute", to: "protocols#execute", as: :execute_protocol
resources :protocols, except: [:edit, :new], param: :slug

resources :controls, except: [:edit, :new]

get "commands/payload_types", to: "commands#payload_types", as: :commands_payload_types
put "command/:id/execute", to: "commands#execute", as: :execute_command
put "command/:slug/execute", to: "commands#execute", as: :execute_command
resources :commands, except: [:edit, :new], param: :slug

scope :options do
Expand Down

0 comments on commit 07e6490

Please sign in to comment.