This commit is contained in:
@@ -145,36 +145,19 @@ export class AuthService {
|
||||
}
|
||||
|
||||
const { rawToken, hash, prefix, expiresAt } = await this.generateDeviceToken();
|
||||
let deviceId: string;
|
||||
|
||||
// One device per venue — update existing or create new
|
||||
const existing = await this.prisma.device.findFirst({ where: { venueId } });
|
||||
if (existing) {
|
||||
deviceId = existing.id;
|
||||
await this.prisma.device.update({
|
||||
where: { id: existing.id },
|
||||
data: {
|
||||
name,
|
||||
tokenHash: hash,
|
||||
tokenPrefix: prefix,
|
||||
tokenExpiresAt: expiresAt,
|
||||
revokedAt: null,
|
||||
lastSeenAt: new Date(),
|
||||
},
|
||||
});
|
||||
} else {
|
||||
deviceId = uuidv4();
|
||||
await this.prisma.device.create({
|
||||
data: {
|
||||
id: deviceId,
|
||||
venueId,
|
||||
name,
|
||||
tokenHash: hash,
|
||||
tokenPrefix: prefix,
|
||||
tokenExpiresAt: expiresAt,
|
||||
},
|
||||
});
|
||||
}
|
||||
// A venue can have several terminals: every pairing adds one. A terminal that is replaced is unpaired on the
|
||||
// dashboard
|
||||
const deviceId = uuidv4();
|
||||
await this.prisma.device.create({
|
||||
data: {
|
||||
id: deviceId,
|
||||
venueId,
|
||||
name,
|
||||
tokenHash: hash,
|
||||
tokenPrefix: prefix,
|
||||
tokenExpiresAt: expiresAt,
|
||||
},
|
||||
});
|
||||
|
||||
await this.auditService.log(venueId, 'device', deviceId, 'device_registered', { deviceName: name });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user