From ef7ea5c9af6b0707f63e26f0f82e4d9c2dcbb2c8 Mon Sep 17 00:00:00 2001
From: nguyentrungthat <80239428+nguentrungthat@users.noreply.github.com>
Date: Wed, 5 Nov 2025 09:10:25 +0700
Subject: [PATCH] Update
---
BACKEND/app/services/apc_connection.ts | 4 +--
...60_update_email_nullable_to_users_table.ts | 17 +++++++++++++
BACKEND/providers/socket_io_provider.ts | 9 ++++---
.../components/Authentication/Register.tsx | 4 +--
FRONTEND/src/components/DragTabs.tsx | 4 +--
FRONTEND/src/components/DrawerControl.tsx | 25 +++++++++----------
6 files changed, 41 insertions(+), 22 deletions(-)
create mode 100644 BACKEND/database/migrations/1762303852760_update_email_nullable_to_users_table.ts
diff --git a/BACKEND/app/services/apc_connection.ts b/BACKEND/app/services/apc_connection.ts
index 7ffc9b8..cb9c428 100644
--- a/BACKEND/app/services/apc_connection.ts
+++ b/BACKEND/app/services/apc_connection.ts
@@ -21,10 +21,10 @@ class APCController {
private apc_port: number
private apc_username: string
private apc_password: string
- private status: 'CONNECTED' | 'DISCONNECTED' | 'TIMEOUT'
+ public status: 'CONNECTED' | 'DISCONNECTED' | 'TIMEOUT'
private socket: Socket
private buffer: string
- private output: string
+ public output: string
private promptCallbacks: PromptCallback[]
private onData: (data: string, status: string) => void
private retryConnect: number
diff --git a/BACKEND/database/migrations/1762303852760_update_email_nullable_to_users_table.ts b/BACKEND/database/migrations/1762303852760_update_email_nullable_to_users_table.ts
new file mode 100644
index 0000000..96520b0
--- /dev/null
+++ b/BACKEND/database/migrations/1762303852760_update_email_nullable_to_users_table.ts
@@ -0,0 +1,17 @@
+import { BaseSchema } from '@adonisjs/lucid/schema'
+
+export default class extends BaseSchema {
+ protected tableName = 'users'
+
+ async up() {
+ this.schema.alterTable(this.tableName, (table) => {
+ table.string('email').nullable().alter()
+ })
+ }
+
+ async down() {
+ this.schema.alterTable(this.tableName, (table) => {
+ table.string('email').notNullable().alter()
+ })
+ }
+}
diff --git a/BACKEND/providers/socket_io_provider.ts b/BACKEND/providers/socket_io_provider.ts
index fb89aa5..ff4670a 100644
--- a/BACKEND/providers/socket_io_provider.ts
+++ b/BACKEND/providers/socket_io_provider.ts
@@ -249,10 +249,12 @@ export class WebSocketIo {
socket.on('connect_apc', async (data) => {
const { apcIp, station, apcName } = data
- if (this.apcsControl.has(apcIp)) {
+ const apc = this.apcsControl.get(apcIp)
+ if (apc && apc.status === 'CONNECTED') {
return
- }
- await this.connectApc(io, apcName, station)
+ } else if (apc && apc.status !== 'CONNECTED') {
+ await apc.reconnect()
+ } else await this.connectApc(io, apcName, station)
})
})
@@ -377,6 +379,7 @@ export class WebSocketIo {
port,
username,
password,
+ number: apcName === 'apc_1' ? 1 : 2,
onData: (data: string, status: string) => {
socket.emit('apc_output', {
stationId: station.id,
diff --git a/FRONTEND/src/components/Authentication/Register.tsx b/FRONTEND/src/components/Authentication/Register.tsx
index f8c059f..eb0a835 100644
--- a/FRONTEND/src/components/Authentication/Register.tsx
+++ b/FRONTEND/src/components/Authentication/Register.tsx
@@ -23,10 +23,10 @@ function Register() {
const handleRegister = async () => {
try {
- if (!formRegister.email) {
+ if (!formRegister.user_name) {
notifications.show({
title: "Error",
- message: "Email is required",
+ message: "Username is required",
color: "red",
});
return;
diff --git a/FRONTEND/src/components/DragTabs.tsx b/FRONTEND/src/components/DragTabs.tsx
index 5c9c286..ea5e913 100644
--- a/FRONTEND/src/components/DragTabs.tsx
+++ b/FRONTEND/src/components/DragTabs.tsx
@@ -263,7 +263,7 @@ export default function DraggableTabs({
/>
}
/>
-
+ {/*
-
+ */}
= ({
useEffect(() => {
socket?.on("apc_output", (data) => {
if (data.stationId !== stationAPI.id) return;
- let apcs: APCProps[] = [];
+ const outlets: TSelectedOutlet[] = [];
setDataStation((prev) => {
const apc1 =
data.apcNumber === 1
@@ -181,19 +181,18 @@ export const DrawerAPCControl: React.FC = ({
data.apcNumber === 2
? { ...prev.apc2, output: data.data, status: data.status }
: prev.apc2;
- apcs = [apc1, apc2];
- return prev.id === data.stationId
- ? { ...prev, apc1: apc1, apc2: apc2 }
- : prev;
- });
- const outlets: TSelectedOutlet[] = [];
- console.log("apcs", apcs);
- apcs.forEach(async (apc, i) => {
- const result: TSelectedOutlet[] = [];
- const lines = apc?.output?.split("\n") || [];
- await detectOutlet(apc, lines, result, i);
- outlets.push(...result);
+ [apc1, apc2].forEach(async (apc, i) => {
+ if (!apc) return;
+ const result: TSelectedOutlet[] = [];
+ const lines = apc?.output?.split("\n") || [];
+ await detectOutlet(apc, lines, result, i);
+ console.log("result", result);
+ outlets.push(...result);
+ });
+ return { ...prev, apc1: apc1, apc2: apc2 };
});
+ // console.log("outlets", outlets);
+
setListOutlet(outlets);
});
}, [socket]);