fix: include mapped names in test map show

This commit is contained in:
mahdahar 2026-04-15 09:29:08 +07:00
parent 52c4680d3d
commit 5a7b9b257e
3 changed files with 64 additions and 14 deletions

View File

@ -61,7 +61,7 @@ class TestMapController extends BaseController {
}
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); }
$row = ValueSet::transformLabels([$row], [

View File

@ -80,6 +80,52 @@ class TestMapModel extends BaseModel {
])->getResultArray();
}
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.*')
->join('testmapdetail', 'testmapdetail.TestMapID = testmap.TestMapID', 'inner')

View File

@ -53,7 +53,11 @@ class TestMapPatchTest extends CIUnitTestCase
$show = $this->withHeaders($this->authHeaders())->call('get', "{$this->endpoint}/{$id}");
$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()