Skip to content

Commit

Permalink
refactor(SubscriptionNotification): create separate class for subscri…
Browse files Browse the repository at this point in the history
…ption created
  • Loading branch information
danbillson committed Oct 16, 2024
1 parent 0fb1cbf commit d5f3ad7
Show file tree
Hide file tree
Showing 15 changed files with 134 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/notifications/entities/subscription/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Changes may be overwritten as part of auto-generation.
*/

export * from './subscription-created-notification';
export * from './subscription-discount-notification';
export * from './subscription-time-period-notification';
export * from './subscription-scheduled-change-notification';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
* ! Autogenerated code !
* Do not make changes to this file.
* Changes may be overwritten as part of auto-generation.
*/

import {
BillingDetailsNotification,
ImportMetaNotification,
SubscriptionDiscountNotification,
SubscriptionItemNotification,
SubscriptionScheduledChangeNotification,
SubscriptionTimePeriodNotification,
TimePeriodNotification,
} from '../index';
import { type CollectionMode, type CurrencyCode, type SubscriptionStatus } from '../../../enums';
import { type ISubscriptionCreatedNotificationResponse } from '../../types';
import { type CustomData } from '../../../entities';

export class SubscriptionCreatedNotification {
public readonly id: string;
public readonly status: SubscriptionStatus;
public readonly transactionId: string;
public readonly customerId: string;
public readonly addressId: string;
public readonly businessId: string | null;
public readonly currencyCode: CurrencyCode;
public readonly createdAt: string;
public readonly updatedAt: string;
public readonly startedAt: string | null;
public readonly firstBilledAt: string | null;
public readonly nextBilledAt: string | null;
public readonly pausedAt: string | null;
public readonly canceledAt: string | null;
public readonly discount: SubscriptionDiscountNotification | null;
public readonly collectionMode: CollectionMode;
public readonly billingDetails: BillingDetailsNotification | null;
public readonly currentBillingPeriod: SubscriptionTimePeriodNotification | null;
public readonly billingCycle: TimePeriodNotification;
public readonly scheduledChange: SubscriptionScheduledChangeNotification | null;
public readonly items: SubscriptionItemNotification[];
public readonly customData: CustomData | null;
public readonly importMeta: ImportMetaNotification | null;

constructor(subscription: ISubscriptionCreatedNotificationResponse) {
this.id = subscription.id;
this.status = subscription.status;
this.transactionId = subscription.transaction_id;
this.customerId = subscription.customer_id;
this.addressId = subscription.address_id;
this.businessId = subscription.business_id ? subscription.business_id : null;
this.currencyCode = subscription.currency_code;
this.createdAt = subscription.created_at;
this.updatedAt = subscription.updated_at;
this.startedAt = subscription.started_at ? subscription.started_at : null;
this.firstBilledAt = subscription.first_billed_at ? subscription.first_billed_at : null;
this.nextBilledAt = subscription.next_billed_at ? subscription.next_billed_at : null;
this.pausedAt = subscription.paused_at ? subscription.paused_at : null;
this.canceledAt = subscription.canceled_at ? subscription.canceled_at : null;
this.discount = subscription.discount ? new SubscriptionDiscountNotification(subscription.discount) : null;
this.collectionMode = subscription.collection_mode;
this.billingDetails = subscription.billing_details
? new BillingDetailsNotification(subscription.billing_details)
: null;
this.currentBillingPeriod = subscription.current_billing_period
? new SubscriptionTimePeriodNotification(subscription.current_billing_period)
: null;
this.billingCycle = new TimePeriodNotification(subscription.billing_cycle);
this.scheduledChange = subscription.scheduled_change
? new SubscriptionScheduledChangeNotification(subscription.scheduled_change)
: null;
this.items = subscription.items.map((item) => new SubscriptionItemNotification(item));
this.customData = subscription.custom_data ? subscription.custom_data : null;
this.importMeta = subscription.import_meta ? new ImportMetaNotification(subscription.import_meta) : null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { type CustomData } from '../../../entities';
export class SubscriptionNotification {
public readonly id: string;
public readonly status: SubscriptionStatus;
public readonly transactionId: string;
public readonly customerId: string;
public readonly addressId: string;
public readonly businessId: string | null;
Expand All @@ -45,7 +44,6 @@ export class SubscriptionNotification {
constructor(subscription: ISubscriptionNotificationResponse) {
this.id = subscription.id;
this.status = subscription.status;
this.transactionId = subscription.transaction_id;
this.customerId = subscription.customer_id;
this.addressId = subscription.address_id;
this.businessId = subscription.business_id ? subscription.business_id : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { type ISubscriptionNotificationResponse } from '../../types';

export class SubscriptionActivatedEvent extends Event {
public override readonly eventType = EventName.SubscriptionActivated;
public override readonly data: Omit<SubscriptionNotification, 'transactionId'>;
public override readonly data: SubscriptionNotification;

constructor(response: IEventsResponse<ISubscriptionNotificationResponse>) {
super(response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { type ISubscriptionNotificationResponse } from '../../types';

export class SubscriptionCanceledEvent extends Event {
public override readonly eventType = EventName.SubscriptionCanceled;
public override readonly data: Omit<SubscriptionNotification, 'transactionId'>;
public override readonly data: SubscriptionNotification;

constructor(response: IEventsResponse<ISubscriptionNotificationResponse>) {
super(response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
*/

import { Event } from '../../../entities/events/event';
import { SubscriptionNotification } from '../../entities';
import { SubscriptionCreatedNotification } from '../../entities';
import { EventName } from '../../helpers';
import { type IEventsResponse } from '../../../types';
import { type ISubscriptionNotificationResponse } from '../../types';
import { type ISubscriptionCreatedNotificationResponse } from '../../types';

export class SubscriptionCreatedEvent extends Event {
public override readonly eventType = EventName.SubscriptionCreated;
public override readonly data: SubscriptionNotification;
public override readonly data: SubscriptionCreatedNotification;

constructor(response: IEventsResponse<ISubscriptionNotificationResponse>) {
constructor(response: IEventsResponse<ISubscriptionCreatedNotificationResponse>) {
super(response);
this.data = new SubscriptionNotification(response.data);
this.data = new SubscriptionCreatedNotification(response.data);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { type ISubscriptionNotificationResponse } from '../../types';

export class SubscriptionImportedEvent extends Event {
public override readonly eventType = EventName.SubscriptionImported;
public override readonly data: Omit<SubscriptionNotification, 'transactionId'>;
public override readonly data: SubscriptionNotification;

constructor(response: IEventsResponse<ISubscriptionNotificationResponse>) {
super(response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { type ISubscriptionNotificationResponse } from '../../types';

export class SubscriptionPastDueEvent extends Event {
public override readonly eventType = EventName.SubscriptionPastDue;
public override readonly data: Omit<SubscriptionNotification, 'transactionId'>;
public override readonly data: SubscriptionNotification;

constructor(response: IEventsResponse<ISubscriptionNotificationResponse>) {
super(response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { type ISubscriptionNotificationResponse } from '../../types';

export class SubscriptionPausedEvent extends Event {
public override readonly eventType = EventName.SubscriptionPaused;
public override readonly data: Omit<SubscriptionNotification, 'transactionId'>;
public override readonly data: SubscriptionNotification;

constructor(response: IEventsResponse<ISubscriptionNotificationResponse>) {
super(response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { type ISubscriptionNotificationResponse } from '../../types';

export class SubscriptionResumedEvent extends Event {
public override readonly eventType = EventName.SubscriptionResumed;
public override readonly data: Omit<SubscriptionNotification, 'transactionId'>;
public override readonly data: SubscriptionNotification;

constructor(response: IEventsResponse<ISubscriptionNotificationResponse>) {
super(response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { type ISubscriptionNotificationResponse } from '../../types';

export class SubscriptionTrialingEvent extends Event {
public override readonly eventType = EventName.SubscriptionTrialing;
public override readonly data: Omit<SubscriptionNotification, 'transactionId'>;
public override readonly data: SubscriptionNotification;

constructor(response: IEventsResponse<ISubscriptionNotificationResponse>) {
super(response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { type ISubscriptionNotificationResponse } from '../../types';

export class SubscriptionUpdatedEvent extends Event {
public override readonly eventType = EventName.SubscriptionUpdated;
public override readonly data: Omit<SubscriptionNotification, 'transactionId'>;
public override readonly data: SubscriptionNotification;

constructor(response: IEventsResponse<ISubscriptionNotificationResponse>) {
super(response);
Expand Down
1 change: 1 addition & 0 deletions src/notifications/types/subscription/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Changes may be overwritten as part of auto-generation.
*/

export * from './subscription-created-notification-response';
export * from './subscription-discount-notification-response';
export * from './subscription-time-period-notification-response';
export * from './subscription-scheduled-change-notification-response';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* ! Autogenerated code !
* Do not make changes to this file.
* Changes may be overwritten as part of auto-generation.
*/

import {
type IBillingDetailsNotificationResponse,
type IImportMetaNotificationResponse,
type ISubscriptionDiscountNotificationResponse,
type ISubscriptionItemNotificationResponse,
type ISubscriptionScheduledChangeNotificationResponse,
type ISubscriptionTimePeriodNotificationResponse,
type ITimePeriodNotification,
} from '../index';
import { type CollectionMode, type CurrencyCode, type SubscriptionStatus } from '../../../enums';
import { type ICustomData } from '../../../types';

export interface ISubscriptionCreatedNotificationResponse {
id: string;
status: SubscriptionStatus;
transaction_id: string;
customer_id: string;
address_id: string;
business_id?: string | null;
currency_code: CurrencyCode;
created_at: string;
updated_at: string;
started_at?: string | null;
first_billed_at?: string | null;
next_billed_at?: string | null;
paused_at?: string | null;
canceled_at?: string | null;
discount?: ISubscriptionDiscountNotificationResponse | null;
collection_mode: CollectionMode;
billing_details?: IBillingDetailsNotificationResponse | null;
current_billing_period?: ISubscriptionTimePeriodNotificationResponse | null;
billing_cycle: ITimePeriodNotification;
scheduled_change?: ISubscriptionScheduledChangeNotificationResponse | null;
items: ISubscriptionItemNotificationResponse[];
custom_data?: ICustomData | null;
import_meta?: IImportMetaNotificationResponse | null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { type ICustomData } from '../../../types';
export interface ISubscriptionNotificationResponse {
id: string;
status: SubscriptionStatus;
transaction_id: string;
customer_id: string;
address_id: string;
business_id?: string | null;
Expand Down

0 comments on commit d5f3ad7

Please sign in to comment.