Skip to content

Commit

Permalink
Merge pull request #323 from mollie/pimm/spring-cleaning.
Browse files Browse the repository at this point in the history
Remove withParent.
  • Loading branch information
Pimm authored Jun 20, 2023
2 parents ed321e0 + 327938d commit f8be354
Show file tree
Hide file tree
Showing 14 changed files with 67 additions and 164 deletions.
32 changes: 0 additions & 32 deletions src/binders/InnerBinder.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/binders/chargebacks/ChargebacksBinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import Chargeback, { ChargebackData } from '../../data/chargebacks/Chargeback';
import Page from '../../data/page/Page';
import renege from '../../plumbing/renege';
import Callback from '../../types/Callback';
import InnerBinder from '../InnerBinder';
import Binder from '../Binder';
import { IterateParameters, PageParameters } from './parameters';

const pathSegment = 'chargebacks';

export default class ChargebacksBinder extends InnerBinder<ChargebackData, Chargeback> {
export default class ChargebacksBinder extends Binder<ChargebackData, Chargeback> {
constructor(protected readonly networkClient: TransformingNetworkClient) {
super();
}
Expand Down
25 changes: 8 additions & 17 deletions src/binders/customers/mandates/CustomerMandatesBinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import ApiError from '../../../errors/ApiError';
import checkId from '../../../plumbing/checkId';
import renege from '../../../plumbing/renege';
import Callback from '../../../types/Callback';
import InnerBinder from '../../InnerBinder';
import Binder from '../../Binder';
import { CreateParameters, GetParameters, IterateParameters, PageParameters, RevokeParameters } from './parameters';

function getPathSegments(customerId: string) {
return `customers/${customerId}/mandates`;
}

export default class CustomerMandatesBinder extends InnerBinder<MandateData, Mandate> {
export default class CustomerMandatesBinder extends Binder<MandateData, Mandate> {
constructor(protected readonly networkClient: TransformingNetworkClient) {
super();
}
Expand All @@ -31,11 +31,10 @@ export default class CustomerMandatesBinder extends InnerBinder<MandateData, Man
public create(parameters: CreateParameters, callback: Callback<Mandate>): void;
public create(parameters: CreateParameters) {
if (renege(this, this.create, ...arguments)) return;
const customerId = this.getParentId(parameters.customerId);
const { customerId, ...data } = parameters;
if (!checkId(customerId, 'customer')) {
throw new ApiError('The customer id is invalid');
}
const { customerId: _, ...data } = parameters;
return this.networkClient.post<MandateData, Mandate>(getPathSegments(customerId), data);
}

Expand All @@ -52,12 +51,10 @@ export default class CustomerMandatesBinder extends InnerBinder<MandateData, Man
if (!checkId(id, 'mandate')) {
throw new ApiError('The customers_mandate id is invalid');
}
// parameters ?? {} is used here, because in case withParent is used, parameters could be omitted.
const customerId = this.getParentId((parameters ?? {}).customerId);
const { customerId, ...query } = parameters;
if (!checkId(customerId, 'customer')) {
throw new ApiError('The customer id is invalid');
}
const { customerId: _, ...query } = parameters ?? {};
return this.networkClient.get<MandateData, Mandate>(`${getPathSegments(customerId)}/${id}`, query);
}

Expand All @@ -73,13 +70,11 @@ export default class CustomerMandatesBinder extends InnerBinder<MandateData, Man
public page(parameters: PageParameters, callback: Callback<Page<Mandate>>): void;
public page(parameters: PageParameters) {
if (renege(this, this.page, ...arguments)) return;
// parameters ?? {} is used here, because in case withParent is used, parameters could be omitted.
const customerId = this.getParentId((parameters ?? {}).customerId);
const { customerId, ...query } = parameters;
if (!checkId(customerId, 'customer')) {
throw new ApiError('The customer id is invalid');
}
const { customerId: _, ...query } = parameters ?? {};
return this.networkClient.page<MandateData, Mandate>(getPathSegments(customerId), 'mandates', query).then(result => this.injectPaginationHelpers(result, this.page, parameters ?? {}));
return this.networkClient.page<MandateData, Mandate>(getPathSegments(customerId), 'mandates', query).then(result => this.injectPaginationHelpers(result, this.page, parameters));
}

/**
Expand All @@ -91,12 +86,10 @@ export default class CustomerMandatesBinder extends InnerBinder<MandateData, Man
* @see https://docs.mollie.com/reference/v2/mandates-api/list-mandates
*/
public iterate(parameters: IterateParameters) {
// parameters ?? {} is used here, because in case withParent is used, parameters could be omitted.
const customerId = this.getParentId((parameters ?? {}).customerId);
const { customerId, valuesPerMinute, ...query } = parameters;
if (!checkId(customerId, 'customer')) {
throw new ApiError('The customer id is invalid');
}
const { valuesPerMinute, customerId: _, ...query } = parameters ?? {};
return this.networkClient.iterate<MandateData, Mandate>(getPathSegments(customerId), 'mandates', query, valuesPerMinute);
}

Expand All @@ -113,12 +106,10 @@ export default class CustomerMandatesBinder extends InnerBinder<MandateData, Man
if (!checkId(id, 'mandate')) {
throw new ApiError('The customers_mandate id is invalid');
}
// parameters ?? {} is used here, because in case withParent is used, parameters could be omitted.
const customerId = this.getParentId((parameters ?? {}).customerId);
const { customerId, ...context } = parameters;
if (!checkId(customerId, 'customer')) {
throw new ApiError('The customer is invalid');
}
const { customerId: _, ...context } = parameters ?? {};
return this.networkClient.delete<MandateData, true>(`${getPathSegments(customerId)}/${id}`, context);
}
}
17 changes: 6 additions & 11 deletions src/binders/customers/payments/CustomerPaymentsBinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import ApiError from '../../../errors/ApiError';
import checkId from '../../../plumbing/checkId';
import renege from '../../../plumbing/renege';
import Callback from '../../../types/Callback';
import InnerBinder from '../../InnerBinder';
import Binder from '../../Binder';
import { CreateParameters, IterateParameters, PageParameters } from './parameters';

function getPathSegments(customerId: string) {
return `customers/${customerId}/payments`;
}

export default class CustomerPaymentsBinder extends InnerBinder<PaymentData, Payment> {
export default class CustomerPaymentsBinder extends Binder<PaymentData, Payment> {
constructor(protected readonly networkClient: TransformingNetworkClient) {
super();
}
Expand All @@ -35,11 +35,10 @@ export default class CustomerPaymentsBinder extends InnerBinder<PaymentData, Pay
public create(parameters: CreateParameters, callback: Callback<Payment>): void;
public create(parameters: CreateParameters) {
if (renege(this, this.create, ...arguments)) return;
const customerId = this.getParentId(parameters.customerId);
const { customerId, ...data } = parameters;
if (!checkId(customerId, 'customer')) {
throw new ApiError('The customer id is invalid');
}
const { customerId: _, ...data } = parameters;
return this.networkClient.post<PaymentData, Payment>(getPathSegments(customerId), data);
}

Expand All @@ -53,13 +52,11 @@ export default class CustomerPaymentsBinder extends InnerBinder<PaymentData, Pay
public page(parameters: PageParameters, callback: Callback<Page<Payment>>): void;
public page(parameters: PageParameters) {
if (renege(this, this.page, ...arguments)) return;
// parameters ?? {} is used here, because in case withParent is used, parameters could be omitted.
const customerId = this.getParentId((parameters ?? {}).customerId);
const { customerId, ...query } = parameters;
if (!checkId(customerId, 'customer')) {
throw new ApiError('The customer id is invalid');
}
const { customerId: _, ...query } = parameters ?? {};
return this.networkClient.page<PaymentData, Payment>(getPathSegments(customerId), 'payments', query).then(result => this.injectPaginationHelpers(result, this.page, parameters ?? {}));
return this.networkClient.page<PaymentData, Payment>(getPathSegments(customerId), 'payments', query).then(result => this.injectPaginationHelpers(result, this.page, parameters));
}

/**
Expand All @@ -69,12 +66,10 @@ export default class CustomerPaymentsBinder extends InnerBinder<PaymentData, Pay
* @see https://docs.mollie.com/reference/v2/customers-api/list-customer-payments
*/
public iterate(parameters: IterateParameters) {
// parameters ?? {} is used here, because in case withParent is used, parameters could be omitted.
const customerId = this.getParentId((parameters ?? {}).customerId);
const { customerId, valuesPerMinute, ...query } = parameters;
if (!checkId(customerId, 'customer')) {
throw new ApiError('The customer id is invalid');
}
const { valuesPerMinute, customerId: _, ...query } = parameters ?? {};
return this.networkClient.iterate<PaymentData, Payment>(getPathSegments(customerId), 'payments', query, valuesPerMinute);
}
}
30 changes: 9 additions & 21 deletions src/binders/customers/subscriptions/CustomerSubscriptionsBinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import ApiError from '../../../errors/ApiError';
import checkId from '../../../plumbing/checkId';
import renege from '../../../plumbing/renege';
import Callback from '../../../types/Callback';
import InnerBinder from '../../InnerBinder';
import Binder from '../../Binder';
import { CancelParameters, CreateParameters, GetParameters, IterateParameters, PageParameters, UpdateParameters } from './parameters';

function getPathSegments(customerId: string) {
return `customers/${customerId}/subscriptions`;
}

export default class CustomerSubscriptionsBinder extends InnerBinder<SubscriptionData, Subscription> {
export default class CustomerSubscriptionsBinder extends Binder<SubscriptionData, Subscription> {
constructor(protected readonly networkClient: TransformingNetworkClient) {
super();
}
Expand All @@ -38,11 +38,10 @@ export default class CustomerSubscriptionsBinder extends InnerBinder<Subscriptio
public create(parameters: CreateParameters, callback: Callback<Subscription>): void;
public create(parameters: CreateParameters) {
if (renege(this, this.create, ...arguments)) return;
const customerId = this.getParentId(parameters.customerId);
const { customerId, ...data } = parameters;
if (!checkId(customerId, 'customer')) {
throw new ApiError('The customer id is invalid');
}
const { customerId: _, ...data } = parameters;
return this.networkClient.post<SubscriptionData, Subscription>(getPathSegments(customerId), data);
}

Expand All @@ -59,12 +58,10 @@ export default class CustomerSubscriptionsBinder extends InnerBinder<Subscriptio
if (!checkId(id, 'subscription')) {
throw new ApiError('The subscription id is invalid');
}
// parameters ?? {} is used here, because in case withParent is used, parameters could be omitted.
const customerId = this.getParentId((parameters ?? {}).customerId);
const { customerId, ...query } = parameters;
if (!checkId(customerId, 'customer')) {
throw new ApiError('The customer id is invalid');
}
const { customerId: _, ...query } = parameters ?? {};
return this.networkClient.get<SubscriptionData, Subscription>(`${getPathSegments(customerId)}/${id}`, query);
}

Expand All @@ -78,15 +75,11 @@ export default class CustomerSubscriptionsBinder extends InnerBinder<Subscriptio
public page(parameters: PageParameters, callback: Callback<Page<Subscription>>): void;
public page(parameters: PageParameters) {
if (renege(this, this.page, ...arguments)) return;
// parameters ?? {} is used here, because in case withParent is used, parameters could be omitted.
const customerId = this.getParentId((parameters ?? {}).customerId);
const { customerId, ...query } = parameters;
if (!checkId(customerId, 'customer')) {
throw new ApiError('The customer id is invalid');
}
const { customerId: _, ...query } = parameters ?? {};
return this.networkClient
.page<SubscriptionData, Subscription>(getPathSegments(customerId), 'subscriptions', query)
.then(result => this.injectPaginationHelpers(result, this.page, parameters ?? {}));
return this.networkClient.page<SubscriptionData, Subscription>(getPathSegments(customerId), 'subscriptions', query).then(result => this.injectPaginationHelpers(result, this.page, parameters));
}

/**
Expand All @@ -96,12 +89,10 @@ export default class CustomerSubscriptionsBinder extends InnerBinder<Subscriptio
* @see https://docs.mollie.com/reference/v2/subscriptions-api/list-subscriptions
*/
public iterate(parameters: IterateParameters) {
// parameters ?? {} is used here, because in case withParent is used, parameters could be omitted.
const customerId = this.getParentId((parameters ?? {}).customerId);
const { customerId, valuesPerMinute, ...query } = parameters;
if (!checkId(customerId, 'customer')) {
throw new ApiError('The customer id is invalid');
}
const { valuesPerMinute, customerId: _, ...query } = parameters ?? {};
return this.networkClient.iterate<SubscriptionData, Subscription>(getPathSegments(customerId), 'subscriptions', query, valuesPerMinute);
}

Expand All @@ -120,11 +111,10 @@ export default class CustomerSubscriptionsBinder extends InnerBinder<Subscriptio
if (!checkId(id, 'subscription')) {
throw new ApiError('The subscription id is invalid');
}
const customerId = this.getParentId(parameters.customerId);
const { customerId, ...data } = parameters;
if (!checkId(customerId, 'customer')) {
throw new ApiError('The customer is invalid');
}
const { customerId: _, ...data } = parameters;
return this.networkClient.patch<SubscriptionData, Subscription>(`${getPathSegments(customerId)}/${id}`, data);
}

Expand All @@ -141,12 +131,10 @@ export default class CustomerSubscriptionsBinder extends InnerBinder<Subscriptio
if (!checkId(id, 'subscription')) {
throw new ApiError('The subscription id is invalid');
}
// parameters ?? {} is used here, because in case withParent is used, parameters could be omitted.
const customerId = this.getParentId((parameters ?? {}).customerId);
const { customerId, ...context } = parameters;
if (!checkId(customerId, 'customer')) {
throw new ApiError('The customer is invalid');
}
const { customerId: _, ...context } = parameters ?? {};
return this.networkClient.delete<SubscriptionData, Subscription>(`${getPathSegments(customerId)}/${id}`, context);
}
}
10 changes: 4 additions & 6 deletions src/binders/orders/orderlines/OrderLinesBinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import ApiError from '../../../errors/ApiError';
import checkId from '../../../plumbing/checkId';
import renege from '../../../plumbing/renege';
import Callback from '../../../types/Callback';
import InnerBinder from '../../InnerBinder';
import Binder from '../../Binder';
import { CancelParameters, UpdateParameters } from './parameters';

