diff --git a/packages/api/routes/collection/subscriptions/index.ts b/packages/api/routes/collection/subscriptions/index.ts index 6b958b2c8..393e6840f 100644 --- a/packages/api/routes/collection/subscriptions/index.ts +++ b/packages/api/routes/collection/subscriptions/index.ts @@ -28,22 +28,24 @@ export async function upsertSubscription( ) { return null; } + + const dates = { + startDate: new Date(subscription.startDate), + endDate: new Date(subscription.endDate), + }; + await prismaDm.subscription.upsert({ - update: { - startDate: subscription.startDate!, - endDate: subscription.endDate!, - }, + update: dates, create: { country: publicationCodeParts[0], magazine: publicationCodeParts[1], users: { connect: { id: userId }, }, - startDate: subscription.startDate!, - endDate: subscription.endDate!, + ...dates }, where: { - id, + id: id || 0, }, }); } diff --git a/packages/types/EditSubscription.ts b/packages/types/EditSubscription.ts index dfcc505b7..0f818f094 100644 --- a/packages/types/EditSubscription.ts +++ b/packages/types/EditSubscription.ts @@ -1,6 +1,6 @@ export type EditSubscription = { id: number | null; - publicationcode: string | null; - startDate: string | null; - endDate: string | null; + publicationcode: string; + startDate: string; + endDate: string; };