fix: include mapped names in test map show
This commit is contained in:
parent
52c4680d3d
commit
5a7b9b257e
@ -60,9 +60,9 @@ class TestMapController extends BaseController {
|
|||||||
return $this->respond([ 'status' => 'success', 'message'=> "Data fetched successfully", 'data' => $rows ], 200);
|
return $this->respond([ 'status' => 'success', 'message'=> "Data fetched successfully", 'data' => $rows ], 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function show($id = null) {
|
public function show($id = null) {
|
||||||
$row = $this->model->where('TestMapID',$id)->where('EndDate', null)->first();
|
$row = $this->model->getByIdWithNames($id);
|
||||||
if (empty($row)) { return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => null ], 200); }
|
if (empty($row)) { return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => null ], 200); }
|
||||||
|
|
||||||
$row = ValueSet::transformLabels([$row], [
|
$row = ValueSet::transformLabels([$row], [
|
||||||
'HostType' => 'entity_type',
|
'HostType' => 'entity_type',
|
||||||
|
|||||||
@ -35,7 +35,7 @@ class TestMapModel extends BaseModel {
|
|||||||
/**
|
/**
|
||||||
* Get all test mappings with names
|
* Get all test mappings with names
|
||||||
*/
|
*/
|
||||||
public function getUniqueGroupings() {
|
public function getUniqueGroupings() {
|
||||||
$db = $this->db;
|
$db = $this->db;
|
||||||
$types = $this->getEntityTypes();
|
$types = $this->getEntityTypes();
|
||||||
|
|
||||||
@ -72,15 +72,61 @@ class TestMapModel extends BaseModel {
|
|||||||
WHERE tm.EndDate IS NULL
|
WHERE tm.EndDate IS NULL
|
||||||
";
|
";
|
||||||
|
|
||||||
return $db->query($sql, [
|
return $db->query($sql, [
|
||||||
$siteType, $wsType, $instType,
|
$siteType, $wsType, $instType,
|
||||||
$siteType, $wsType, $instType,
|
$siteType, $wsType, $instType,
|
||||||
$siteType, $wsType, $instType,
|
$siteType, $wsType, $instType,
|
||||||
$siteType, $wsType, $instType
|
$siteType, $wsType, $instType
|
||||||
])->getResultArray();
|
])->getResultArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getMappingsByTestCode($testCode) {
|
public function getByIdWithNames($id) {
|
||||||
|
$db = $this->db;
|
||||||
|
$types = $this->getEntityTypes();
|
||||||
|
|
||||||
|
$siteType = $types['SITE'] ?? 'SITE';
|
||||||
|
$wsType = $types['WST'] ?? 'WST';
|
||||||
|
$instType = $types['INST'] ?? 'INST';
|
||||||
|
|
||||||
|
$sql = "
|
||||||
|
SELECT
|
||||||
|
tm.*,
|
||||||
|
CASE
|
||||||
|
WHEN tm.HostType = ? THEN s.SiteName
|
||||||
|
WHEN tm.HostType = ? THEN ws.WorkstationName
|
||||||
|
WHEN tm.HostType = ? THEN el.InstrumentName
|
||||||
|
ELSE tm.HostID
|
||||||
|
END as HostName,
|
||||||
|
CASE
|
||||||
|
WHEN tm.ClientType = ? THEN cs.SiteName
|
||||||
|
WHEN tm.ClientType = ? THEN cws.WorkstationName
|
||||||
|
WHEN tm.ClientType = ? THEN cel.InstrumentName
|
||||||
|
ELSE tm.ClientID
|
||||||
|
END as ClientName
|
||||||
|
FROM testmap tm
|
||||||
|
LEFT JOIN site s ON tm.HostType = ? AND s.SiteID = tm.HostID
|
||||||
|
LEFT JOIN workstation ws ON tm.HostType = ? AND ws.WorkstationID = tm.HostID
|
||||||
|
LEFT JOIN equipmentlist el ON tm.HostType = ? AND el.EID = tm.HostID
|
||||||
|
LEFT JOIN site cs ON tm.ClientType = ? AND cs.SiteID = tm.ClientID
|
||||||
|
LEFT JOIN workstation cws ON tm.ClientType = ? AND cws.WorkstationID = tm.ClientID
|
||||||
|
LEFT JOIN equipmentlist cel ON tm.ClientType = ? AND cel.EID = tm.ClientID
|
||||||
|
WHERE tm.TestMapID = ?
|
||||||
|
AND tm.EndDate IS NULL
|
||||||
|
LIMIT 1
|
||||||
|
";
|
||||||
|
|
||||||
|
$rows = $db->query($sql, [
|
||||||
|
$siteType, $wsType, $instType,
|
||||||
|
$siteType, $wsType, $instType,
|
||||||
|
$siteType, $wsType, $instType,
|
||||||
|
$siteType, $wsType, $instType,
|
||||||
|
$id,
|
||||||
|
])->getResultArray();
|
||||||
|
|
||||||
|
return $rows[0] ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMappingsByTestCode($testCode) {
|
||||||
return $this->select('testmap.*')
|
return $this->select('testmap.*')
|
||||||
->join('testmapdetail', 'testmapdetail.TestMapID = testmap.TestMapID', 'inner')
|
->join('testmapdetail', 'testmapdetail.TestMapID = testmap.TestMapID', 'inner')
|
||||||
->groupStart()
|
->groupStart()
|
||||||
|
|||||||
@ -53,7 +53,11 @@ class TestMapPatchTest extends CIUnitTestCase
|
|||||||
|
|
||||||
$show = $this->withHeaders($this->authHeaders())->call('get', "{$this->endpoint}/{$id}");
|
$show = $this->withHeaders($this->authHeaders())->call('get', "{$this->endpoint}/{$id}");
|
||||||
$show->assertStatus(200);
|
$show->assertStatus(200);
|
||||||
return json_decode($show->getJSON(), true)['data'];
|
$showData = json_decode($show->getJSON(), true)['data'];
|
||||||
|
$this->assertArrayHasKey('HostName', $showData);
|
||||||
|
$this->assertArrayHasKey('ClientName', $showData);
|
||||||
|
|
||||||
|
return $showData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPartialUpdateTestMapSuccess()
|
public function testPartialUpdateTestMapSuccess()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user