feat: added PATCH /me endpoint
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -15,5 +15,6 @@ class AuthService
|
||||
Json::Value loginWithPassword(const Json::Value &body);
|
||||
Json::Value changePassword(const auth::UserContext &user, const Json::Value &body);
|
||||
Json::Value currentUser(const auth::UserContext &user);
|
||||
Json::Value editUser(const auth::UserContext & user, Json::Value::const_iterator::reference body);
|
||||
};
|
||||
} // namespace visione::services
|
||||
|
||||
Reference in New Issue
Block a user