feat(api): set custom device name

This commit is contained in:
isra el
2026-02-06 18:33:55 +03:00
parent e6ad6a18dc
commit 1b24cd9754
3 changed files with 22 additions and 0 deletions

View File

@@ -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
}

View File

@@ -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,
}
}
}

View File

@@ -26,6 +26,9 @@ export class Device {
@Prop({ type: String })
model: string
@Prop({ type: String, required: false })
name?: string
@Prop({ type: String })
serial: string