Update create token logic
This commit is contained in:
@@ -91,6 +91,12 @@ async def create_discord_token():
|
|||||||
"""
|
"""
|
||||||
data = await request.get_json()
|
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_name = data.get("name")
|
||||||
temp_discord_id = data.get("discord_id")
|
temp_discord_id = data.get("discord_id")
|
||||||
temp_token = data.get("token")
|
temp_token = data.get("token")
|
||||||
@@ -98,9 +104,15 @@ async def create_discord_token():
|
|||||||
temp_guilds = data.get("guild_ids")
|
temp_guilds = data.get("guild_ids")
|
||||||
|
|
||||||
# Create the discord ID object
|
# 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:
|
if new_d_id:
|
||||||
return jsonify(new_d_id.to_dict()), 201
|
return jsonify(new_d_id.to_dict()), 201
|
||||||
|
|||||||
Reference in New Issue
Block a user