Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FD-711 missing geolocation in kafka event fix #474

Merged
merged 3 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/external-api/kafka.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
});
Expand Down Expand Up @@ -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',
});
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/device-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export function makeZonesWithDevicesFromDevices(devices: Device[]) {
}

export type DeviceLocation = {
type: 'Point';
type: 'POINT';
coordinates: [number, number];
};

Expand Down
10 changes: 8 additions & 2 deletions src/schema/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -430,6 +431,7 @@ export const UpdateDeviceMutation = extendType({
...oldMetadata,
deviceSize: input.deviceSize,
};

const updatedDevice = await prisma.device.update({
where: { id: nativeId },
data: {
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/test/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
Loading