Updated alignment for controller
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
This commit is contained in:
@@ -33,29 +33,28 @@ class MachineController extends Controller
|
||||
public function get_all_data(Request $request)
|
||||
{
|
||||
$expectedUser = env('API_AUTH_USER');
|
||||
$expectedPw = env('API_AUTH_PW');
|
||||
$header_auth = $request->header('Authorization');
|
||||
$expectedToken = $expectedUser . ':' . $expectedPw;
|
||||
$expectedPw = env('API_AUTH_PW');
|
||||
$header_auth = $request->header('Authorization');
|
||||
$expectedToken = $expectedUser.':'.$expectedPw;
|
||||
|
||||
if ("Bearer " . $expectedToken != $header_auth)
|
||||
{
|
||||
if ('Bearer '.$expectedToken != $header_auth) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => 'Invalid authorization token!'
|
||||
'status_description' => 'Invalid authorization token!',
|
||||
], 403);
|
||||
}
|
||||
|
||||
$machines = Machine::with('plant')->with('workGroupMaster')->orderBy('plant_id')->get();
|
||||
$machinesData = $machines->map(function($machine) {
|
||||
$machinesData = $machines->map(function ($machine) {
|
||||
return [
|
||||
'plant_code' => $machine->plant ? (String)$machine->plant->code : "",
|
||||
'group_work_center' => $machine->workGroupMaster ? (String)$machine->workGroupMaster->name : "",
|
||||
'work_center' => $machine->work_center ?? "",
|
||||
'plant_code' => $machine->plant ? (string) $machine->plant->code : '',
|
||||
'group_work_center' => $machine->workGroupMaster ? (string) $machine->workGroupMaster->name : '',
|
||||
'work_center' => $machine->work_center ?? '',
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'machines' => $machinesData
|
||||
'machines' => $machinesData,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -65,80 +64,70 @@ class MachineController extends Controller
|
||||
public function get_data(Request $request)
|
||||
{
|
||||
$expectedUser = env('API_AUTH_USER');
|
||||
$expectedPw = env('API_AUTH_PW');
|
||||
$header_auth = $request->header('Authorization');
|
||||
$expectedToken = $expectedUser . ':' . $expectedPw;
|
||||
$expectedPw = env('API_AUTH_PW');
|
||||
$header_auth = $request->header('Authorization');
|
||||
$expectedToken = $expectedUser.':'.$expectedPw;
|
||||
|
||||
if ("Bearer " . $expectedToken != $header_auth)
|
||||
{
|
||||
if ('Bearer '.$expectedToken != $header_auth) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => 'Invalid authorization token!'
|
||||
'status_description' => 'Invalid authorization token!',
|
||||
], 403);
|
||||
}
|
||||
|
||||
$plantCode = $request->header('plant-code');
|
||||
$lineName = $request->header('line-name');
|
||||
|
||||
if ($plantCode == null || $plantCode == '')
|
||||
{
|
||||
if ($plantCode == null || $plantCode == '') {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Plant code can't be empty!"
|
||||
'status_description' => "Plant code can't be empty!",
|
||||
], 400);
|
||||
}
|
||||
else if (Str::length($plantCode) < 4 || !is_numeric($plantCode) || !preg_match('/^[1-9]\d{3,}$/', $plantCode))
|
||||
{
|
||||
} elseif (Str::length($plantCode) < 4 || ! is_numeric($plantCode) || ! preg_match('/^[1-9]\d{3,}$/', $plantCode)) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Invalid plant code found!"
|
||||
'status_description' => 'Invalid plant code found!',
|
||||
], 400);
|
||||
}
|
||||
else if ($lineName == null || $lineName == '' || Str::length($lineName) <= 0)
|
||||
{
|
||||
} elseif ($lineName == null || $lineName == '' || Str::length($lineName) <= 0) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Line name can't be empty!"
|
||||
'status_description' => "Line name can't be empty!",
|
||||
], 400);
|
||||
}
|
||||
|
||||
$plant = Plant::where('code', $plantCode)->first();
|
||||
if (!$plant)
|
||||
{
|
||||
if (! $plant) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Plant Code '{$plantCode}' not found!"
|
||||
'status_description' => "Plant Code '{$plantCode}' not found!",
|
||||
], 400);
|
||||
}
|
||||
|
||||
$plantId = $plant->id;
|
||||
|
||||
$line = Line::where('name', $lineName)->first();
|
||||
if (!$line)
|
||||
{
|
||||
if (! $line) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Line Name '{$lineName}' not found!"
|
||||
'status_description' => "Line Name '{$lineName}' not found!",
|
||||
], 400);
|
||||
}
|
||||
|
||||
$line = Line::where('name', $lineName)->where('plant_id', $plantId)->first();
|
||||
if (!$line)
|
||||
{
|
||||
if (! $line) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Line Name '{$lineName}' not found for the plant!"
|
||||
'status_description' => "Line Name '{$lineName}' not found for the plant!",
|
||||
], 400);
|
||||
}
|
||||
|
||||
$lineId = $line->id;//no_of_operation
|
||||
$lineId = $line->id; // no_of_operation
|
||||
$lineWorkGroup1Id = $line->work_group1_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([
|
||||
'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);
|
||||
}
|
||||
|
||||
@@ -146,26 +135,22 @@ class MachineController extends Controller
|
||||
$lineWorkGroupIds = [];
|
||||
for ($i = 1; $i <= $line->no_of_operation; $i++) {
|
||||
$curWorkGroupId = $line->{"work_group{$i}_id"};
|
||||
if (in_array($curWorkGroupId, $lineWorkGroupIds))
|
||||
{
|
||||
if (in_array($curWorkGroupId, $lineWorkGroupIds)) {
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$lineWorkGroupIds[] = $curWorkGroupId;
|
||||
}
|
||||
|
||||
$test[] = [
|
||||
'group_work_center' => WorkGroupMaster::where('id', $curWorkGroupId)->first()->name ?? "",
|
||||
'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() ?? [],
|
||||
'group_work_center' => WorkGroupMaster::where('id', $curWorkGroupId)->first()->name ?? '',
|
||||
'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() ?? [],
|
||||
];
|
||||
}
|
||||
|
||||
if($lineWorkGroupIds)
|
||||
{
|
||||
if ($lineWorkGroupIds) {
|
||||
return response()->json([
|
||||
'machines' => $test
|
||||
'machines' => $test,
|
||||
]);
|
||||
}
|
||||
// $machines = Machine::with('plant')->with('workGroupMaster')->orderBy('plant_id')->get();
|
||||
|
||||
Reference in New Issue
Block a user