Update Template

Updates an existing route template. This endpoint supports partial updates — you can update just the name, just the steps, or both in a single request. Only the fields you include in the request body are modified; omitted fields retain their current values.

When updating steps, the entire step array is replaced. There is no mechanism to add, remove, or reorder individual steps — you must provide the complete new step list. The system re-assigns order values from the new array indices.

Updating a template does not affect any paths that were previously created from it. Template application is a deep-clone operation, so existing paths are fully independent.

Request

Path Parameters

ParameterTypeRequiredDescription
idstringYesThe unique identifier of the template to update (e.g. "tmpl_abc123")

Request Body

FieldTypeRequiredDescription
namestringNoUpdated template name. Must be non-empty if provided. Leading and trailing whitespace is trimmed.
stepsarrayNoUpdated array of step definitions. Must contain at least one step if provided. Replaces the entire existing step array.
steps[].namestringYes (if steps provided)The name of the process step.
steps[].locationstringNoThe physical location where this step is performed.
steps[].optionalbooleanNoWhether the step can be skipped. Defaults to false if omitted.
steps[].dependencyType'physical' | 'preferred' | 'completion_gate'NoHow strictly step order is enforced. Defaults to "preferred" if omitted.

Response

200 OK

Returned when the template is successfully updated. The response contains the complete updated TemplateRoute object.

FieldTypeDescription
idstringThe template's unique identifier (unchanged)
namestringThe template name (updated or unchanged)
stepsTemplateStep[]The step definitions (updated or unchanged)
steps[].namestringStep name
steps[].ordernumberZero-based position re-assigned from array index
steps[].locationstring | undefinedLocation, if provided
steps[].optionalbooleanWhether the step is optional
steps[].dependencyType'physical' | 'preferred' | 'completion_gate'Dependency enforcement level
createdAtstringOriginal creation timestamp (unchanged)
updatedAtstringISO 8601 timestamp of this update

400 Bad Request

Returned when the request body fails validation.

ConditionMessage
name is provided but empty"name is required"
steps is provided but empty array"steps must have at least one item"

404 Not Found

Returned when no template exists with the given ID.

ConditionMessage
Template does not exist"TemplateRoute not found: tmpl_abc123"

500 Internal Server Error

Returned if an unhandled error occurs while persisting the update.

ConditionMessage
Database write failure"Internal Server Error"

Examples

Request — Update name only

curl -X PUT http://localhost:3000/api/templates/tmpl_abc123 \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Advanced CNC Machining v2"
  }'

Response — Name updated

{
  "id": "tmpl_abc123",
  "name": "Advanced CNC Machining v2",
  "steps": [
    {
      "name": "Raw Material Inspection",
      "order": 0,
      "location": "QC Lab",
      "optional": false,
      "dependencyType": "physical"
    },
    {
      "name": "CNC Milling",
      "order": 1,
      "location": "CNC Room",
      "optional": false,
      "dependencyType": "physical"
    }
  ],
  "createdAt": "2024-01-10T09:00:00.000Z",
  "updatedAt": "2024-01-20T14:00:00.000Z"
}

Request — Replace steps entirely

curl -X PUT http://localhost:3000/api/templates/tmpl_abc123 \
  -H "Content-Type: application/json" \
  -d '{
    "steps": [
      { "name": "Laser Cutting", "location": "Laser Bay" },
      { "name": "Welding", "location": "Weld Shop" },
      { "name": "Powder Coating", "location": "Paint Booth" },
      { "name": "QC Inspection", "location": "QC Lab" }
    ]
  }'

Response — Steps replaced

{
  "id": "tmpl_abc123",
  "name": "Advanced CNC Machining v2",
  "steps": [
    {
      "name": "Laser Cutting",
      "order": 0,
      "location": "Laser Bay",
      "optional": false,
      "dependencyType": "preferred"
    },
    {
      "name": "Welding",
      "order": 1,
      "location": "Weld Shop",
      "optional": false,
      "dependencyType": "preferred"
    },
    {
      "name": "Powder Coating",
      "order": 2,
      "location": "Paint Booth",
      "optional": false,
      "dependencyType": "preferred"
    },
    {
      "name": "QC Inspection",
      "order": 3,
      "location": "QC Lab",
      "optional": false,
      "dependencyType": "preferred"
    }
  ],
  "createdAt": "2024-01-10T09:00:00.000Z",
  "updatedAt": "2024-01-20T15:30:00.000Z"
}

Notes

  • When steps is provided, the entire step array is replaced. There is no merge or diff — the old steps are discarded and the new ones take their place.
  • Step order values are re-assigned from the new array indices (0, 1, 2, ...) regardless of any order values you might include in the request.
  • If optional is not specified for a step, it defaults to false. If dependencyType is not specified, it defaults to "preferred".
  • The updatedAt timestamp is set to the current time on every successful update, even if the actual data did not change.
  • Updating a template has no effect on paths that were previously created from it. Template application is a one-time deep-clone.
  • The createdAt timestamp is never modified.