feat: added PATCH /me endpoint

This commit is contained in:
2026-06-14 22:07:13 +02:00 Unverified
parent cb922baa46
commit a784094692
4 changed files with 50 additions and 0 deletions
+23
View File
@@ -271,4 +271,27 @@ Json::Value AuthService::currentUser(const auth::UserContext &user)
}
return response;
}
Json::Value AuthService::editUser(const auth::UserContext &user, Json::Value::const_iterator::reference body) {
const auto allowedFields = {"first_name", "last_name", "phone"};
if (!body.isMember("field") || !body.isMember("value") ||
!body["field"].isString() || !body["value"].isString())
{
return failure("missing_fields");
}
const auto field = body["field"].asString();
if (std::find(allowedFields.begin(), allowedFields.end(), field) ==
allowedFields.end())
{
return failure("invalid_field");
}
auto db = drogon::app().getDbClient();
db->execSqlSync(
"UPDATE users SET " + field + " = ? WHERE id = ?",
body["value"].asString(),
user.id);
return success();
}
} // namespace visione::services