From ef6023330df058c6e1fd47d5a2a5d400311cbd6d Mon Sep 17 00:00:00 2001 From: Alexey Date: Wed, 22 Oct 2025 15:05:12 +0300 Subject: [PATCH] --- com/Access/_common.lua | 22 ++++++++++++++++++++++ com/Access/_errors.lua | 30 ++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 com/Access/_common.lua create mode 100644 com/Access/_errors.lua diff --git a/com/Access/_common.lua b/com/Access/_common.lua new file mode 100644 index 0000000..bd7e940 --- /dev/null +++ b/com/Access/_common.lua @@ -0,0 +1,22 @@ +-- File com/Access/_common.lua +-- +-- Created at 2025-21-10 +-- +-- Description: +--- Common functions for Unit module + +local common = {} + +function common.CheckMissingElement(arr, cmp) + local is_missing = {} + local ok = true + for _, key in ipairs(arr) do + if cmp[key] == nil then + table.insert(is_missing, key) + ok = false + end + end + return ok, is_missing +end + +return common \ No newline at end of file diff --git a/com/Access/_errors.lua b/com/Access/_errors.lua new file mode 100644 index 0000000..f9cf714 --- /dev/null +++ b/com/Access/_errors.lua @@ -0,0 +1,30 @@ +-- File com/Access/_errors.lua +-- +-- Created at 2025-21-10 +-- Description: +--- Centralized error definitions for Access operations +--- to keep API responses consistent and clean. + +local errors = { + -- Common validation + MISSING_PARAMS = { code = -32602, message = "Missing params" }, + INVALID_FIELD_TYPE = { code = -32602, message = "'fields' must be a non-empty table" }, + INVALID_BY_PARAM = { code = -32602, message = "Invalid 'by' param" }, + NO_VALID_FIELDS = { code = -32604, message = "No valid fields to update" }, + + -- Existence / duplication + UNIT_NOT_FOUND = { code = -32102, message = "Unit is not exists" }, + UNIT_EXISTS = { code = -32101, message = "Unit is already exists" }, + + -- Database & constraint + UNIQUE_CONSTRAINT = { code = -32602, message = "Unique constraint failed" }, + DB_QUERY_FAILED = { code = -32001, message = "Database query failed" }, + DB_EXEC_FAILED = { code = -32002, message = "Database execution failed" }, + DB_INSERT_FAILED = { code = -32003, message = "Failed to create unit" }, + DB_DELETE_FAILED = { code = -32004, message = "Failed to delete unit" }, + + -- Generic fallback + UNKNOWN = { code = -32099, message = "Unexpected internal error" }, +} + +return errors