Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ export class DynamicIntegrationsController {
? SyncDefinitionSchema.parse(rawSyncDef)
: undefined;

const rawDeviceSyncDef = body.deviceSyncDefinition;
const validatedDeviceSyncDef = rawDeviceSyncDef
? SyncDefinitionSchema.parse(rawDeviceSyncDef)

This comment was marked as resolved.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intentionally matches the existing syncDefinition validation pattern on the line above, which also uses parse. Changing only the device variant to safeParse would be inconsistent — both should be changed together in a separate cleanup.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback! I've saved this as a new learning to improve future reviews.

: undefined;

// Upsert the integration
const integration = await this.dynamicIntegrationRepo.upsertBySlug({
slug: def.slug,
Expand All @@ -83,6 +88,11 @@ export class DynamicIntegrationsController {
JSON.stringify(validatedSyncDef),
) as Prisma.InputJsonValue)
: null,
deviceSyncDefinition: validatedDeviceSyncDef
? (JSON.parse(
JSON.stringify(validatedDeviceSyncDef),
) as Prisma.InputJsonValue)
: null,
services: (def.services as unknown as Prisma.InputJsonValue) ?? undefined,
});

Expand Down Expand Up @@ -167,6 +177,12 @@ export class DynamicIntegrationsController {
const validatedSyncDefCreate = rawSyncDefCreate
? SyncDefinitionSchema.parse(rawSyncDefCreate)
: undefined;

const rawDeviceSyncDefCreate = body.deviceSyncDefinition;
const validatedDeviceSyncDefCreate = rawDeviceSyncDefCreate
? SyncDefinitionSchema.parse(rawDeviceSyncDefCreate)

This comment was marked as resolved.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above — follows the existing syncDefinition pattern which also uses parse. Both should be migrated to safeParse together in a separate PR for consistency.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback! I already have a similar learning that covers this, so I'm keeping the existing one.

: undefined;

const integration = await this.dynamicIntegrationRepo.create({
slug: def.slug,
name: def.name,
Expand All @@ -184,6 +200,11 @@ export class DynamicIntegrationsController {
JSON.stringify(validatedSyncDefCreate),
) as Prisma.InputJsonValue)
: undefined,
deviceSyncDefinition: validatedDeviceSyncDefCreate
? (JSON.parse(
JSON.stringify(validatedDeviceSyncDefCreate),
) as Prisma.InputJsonValue)
: undefined,
});

for (const [index, check] of def.checks.entries()) {
Expand Down
Loading
Loading