mirror of
https://github.com/vernu/textbee.git
synced 2026-02-20 07:34:00 -05:00
feat(api): set custom device name
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,9 @@ export class Device {
|
||||
@Prop({ type: String })
|
||||
model: string
|
||||
|
||||
@Prop({ type: String, required: false })
|
||||
name?: string
|
||||
|
||||
@Prop({ type: String })
|
||||
serial: string
|
||||
|
||||
|
||||
Reference in New Issue
Block a user