fix: sanitize device identifier and explicitly enable device
- Lowercase and strip non-alphanumeric chars from device ID - Explicitly set disabled=false when creating device in Traccar - Use the uniqueId returned by Traccar (ensures consistency) - Add logging for debugging device creation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -162,8 +162,10 @@ export class GpsService implements OnModuleInit {
|
||||
throw new BadRequestException('Driver is already enrolled for GPS tracking');
|
||||
}
|
||||
|
||||
// Generate unique device identifier (no special characters for better compatibility)
|
||||
const deviceIdentifier = `vipdriver${driverId.replace(/-/g, '').slice(0, 8)}`;
|
||||
// Generate unique device identifier (lowercase alphanumeric only for compatibility)
|
||||
const deviceIdentifier = `vipdriver${driverId.replace(/-/g, '').slice(0, 8)}`.toLowerCase();
|
||||
|
||||
this.logger.log(`Enrolling driver ${driver.name} with device identifier: ${deviceIdentifier}`);
|
||||
|
||||
// Create device in Traccar
|
||||
const traccarDevice = await this.traccarClient.createDevice(
|
||||
@@ -172,12 +174,16 @@ export class GpsService implements OnModuleInit {
|
||||
driver.phone || undefined,
|
||||
);
|
||||
|
||||
// Use the uniqueId returned by Traccar (in case it was modified)
|
||||
const actualDeviceId = traccarDevice.uniqueId;
|
||||
this.logger.log(`Traccar returned device with uniqueId: ${actualDeviceId}`);
|
||||
|
||||
// Create GPS device record (consent pre-approved by HR at hiring)
|
||||
await this.prisma.gpsDevice.create({
|
||||
data: {
|
||||
driverId,
|
||||
traccarDeviceId: traccarDevice.id,
|
||||
deviceIdentifier,
|
||||
deviceIdentifier: actualDeviceId, // Use what Traccar actually stored
|
||||
consentGiven: true,
|
||||
consentGivenAt: new Date(),
|
||||
},
|
||||
@@ -194,7 +200,7 @@ GPS Tracking Setup Instructions for ${driver.name}:
|
||||
- Android: https://play.google.com/store/apps/details?id=org.traccar.client
|
||||
|
||||
2. Open the app and configure:
|
||||
- Device identifier: ${deviceIdentifier}
|
||||
- Device identifier: ${actualDeviceId}
|
||||
- Server URL: ${serverUrl}
|
||||
- Frequency: ${settings.updateIntervalSeconds} seconds
|
||||
- Location accuracy: High
|
||||
@@ -226,7 +232,7 @@ Note: GPS tracking is only active during shift hours (${settings.shiftStartHour}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
deviceIdentifier,
|
||||
deviceIdentifier: actualDeviceId, // Return what Traccar actually stored
|
||||
serverUrl,
|
||||
instructions,
|
||||
signalMessageSent,
|
||||
|
||||
Reference in New Issue
Block a user