fix: remove both option for api endpoints. it just makes things complicated

This commit is contained in:
Andras Bacsai 2024-06-26 13:57:04 +02:00
parent 2a52fb5872
commit 07508df8fd
2 changed files with 2 additions and 93 deletions

View File

@ -276,7 +276,7 @@ public function envs_by_uuid(Request $request)
public function update_env_by_uuid(Request $request) public function update_env_by_uuid(Request $request)
{ {
ray()->clearAll(); ray()->clearAll();
$allowedFields = ['key', 'value', 'is_preview', 'is_build_time', 'is_literal', 'both']; $allowedFields = ['key', 'value', 'is_preview', 'is_build_time', 'is_literal'];
$teamId = get_team_id_from_token(); $teamId = get_team_id_from_token();
if (is_null($teamId)) { if (is_null($teamId)) {
@ -296,7 +296,6 @@ public function update_env_by_uuid(Request $request)
'is_preview' => 'boolean', 'is_preview' => 'boolean',
'is_build_time' => 'boolean', 'is_build_time' => 'boolean',
'is_literal' => 'boolean', 'is_literal' => 'boolean',
'both' => 'boolean',
]); ]);
$extraFields = array_diff(array_keys($request->all()), $allowedFields); $extraFields = array_diff(array_keys($request->all()), $allowedFields);
@ -316,37 +315,6 @@ public function update_env_by_uuid(Request $request)
$is_preview = $request->is_preview ?? false; $is_preview = $request->is_preview ?? false;
$is_build_time = $request->is_build_time ?? false; $is_build_time = $request->is_build_time ?? false;
$is_literal = $request->is_literal ?? false; $is_literal = $request->is_literal ?? false;
$both = $request->both ?? false;
if ($both) {
$env = $application->environment_variables_preview->where('key', $request->key)->first();
if ($env) {
$env->value = $request->value;
if ($env->is_build_time != $is_build_time) {
$env->is_build_time = $is_build_time;
}
if ($env->is_literal != $is_literal) {
$env->is_literal = $is_literal;
}
ray($env);
$env->save();
}
$env = $application->environment_variables->where('key', $request->key)->first();
if ($env) {
$env->value = $request->value;
if ($env->is_build_time != $is_build_time) {
$env->is_build_time = $is_build_time;
}
if ($env->is_literal != $is_literal) {
$env->is_literal = $is_literal;
}
$env->save();
}
return response()->json([
'message' => 'Environment variables updated.',
]);
}
if ($is_preview) { if ($is_preview) {
$env = $application->environment_variables_preview->where('key', $request->key)->first(); $env = $application->environment_variables_preview->where('key', $request->key)->first();
if ($env) { if ($env) {
@ -423,7 +391,7 @@ public function create_bulk_envs(Request $request)
], 400); ], 400);
} }
$bulk_data = collect($bulk_data)->map(function ($item) { $bulk_data = collect($bulk_data)->map(function ($item) {
return collect($item)->only(['key', 'value', 'is_preview', 'is_build_time', 'is_literal', 'both']); return collect($item)->only(['key', 'value', 'is_preview', 'is_build_time', 'is_literal']);
}); });
foreach ($bulk_data as $item) { foreach ($bulk_data as $item) {
$validator = customApiValidator($item, [ $validator = customApiValidator($item, [
@ -432,7 +400,6 @@ public function create_bulk_envs(Request $request)
'is_preview' => 'boolean', 'is_preview' => 'boolean',
'is_build_time' => 'boolean', 'is_build_time' => 'boolean',
'is_literal' => 'boolean', 'is_literal' => 'boolean',
'both' => 'boolean',
]); ]);
if ($validator->fails()) { if ($validator->fails()) {
return response()->json([ return response()->json([
@ -443,50 +410,6 @@ public function create_bulk_envs(Request $request)
$is_preview = $item->get('is_preview') ?? false; $is_preview = $item->get('is_preview') ?? false;
$is_build_time = $item->get('is_build_time') ?? false; $is_build_time = $item->get('is_build_time') ?? false;
$is_literal = $item->get('is_literal') ?? false; $is_literal = $item->get('is_literal') ?? false;
$both = $item->get('both') ?? false;
if ($both) {
$env = $application->environment_variables_preview->where('key', $item->get('key'))->first();
if ($env) {
$env->value = $item->get('value');
if ($env->is_build_time != $is_build_time) {
$env->is_build_time = $is_build_time;
}
if ($env->is_literal != $is_literal) {
$env->is_literal = $is_literal;
}
$env->save();
} else {
$env = $application->environment_variables()->create([
'key' => $item->get('key'),
'value' => $item->get('value'),
'is_preview' => $is_preview,
'is_build_time' => $is_build_time,
'is_literal' => $is_literal,
]);
}
$env = $application->environment_variables->where('key', $item->get('key'))->first();
if ($env) {
$env->value = $item->get('value');
if ($env->is_build_time != $is_build_time) {
$env->is_build_time = $is_build_time;
}
if ($env->is_literal != $is_literal) {
$env->is_literal = $is_literal;
}
$env->save();
} else {
$env = $application->environment_variables()->create([
'key' => $item->get('key'),
'value' => $item->get('value'),
'is_preview' => $is_preview,
'is_build_time' => $is_build_time,
'is_literal' => $is_literal,
]);
}
continue;
}
if ($is_preview) { if ($is_preview) {
$env = $application->environment_variables_preview->where('key', $item->get('key'))->first(); $env = $application->environment_variables_preview->where('key', $item->get('key'))->first();
if ($env) { if ($env) {
@ -622,7 +545,6 @@ public function delete_env_by_uuid(Request $request)
{ {
ray()->clearAll(); ray()->clearAll();
$teamId = get_team_id_from_token(); $teamId = get_team_id_from_token();
$both = $request->query->get('both') ?? false;
if (is_null($teamId)) { if (is_null($teamId)) {
return invalid_token(); return invalid_token();
} }
@ -642,12 +564,6 @@ public function delete_env_by_uuid(Request $request)
], 404); ], 404);
} }
$found_env->delete(); $found_env->delete();
if ($both) {
$found_other_pair = EnvironmentVariable::where('application_id', $application->id)->where('key', $found_env->key)->first();
if ($found_other_pair) {
$found_other_pair->delete();
}
}
return response()->json([ return response()->json([
'success' => true, 'success' => true,

View File

@ -12,7 +12,6 @@ public function delete_env_by_uuid(Request $request)
{ {
ray()->clearAll(); ray()->clearAll();
$teamId = get_team_id_from_token(); $teamId = get_team_id_from_token();
$both = $request->query->get('both') ?? false;
if (is_null($teamId)) { if (is_null($teamId)) {
return invalid_token(); return invalid_token();
} }
@ -31,12 +30,6 @@ public function delete_env_by_uuid(Request $request)
], 404); ], 404);
} }
$env->delete(); $env->delete();
if ($both) {
$found_other_pair = EnvironmentVariable::where('application_id', $found_app->id)->where('key', $env->key)->first();
if ($found_other_pair) {
$found_other_pair->delete();
}
}
return response()->json([ return response()->json([
'success' => true, 'success' => true,