function getPathSegments(orderId: string) {
return `orders/${orderId}/lines`;
}

export default class OrderLinesBinder extends InnerBinder<OrderData, Order> {
export default class OrderLinesBinder extends Binder<OrderData, Order> {
constructor(protected readonly networkClient: TransformingNetworkClient) {
super();
}
Expand Down Expand Up @@ -40,11 +40,10 @@ export default class OrderLinesBinder extends InnerBinder<OrderData, Order> {
if (!checkId(id, 'orderline')) {
throw new ApiError('The orders_lines id is invalid');
}
const orderId = this.getParentId(parameters.orderId);
const { orderId, ...data } = parameters;
if (!checkId(orderId, 'order')) {
throw new ApiError('The order id is invalid');
}
const { orderId: _, ...data } = parameters;
return this.networkClient.patch<OrderData, Order>(`${getPathSegments(orderId)}/${id}`, data);
}

Expand All @@ -71,11 +70,10 @@ export default class OrderLinesBinder extends InnerBinder<OrderData, Order> {
public cancel(parameters: CancelParameters, callback: Callback<true>): void;
public cancel(parameters: CancelParameters) {
if (renege(this, this.cancel, ...arguments)) return;
const orderId = this.getParentId(parameters.orderId);
const { orderId, ...data } = parameters;
if (!checkId(orderId, 'order')) {
throw new ApiError('The order id is invalid');
}
const { orderId: _, ...data } = parameters;
return this.networkClient.delete<OrderData, true>(getPathSegments(orderId), data);
}
}
Loading

0 comments on commit f8be354

Please sign in to comment.