From 1b24cd975407179d625f8328fea8bf8d1152f7e0 Mon Sep 17 00:00:00 2001 From: isra el Date: Fri, 6 Feb 2026 18:33:55 +0300 Subject: [PATCH] feat(api): set custom device name --- api/src/gateway/gateway.dto.ts | 10 ++++++++++ api/src/gateway/gateway.service.ts | 9 +++++++++ api/src/gateway/schemas/device.schema.ts | 3 +++ 3 files changed, 22 insertions(+) diff --git a/api/src/gateway/gateway.dto.ts b/api/src/gateway/gateway.dto.ts index ad7c3e4..63df517 100644 --- a/api/src/gateway/gateway.dto.ts +++ b/api/src/gateway/gateway.dto.ts @@ -56,6 +56,9 @@ export class RegisterDeviceInputDTO { @ApiProperty({ type: String }) model?: string + @ApiProperty({ type: String, required: false }) + name?: string + @ApiProperty({ type: String }) serial?: string @@ -490,4 +493,11 @@ export class HeartbeatResponseDTO { description: 'Server timestamp of the heartbeat', }) lastHeartbeat: Date + + @ApiProperty({ + type: String, + required: false, + description: 'Device name (if updated)', + }) + name?: string } diff --git a/api/src/gateway/gateway.service.ts b/api/src/gateway/gateway.service.ts index a34480e..32467ec 100644 --- a/api/src/gateway/gateway.service.ts +++ b/api/src/gateway/gateway.service.ts @@ -48,6 +48,11 @@ export class GatewayService { const deviceData: any = { ...input, user } + // Set default name to "brand model" if not provided + if (!deviceData.name && input.brand && input.model) { + deviceData.name = `${input.brand} ${input.model}` + } + // Handle simInfo if provided if (input.simInfo) { deviceData.simInfo = { @@ -1142,10 +1147,14 @@ const updatedSms = await this.smsModel.findByIdAndUpdate( $set: updateData, }) + // Fetch updated device to get current name + const updatedDevice = await this.deviceModel.findById(deviceId) + return { success: true, fcmTokenUpdated, lastHeartbeat: now, + name: updatedDevice?.name, } } } diff --git a/api/src/gateway/schemas/device.schema.ts b/api/src/gateway/schemas/device.schema.ts index 46ad1dd..7bdb2d2 100644 --- a/api/src/gateway/schemas/device.schema.ts +++ b/api/src/gateway/schemas/device.schema.ts @@ -26,6 +26,9 @@ export class Device { @Prop({ type: String }) model: string + @Prop({ type: String, required: false }) + name?: string + @Prop({ type: String }) serial: string