From b984f08d223dc39ee6625a5499fc97f54ed65c40 Mon Sep 17 00:00:00 2001 From: Darragh ORiordan Date: Sun, 24 Dec 2023 11:25:21 +1100 Subject: [PATCH] fix: fix lint issues --- src/invitations/invitation.service.ts | 21 ++++++------ .../organisation-memberships.service.ts | 2 ++ .../services/queued-payment-event.handler.ts | 33 +++++++------------ 3 files changed, 25 insertions(+), 31 deletions(-) diff --git a/src/invitations/invitation.service.ts b/src/invitations/invitation.service.ts index 0be67cd1..2a2fe13c 100644 --- a/src/invitations/invitation.service.ts +++ b/src/invitations/invitation.service.ts @@ -91,10 +91,12 @@ export class InvitationService { }); if ( - existingMemberships.some((m) => - m.roles?.some( - (r) => r.name === Roles.member || r.name === Roles.owner - ) + existingMemberships.some( + (m) => + m.roles?.some( + // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison + (r) => r.name === Roles.member || r.name === Roles.owner + ) ) ) { const message = @@ -146,9 +148,8 @@ export class InvitationService { membership.invitations?.push(unsavedInvitation); membership.roles = [role]; - const savedMembership = await this.orgMembershipRepository.save( - membership - ); + const savedMembership = + await this.orgMembershipRepository.save(membership); const retrievedMembership = await this.orgMembershipRepository.findOne({ where: {id: savedMembership.id}, relations: { @@ -200,9 +201,8 @@ export class InvitationService { // if it gets to here we have a queued invitation validInvitation.notificationSent = new Date(); - const savedInvitation = await this.invitationRepository.save( - validInvitation - ); + const savedInvitation = + await this.invitationRepository.save(validInvitation); // we need to return the membership with the invitation // torm doesn't like if we just assign and return so get it again const fullInvitation = await this.invitationRepository.findOne({ @@ -253,6 +253,7 @@ export class InvitationService { }, }); if ( + // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison requesterMembership.roles?.some((role) => role.name === Roles.owner) ) { return; diff --git a/src/organisation-memberships/organisation-memberships.service.ts b/src/organisation-memberships/organisation-memberships.service.ts index 46f3986a..57229f75 100644 --- a/src/organisation-memberships/organisation-memberships.service.ts +++ b/src/organisation-memberships/organisation-memberships.service.ts @@ -75,6 +75,7 @@ export class OrganisationMembershipsService { // add all roles to the existing membership for (const role of createOmDto.roles) { const existingRole = existingMembership.roles?.find( + // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison (r) => r.name === role ); if (!existingRole) { @@ -106,6 +107,7 @@ export class OrganisationMembershipsService { const membership = org.memberships?.find( (m) => m.user.id === currentUserId && + // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison m.roles?.some((r) => r.name === Roles.owner) ); if (!membership) { diff --git a/src/stripe-client/services/queued-payment-event.handler.ts b/src/stripe-client/services/queued-payment-event.handler.ts index be83ec38..238a6107 100644 --- a/src/stripe-client/services/queued-payment-event.handler.ts +++ b/src/stripe-client/services/queued-payment-event.handler.ts @@ -74,8 +74,7 @@ export class StripeQueuedEventHandler { // Payment is successful and for example the subscription can be created. // If you support asynchronous payment methods, handle those events in the // checkout.session.async_payment_succeeded webhook. - const stripeDataProperty = job.data.data - .object as Stripe.Checkout.Session; + const stripeDataProperty = job.data.data.object; if (stripeDataProperty.payment_status === "paid") { // fulfil it const fullSession = @@ -104,8 +103,7 @@ export class StripeQueuedEventHandler { case "checkout.session.async_payment_succeeded": { // Payment link payment is successful for async payment methods. (bank drafts, etc.) // probably not relevant for most people. But if you want to support it, here's how. - const stripeDataProperty = job.data.data - .object as Stripe.Checkout.Session; + const stripeDataProperty = job.data.data.object; const fullSession = await this.stripe.checkout.sessions.retrieve( stripeDataProperty.id, @@ -122,17 +120,15 @@ export class StripeQueuedEventHandler { fullSession ); - const result = await this.organisationSubscriptionService.save( - subs - ); + const result = + await this.organisationSubscriptionService.save(subs); this.logger.log("Async payment succeeded", {result}); return; } case "checkout.session.async_payment_failed": { // Payment link payment is NOT successful for async payment methods. (bank drafts, etc.) // You can use this webhook to notify the user that their payment was not successful. - const stripeDataProperty = job.data.data - .object as Stripe.Checkout.Session; + const stripeDataProperty = job.data.data.object; this.logger.error( `Async payment failed for session ${stripeDataProperty.id}` ); @@ -168,8 +164,7 @@ export class StripeQueuedEventHandler { // The subscription becomes past_due. Notify your customer and send them to the // customer portal to update their payment information. - const stripeDataProperty = job.data.data - .object as Stripe.Invoice; + const stripeDataProperty = job.data.data.object; this.logger.error("Invoice payment failed", { stripeDataProperty, }); @@ -189,8 +184,7 @@ export class StripeQueuedEventHandler { case "customer.subscription.deleted": { // Sent when a customer’s subscription ends. - const stripeDataProperty = job.data.data - .object as Stripe.Subscription; + const stripeDataProperty = job.data.data.object; const fullSession = await this.stripe.subscriptions.retrieve( stripeDataProperty.id, { @@ -207,9 +201,8 @@ export class StripeQueuedEventHandler { sub.validUntil = new Date(); } - const result = await this.organisationSubscriptionService.save( - subs - ); + const result = + await this.organisationSubscriptionService.save(subs); this.logger.log( "Subscription deleted - validity set to today", {result} @@ -224,8 +217,7 @@ export class StripeQueuedEventHandler { * For example, adding a coupon, applying a discount, * adding an invoice item, and changing plans all trigger this event. */ - const stripeDataProperty = job.data.data - .object as Stripe.Subscription; + const stripeDataProperty = job.data.data.object; const fullSubscription = await this.stripe.subscriptions.retrieve( stripeDataProperty.id, @@ -242,9 +234,8 @@ export class StripeQueuedEventHandler { } ); - const result = await this.organisationSubscriptionService.save( - subs - ); + const result = + await this.organisationSubscriptionService.save(subs); this.logger.log("Subscription updated", {result}); return;