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