Update create token logic

This commit is contained in:
Logan Cusano
2025-05-26 01:09:41 -04:00
parent 243ae6d15a
commit a6c318ecc8

View File

@@ -91,6 +91,12 @@ async def create_discord_token():
"""
data = await request.get_json()
if '_id' in data:
id_search_result = await current_app.sys_db_h.find_system({"_id": data["_id"]})
if id_search_result:
# If _id is provided and exists, return conflict
abort(409, f"System with ID '{data['_id']}' already exists")
temp_name = data.get("name")
temp_discord_id = data.get("discord_id")
temp_token = data.get("token")
@@ -98,9 +104,15 @@ async def create_discord_token():
temp_guilds = data.get("guild_ids")
# Create the discord ID object
d_id = DiscordId(None, temp_discord_id, temp_name, temp_token, temp_active, temp_guilds)
temp_d_id = {
"discord_id": temp_discord_id,
"name": temp_name,
"token": temp_token,
"active": temp_active,
"guild_ids": temp_guilds
}
new_d_id = await current_app.d_id_db_h.create_discord_id(d_id.to_dict())
new_d_id = await current_app.d_id_db_h.create_discord_id(temp_d_id)
if new_d_id:
return jsonify(new_d_id.to_dict()), 201