Updated alignment for controller
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled

This commit is contained in:
dhanabalan
2026-01-28 16:07:33 +05:30
parent d74e1d73c9
commit eb343f1d0c

View File

@@ -33,29 +33,28 @@ class MachineController extends Controller
public function get_all_data(Request $request) public function get_all_data(Request $request)
{ {
$expectedUser = env('API_AUTH_USER'); $expectedUser = env('API_AUTH_USER');
$expectedPw = env('API_AUTH_PW'); $expectedPw = env('API_AUTH_PW');
$header_auth = $request->header('Authorization'); $header_auth = $request->header('Authorization');
$expectedToken = $expectedUser . ':' . $expectedPw; $expectedToken = $expectedUser.':'.$expectedPw;
if ("Bearer " . $expectedToken != $header_auth) if ('Bearer '.$expectedToken != $header_auth) {
{
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => 'Invalid authorization token!' 'status_description' => 'Invalid authorization token!',
], 403); ], 403);
} }
$machines = Machine::with('plant')->with('workGroupMaster')->orderBy('plant_id')->get(); $machines = Machine::with('plant')->with('workGroupMaster')->orderBy('plant_id')->get();
$machinesData = $machines->map(function($machine) { $machinesData = $machines->map(function ($machine) {
return [ return [
'plant_code' => $machine->plant ? (String)$machine->plant->code : "", 'plant_code' => $machine->plant ? (string) $machine->plant->code : '',
'group_work_center' => $machine->workGroupMaster ? (String)$machine->workGroupMaster->name : "", 'group_work_center' => $machine->workGroupMaster ? (string) $machine->workGroupMaster->name : '',
'work_center' => $machine->work_center ?? "", 'work_center' => $machine->work_center ?? '',
]; ];
}); });
return response()->json([ return response()->json([
'machines' => $machinesData 'machines' => $machinesData,
]); ]);
} }
@@ -65,80 +64,70 @@ class MachineController extends Controller
public function get_data(Request $request) public function get_data(Request $request)
{ {
$expectedUser = env('API_AUTH_USER'); $expectedUser = env('API_AUTH_USER');
$expectedPw = env('API_AUTH_PW'); $expectedPw = env('API_AUTH_PW');
$header_auth = $request->header('Authorization'); $header_auth = $request->header('Authorization');
$expectedToken = $expectedUser . ':' . $expectedPw; $expectedToken = $expectedUser.':'.$expectedPw;
if ("Bearer " . $expectedToken != $header_auth) if ('Bearer '.$expectedToken != $header_auth) {
{
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => 'Invalid authorization token!' 'status_description' => 'Invalid authorization token!',
], 403); ], 403);
} }
$plantCode = $request->header('plant-code'); $plantCode = $request->header('plant-code');
$lineName = $request->header('line-name'); $lineName = $request->header('line-name');
if ($plantCode == null || $plantCode == '') if ($plantCode == null || $plantCode == '') {
{
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => "Plant code can't be empty!" 'status_description' => "Plant code can't be empty!",
], 400); ], 400);
} } elseif (Str::length($plantCode) < 4 || ! is_numeric($plantCode) || ! preg_match('/^[1-9]\d{3,}$/', $plantCode)) {
else if (Str::length($plantCode) < 4 || !is_numeric($plantCode) || !preg_match('/^[1-9]\d{3,}$/', $plantCode))
{
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => "Invalid plant code found!" 'status_description' => 'Invalid plant code found!',
], 400); ], 400);
} } elseif ($lineName == null || $lineName == '' || Str::length($lineName) <= 0) {
else if ($lineName == null || $lineName == '' || Str::length($lineName) <= 0)
{
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => "Line name can't be empty!" 'status_description' => "Line name can't be empty!",
], 400); ], 400);
} }
$plant = Plant::where('code', $plantCode)->first(); $plant = Plant::where('code', $plantCode)->first();
if (!$plant) if (! $plant) {
{
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => "Plant Code '{$plantCode}' not found!" 'status_description' => "Plant Code '{$plantCode}' not found!",
], 400); ], 400);
} }
$plantId = $plant->id; $plantId = $plant->id;
$line = Line::where('name', $lineName)->first(); $line = Line::where('name', $lineName)->first();
if (!$line) if (! $line) {
{
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => "Line Name '{$lineName}' not found!" 'status_description' => "Line Name '{$lineName}' not found!",
], 400); ], 400);
} }
$line = Line::where('name', $lineName)->where('plant_id', $plantId)->first(); $line = Line::where('name', $lineName)->where('plant_id', $plantId)->first();
if (!$line) if (! $line) {
{
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => "Line Name '{$lineName}' not found for the plant!" 'status_description' => "Line Name '{$lineName}' not found for the plant!",
], 400); ], 400);
} }
$lineId = $line->id;//no_of_operation $lineId = $line->id; // no_of_operation
$lineWorkGroup1Id = $line->work_group1_id; $lineWorkGroup1Id = $line->work_group1_id;
$lineWorkGroup2Id = $line->work_group2_id; $lineWorkGroup2Id = $line->work_group2_id;
if ($line->no_of_operation == null || $line->no_of_operation == '' || $line->no_of_operation == 0 || !is_numeric($line->no_of_operation)) if ($line->no_of_operation == null || $line->no_of_operation == '' || $line->no_of_operation == 0 || ! is_numeric($line->no_of_operation)) {
{
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => "Group work center not found for the plant & line!" 'status_description' => 'Group work center not found for the plant & line!',
], 400); ], 400);
} }
@@ -146,26 +135,22 @@ class MachineController extends Controller
$lineWorkGroupIds = []; $lineWorkGroupIds = [];
for ($i = 1; $i <= $line->no_of_operation; $i++) { for ($i = 1; $i <= $line->no_of_operation; $i++) {
$curWorkGroupId = $line->{"work_group{$i}_id"}; $curWorkGroupId = $line->{"work_group{$i}_id"};
if (in_array($curWorkGroupId, $lineWorkGroupIds)) if (in_array($curWorkGroupId, $lineWorkGroupIds)) {
{
continue; continue;
} } else {
else
{
$lineWorkGroupIds[] = $curWorkGroupId; $lineWorkGroupIds[] = $curWorkGroupId;
} }
$test[] = [ $test[] = [
'group_work_center' => WorkGroupMaster::where('id', $curWorkGroupId)->first()->name ?? "", 'group_work_center' => WorkGroupMaster::where('id', $curWorkGroupId)->first()->name ?? '',
'operation_number' => WorkGroupMaster::where('id', $curWorkGroupId)->first()->operation_number ?? "", 'operation_number' => WorkGroupMaster::where('id', $curWorkGroupId)->first()->operation_number ?? '',
'work_centers' => Machine::where('plant_id', $plantId)->where('work_group_master_id', $curWorkGroupId)->orderBy('work_center')->pluck('work_center')->toArray() ?? [], 'work_centers' => Machine::where('plant_id', $plantId)->where('work_group_master_id', $curWorkGroupId)->orderBy('work_center')->pluck('work_center')->toArray() ?? [],
]; ];
} }
if($lineWorkGroupIds) if ($lineWorkGroupIds) {
{
return response()->json([ return response()->json([
'machines' => $test 'machines' => $test,
]); ]);
} }
// $machines = Machine::with('plant')->with('workGroupMaster')->orderBy('plant_id')->get(); // $machines = Machine::with('plant')->with('workGroupMaster')->orderBy('plant_id')->get();