From e1f8e42112e24f02639a7867e4f7d82713f027ce Mon Sep 17 00:00:00 2001 From: nguyentrungthat <80239428+nguentrungthat@users.noreply.github.com> Date: Tue, 20 Jan 2026 10:51:51 +0700 Subject: [PATCH] Update note from user --- BACKEND/app/services/line_connection.ts | 22 +++++++++++ BACKEND/app/ultils/helper.ts | 12 ++++-- BACKEND/providers/socket_io_provider.ts | 26 +++++++++++-- .../src/components/Modal/ModalTerminal.tsx | 38 +++++++++++++++++-- 4 files changed, 89 insertions(+), 9 deletions(-) diff --git a/BACKEND/app/services/line_connection.ts b/BACKEND/app/services/line_connection.ts index e4dcf4b..5fc5819 100644 --- a/BACKEND/app/services/line_connection.ts +++ b/BACKEND/app/services/line_connection.ts @@ -1042,6 +1042,28 @@ export default class LineConnection { await updateNoteToERP(sn, note) } + /** + * Update note of SN to ERP from user input + */ + async updateNoteFromUser(sn: string, note: string, licenses: string[]) { + const timeZone = process.env.TIME_ZONE || 'Australia/Sydney' + const dataFormat = momentTZ().tz(timeZone).format('YYYY/MM/DD, HH:mm') + const data = `-------[ATC]-[${dataFormat}]-------\nLicense: ${licenses.join(', ')}\nIssues:\n${note}\n\n` + const issueList = note + .split('\n') + .map((line) => (line[0] === '-' ? line.substring(1).trim() : line.trim())) + + const detectAI = this.config?.latestScenario?.detectAI + ? { ...this.config.latestScenario.detectAI, issue: issueList } + : { issue: issueList, summary: '', status: [] } + + if (this.config.latestScenario) { + this.config.latestScenario = { ...this.config.latestScenario, detectAI } + } + + await updateNoteToERP(sn, data) + } + /** * Starting physical test (PoE ports testing) */ diff --git a/BACKEND/app/ultils/helper.ts b/BACKEND/app/ultils/helper.ts index 53c61c0..b8206b3 100644 --- a/BACKEND/app/ultils/helper.ts +++ b/BACKEND/app/ultils/helper.ts @@ -639,11 +639,17 @@ export async function updateNoteToERP(sn: string, note: string) { } ) + // console.log('updateNoteToERP', responseDataSN?.data?.data) if (!responseDataSN?.data?.data || responseDataSN?.data?.data?.length === 0) { - console.log('updateNoteToERP', responseDataSN?.data) return } - const dataSN = responseDataSN?.data?.data[0] || {} + const dataSN = + responseDataSN?.data?.data.length === 1 + ? responseDataSN?.data?.data[0] + : responseDataSN?.data?.data.length > 1 + ? responseDataSN?.data?.data.find((el: any) => el.serialNumberA === sn) + : {} + if (!dataSN?.id) return const payload = { id: dataSN?.id, @@ -664,7 +670,7 @@ export async function updateNoteToERP(sn: string, note: string) { } ) } catch (error) { - console.log(error) + console.log('updateNoteToERP', error) } } diff --git a/BACKEND/providers/socket_io_provider.ts b/BACKEND/providers/socket_io_provider.ts index ec6d0b8..c10bf31 100644 --- a/BACKEND/providers/socket_io_provider.ts +++ b/BACKEND/providers/socket_io_provider.ts @@ -812,6 +812,24 @@ export class WebSocketIo { {} ) }) + + socket.on('update_note', async (data) => { + console.log('Update note', data) + const { stationId, lineId, note, licenses, sn } = data + // Check station is active + const activeStation = await checkStationActive(stationId) + if (!activeStation) return + + await this.handleLineOperation( + io, + stationId, + [lineId], + async (lineCon) => { + lineCon.updateNoteFromUser(sn, note, licenses) + }, + {} + ) + }) }) socketServer.listen(SOCKET_IO_PORT, () => { @@ -830,7 +848,8 @@ export class WebSocketIo { station: Station, output = '', inventory: string = '', - latestScenario?: any + latestScenario?: any, + data?: any ) { try { for (const line of lines) { @@ -851,7 +870,7 @@ export class WebSocketIo { openCLI: false, userEmailOpenCLI: '', userOpenCLI: '', - data: [], + data: data, ports: [], inventory: inventory, runningPhysical: false, @@ -941,7 +960,8 @@ export class WebSocketIo { stationData, line?.config?.output || '', line?.config?.inventory || '', - line?.config?.latestScenario || undefined + line?.config?.latestScenario || undefined, + line?.config?.data || [] ) this.lineConnecting = this.lineConnecting.filter((el) => el !== lineId) diff --git a/FRONTEND/src/components/Modal/ModalTerminal.tsx b/FRONTEND/src/components/Modal/ModalTerminal.tsx index ddf7206..889d34d 100644 --- a/FRONTEND/src/components/Modal/ModalTerminal.tsx +++ b/FRONTEND/src/components/Modal/ModalTerminal.tsx @@ -824,11 +824,43 @@ const ModalTerminal = ({ - - Warning from test report: AI - + + + Warning from test report: AI + + + +