diff --git a/src/external-api/kafka.ts b/src/external-api/kafka.ts index 76b99bb8..1037301d 100644 --- a/src/external-api/kafka.ts +++ b/src/external-api/kafka.ts @@ -113,7 +113,7 @@ async function produceDeviceRegistrationEvent( } try { - const kafkaCoordinates: DeviceLocation | null = coordinates ? { type: 'Point', coordinates } : null; + const kafkaCoordinates: DeviceLocation | null = coordinates ? { type: 'POINT', coordinates } : null; await kafka.send(device.name, encodeDeviceForInventoryKafka(device, kafkaCoordinates, labelIds), { type: 'device_registration', }); @@ -153,7 +153,7 @@ async function produceDeviceUpdateEvent( } try { - const kafkaCoordinates: DeviceLocation | null = coordinates ? { type: 'Point', coordinates } : null; + const kafkaCoordinates: DeviceLocation | null = coordinates ? { type: 'POINT', coordinates } : null; await kafka.send(device.name, encodeDeviceForInventoryKafka(device, kafkaCoordinates, labelIds), { type: 'device_update', }); diff --git a/src/helpers/device-helpers.ts b/src/helpers/device-helpers.ts index 75aa2ba7..abdba38a 100644 --- a/src/helpers/device-helpers.ts +++ b/src/helpers/device-helpers.ts @@ -91,7 +91,7 @@ export function makeZonesWithDevicesFromDevices(devices: Device[]) { } export type DeviceLocation = { - type: 'Point'; + type: 'POINT'; coordinates: [number, number]; }; diff --git a/src/schema/device.ts b/src/schema/device.ts index 22ef518a..e0c1bdc4 100644 --- a/src/schema/device.ts +++ b/src/schema/device.ts @@ -293,9 +293,10 @@ export const AddDeviceMutation = extendType({ resolve: async (_, args, { prisma, tenantId, kafka, inventoryKafka }) => { const { input } = args; const nativeZoneId = fromGraphId('Zone', input.zoneId); + const nativeLocationId = input.locationId ? fromGraphId('Location', input.locationId) : null; const zone = await prisma.uniconfigZone.findFirst({ where: { tenantId, id: nativeZoneId } }); const deviceLocation = await prisma.location.findFirst({ - where: { id: input.locationId ?? undefined }, + where: { id: nativeLocationId ?? undefined }, }); if (zone == null) { @@ -430,6 +431,7 @@ export const UpdateDeviceMutation = extendType({ ...oldMetadata, deviceSize: input.deviceSize, }; + const updatedDevice = await prisma.device.update({ where: { id: nativeId }, data: { @@ -443,7 +445,11 @@ export const UpdateDeviceMutation = extendType({ password: input.password, port: input.port, serviceState: input.serviceState ?? undefined, - location: input.locationId ? { connect: { id: fromGraphId('Location', input.locationId) } } : undefined, + location: input.locationId + ? { connect: { id: fromGraphId('Location', input.locationId) } } + : { + disconnect: true, + }, blueprint: input.blueprintId ? { connect: { id: fromGraphId('Blueprint', input.blueprintId) } } : undefined, diff --git a/src/test/helpers.ts b/src/test/helpers.ts index afdc4a05..60ba6c11 100644 --- a/src/test/helpers.ts +++ b/src/test/helpers.ts @@ -57,7 +57,7 @@ async function produceDeviceRegistrationEventMock( } try { - await kafka.send(device.name, encodeDeviceForInventoryKafka(device, { type: 'Point', coordinates }, labelIds), { + await kafka.send(device.name, encodeDeviceForInventoryKafka(device, { type: 'POINT', coordinates }, labelIds), { type: 'device_registration', }); } catch (error) { @@ -96,7 +96,7 @@ async function produceDeviceUpdateEventMock( } try { - await kafka.send(device.name, encodeDeviceForInventoryKafka(device, { type: 'Point', coordinates }, labelIds), { + await kafka.send(device.name, encodeDeviceForInventoryKafka(device, { type: 'POINT', coordinates }, labelIds), { type: 'device_update', }); } catch (error) {