Replace question with condition_id across department_selfserve_tasks logic, routes, OpenAPI spec, and associated methods for improved consistency and clarity.

This commit is contained in:
Jeppe Bundgaard
2026-01-09 13:47:10 +01:00
parent c87f96ebcf
commit d576a4741b
6 changed files with 27 additions and 26 deletions
+7 -7
View File
@@ -1772,7 +1772,7 @@ paths:
tags:
- Self-Serve
summary: List self-serve tasks
description: Retrieve a list of self-serve tasks for a department, lane, product, or question.
description: Retrieve a list of self-serve tasks for a department, lane, product, or condition_id.
operationId: listSelfserveTasks
parameters:
- name: id
@@ -1795,9 +1795,9 @@ paths:
description: Filter by product ID
schema:
type: integer
- name: question
- name: condition_id
in: query
description: Filter by question ID
description: Filter by condition ID
schema:
type: integer
- $ref: '#/components/parameters/PageParam'
@@ -1843,7 +1843,7 @@ paths:
type: integer
product:
type: integer
question:
condition_id:
type: integer
nullable: true
task:
@@ -1890,7 +1890,7 @@ paths:
type: integer
product:
type: integer
question:
condition_id:
type: integer
nullable: true
task:
@@ -5032,9 +5032,9 @@ components:
product:
type: integer
description: Product ID
question:
condition_id:
type: integer
description: Question ID (if conditional task)
description: Condition ID (if conditional task)
nullable: true
task:
type: string
@@ -48,6 +48,7 @@ trait selfserve_lane_port_controller_t
// Log the port open event
$this->logLaneAction(selfserve_lane_log_action::OPEN_PORT, 200, ['port' => $port->name]);
// Open the relay
return true; // TODO: Remove this in production
return $this->shellyOpenPort($port);
}
@@ -13,7 +13,7 @@ class department_selfserve_condition_rules_o extends db
public object_property $condition_id; // The condition object id
public object_property $type; // The condition type (e.g., true/false, equals, greater than, etc.)
public object_property $object_type; // The object type to which the condition applies (e.g., question, task, etc.)
public object_property $object_type; // The object type to which the condition applies (e.g., condition_id, task, etc.)
public object_property $object_id; // The object id to which the condition applies
public object_property $name; // The condition name
public object_property $description; // The task description
@@ -31,7 +31,7 @@ class department_selfserve_condition_rules_o extends db
* Add a condition rule
* @param int $condition_id The condition object id
* @param string $type The condition type (e.g., IS_TRUE, IS_FALSE)
* @param string $object_type The object type to which the condition applies (e.g., question, task, etc.)
* @param string $object_type The object type to which the condition applies (e.g., condition_id, task, etc.)
* @param int $object_id The object id to which the condition applies
* @param string $name The condition name
* @param string $description The condition description
@@ -96,7 +96,7 @@ class department_selfserve_questions_o extends db
self::requireSelected();
global $db;
$id = (int)$this->id;
$sql = "UPDATE department_selfserve_tasks SET question = NULL WHERE question = $id";
$sql = "UPDATE department_selfserve_tasks SET condition_id = NULL WHERE condition_id = $id";
$db->query($sql);
$this->trait_delete();
}
@@ -14,10 +14,10 @@ class department_selfserve_tasks_o extends db
public object_property $department; // The department id
public object_property $lane; // The lane id
public object_property $product; // The product id
public object_property $question; // The question id (if conditional task)
public object_property $condition_id; // The question id (if conditional task)
public object_property $task; // The task
public object_property $description; // The task description
public object_property $order_priority; // The order priority of the question (lower numbers are shown first)
public object_property $order_priority; // The order priority of the task (lower numbers are shown first)
public object_property $created_at;
public object_property $updated_at;
public object_property $deleted_at;
@@ -33,14 +33,14 @@ class department_selfserve_tasks_o extends db
* @param int $department The department id
* @param int $lane The lane id
* @param int $product The product id
* @param int|null $question The question id (if conditional task)
* @param int|null $condition_id The question id (if conditional task)
* @param string $task The task text
* @param string $description The task description
* @param int $order_priority The order priority of the task (lower numbers are shown first)
* @return department_selfserve_tasks_o
* @throws Exception If the object was not created successfully
*/
public function add(int $department, int $lane, int $product, int|null $question, string $task, string $description, int $order_priority = 0): department_selfserve_tasks_o
public function add(int $department, int $lane, int $product, int|null $condition_id, string $task, string $description, int $order_priority = 0): department_selfserve_tasks_o
{
global /** @var db $db */
$db;
@@ -48,8 +48,8 @@ class department_selfserve_tasks_o extends db
$department = (int)$department;
$lane = (int)$lane;
$product = (int)$product;
if (!is_null($question)) {
$question = (int)$question;
if (!is_null($condition_id)) {
$condition_id = (int)$condition_id;
}
$task = $db->escape_string($task);
$description = $db->escape_string($description);
@@ -59,7 +59,7 @@ class department_selfserve_tasks_o extends db
'department' => $department,
'lane' => $lane,
'product' => $product,
...(!is_null($question) ? ['question' => $question] : []), // If the question is null, it will be set to null in the database
...(!is_null($condition_id) ? ['condition_id' => $condition_id] : []), // If the question is null, it will be set to null in the database
'task' => $task,
'description' => $description,
'order_priority' => $order_priority,
@@ -76,7 +76,7 @@ class department_selfserve_tasks_o extends db
$this->department = new object_property($this->table, $this->id, 'department', 'int', false);
$this->lane = new object_property($this->table, $this->id, 'lane', 'int', false);
$this->product = new object_property($this->table, $this->id, 'product', 'int', false);
$this->question = new object_property($this->table, $this->id, 'question', 'int', true);
$this->condition_id = new object_property($this->table, $this->id, 'condition_id', 'int', true);
$this->task = new object_property($this->table, $this->id, 'task', 'string', false);
$this->description = new object_property($this->table, $this->id, 'description', 'string', false);
$this->order_priority = new object_property($this->table, $this->id, 'order_priority', 'int', false);
@@ -97,7 +97,7 @@ class department_selfserve_tasks_o extends db
'department' => (int)$this->department->value(),
'lane' => (int)$this->lane->value(),
'product' => (int)$this->product->value(),
'question' => is_null($this->question->value()) ? null : (int)$this->question->value(),
'condition_id' => is_null($this->condition_id->value()) ? null : (int)$this->condition_id->value(),
'task' => (string)$this->task->value(),
'description' => (string)$this->description->value(),
'order_priority' => (int)$this->order_priority->value(),
@@ -65,12 +65,12 @@ class departmentSelfserveTasksRoute
$filters['product'] = (int)self::getParameter('product');
}
if (self::isParametersSet(['question'])) {
$filters['question'] = (int)self::getParameter('question');
if (self::isParametersSet(['condition_id'])) {
$filters['condition_id'] = (int)self::getParameter('condition_id');
}
$response->success(
$tasks_o->setSearchableFields(['id', 'department', 'lane', 'product', 'question', 'task', 'description', 'deleted_at'])
$tasks_o->setSearchableFields(['id', 'department', 'lane', 'product', 'condition_id', 'task', 'description', 'deleted_at'])
->listObjectsWithPaginationIfSet(function ($task) {
$t = new department_selfserve_tasks_o();
$t->select((int)$task['id']);
@@ -95,7 +95,7 @@ class departmentSelfserveTasksRoute
$department = (int)$response->getRequestParameter('department');
$lane = (int)$response->getRequestParameter('lane');
$product = (int)$response->getRequestParameter('product');
$question = $response->isRequestParameterSet('question') ? (int)$response->getRequestParameter('question') : null;
$condition_id = $response->isRequestParameterSet('condition_id') ? (int)$response->getRequestParameter('condition_id') : null;
$task = (string)$response->getRequestParameter('task');
$description = (string)$response->getRequestParameter('description');
$order_priority = (int)($response->getRequestParameter('order_priority') ?? 0);
@@ -114,7 +114,7 @@ class departmentSelfserveTasksRoute
$department,
$lane,
$product,
$question,
$condition_id,
$task,
$description,
$order_priority
@@ -166,8 +166,8 @@ class departmentSelfserveTasksRoute
if (self::isParametersSet(['product'])) {
$task_o->product->set((int)self::getParameter('product'));
}
if (self::isParametersSet(['question'])) {
$task_o->question->set(self::getParameter('question') === null ? null : (int)self::getParameter('question'));
if (self::isParametersSet(['condition_id'])) {
$task_o->condition_id->set(self::getParameter('condition_id') === null ? null : (int)self::getParameter('condition_id'));
}
if (self::isParametersSet(['task'])) {
$task_o->task->set((string)self::getParameter('task'));