Skip to content

Commit

Permalink
feat(admin-ui): Add support for payment method relation custom field.…
Browse files Browse the repository at this point in the history
… add payment method service
  • Loading branch information
Stefanyshyn committed Nov 19, 2023
1 parent b40aa88 commit 101704b
Show file tree
Hide file tree
Showing 36 changed files with 414 additions and 250 deletions.
121 changes: 59 additions & 62 deletions packages/admin-ui/src/lib/core/src/common/generated-types.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import { gql } from 'apollo-angular';

import { CONFIGURABLE_OPERATION_DEF_FRAGMENT, CONFIGURABLE_OPERATION_FRAGMENT } from './shared-definitions';

export const PAYMENT_METHOD_FRAGMENT = gql`
fragment PaymentMethod on PaymentMethod {
id
createdAt
updatedAt
name
code
description
enabled
translations {
id
languageCode
name
description
}
checker {
...ConfigurableOperation
}
handler {
...ConfigurableOperation
}
}
${CONFIGURABLE_OPERATION_FRAGMENT}
`;

export const GET_PAYMENT_METHOD_OPERATIONS = gql`
query GetPaymentMethodOperations {
paymentMethodEligibilityCheckers {
...ConfigurableOperationDef
}
paymentMethodHandlers {
...ConfigurableOperationDef
}
}
${CONFIGURABLE_OPERATION_DEF_FRAGMENT}
`;

export const GET_PAYMENT_METHOD_LIST = gql`
query GetPaymentMethodList($options: PaymentMethodListOptions!) {
paymentMethods(options: $options) {
items {
...PaymentMethod
}
totalItems
}
}
${PAYMENT_METHOD_FRAGMENT}
`;

export const GET_PAYMENT_METHOD = gql`
query GetPaymentMethod($id: ID!) {
paymentMethod(id: $id) {
...PaymentMethod
}
}
${PAYMENT_METHOD_FRAGMENT}
`;

export const CREATE_PAYMENT_METHOD = gql`
mutation CreatePaymentMethod($input: CreatePaymentMethodInput!) {
createPaymentMethod(input: $input) {
...PaymentMethod
}
}
${PAYMENT_METHOD_FRAGMENT}
`;

export const UPDATE_PAYMENT_METHOD = gql`
mutation UpdatePaymentMethod($input: UpdatePaymentMethodInput!) {
updatePaymentMethod(input: $input) {
...PaymentMethod
}
}
${PAYMENT_METHOD_FRAGMENT}
`;

export const DELETE_PAYMENT_METHOD = gql`
mutation DeletePaymentMethod($id: ID!, $force: Boolean) {
deletePaymentMethod(id: $id, force: $force) {
result
message
}
}
`;

export const DELETE_PAYMENT_METHODS = gql`
mutation DeletePaymentMethods($ids: [ID!]!, $force: Boolean) {
deletePaymentMethods(ids: $ids, force: $force) {
result
message
}
}
`;
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { gql } from 'apollo-angular';

import {
CONFIGURABLE_OPERATION_DEF_FRAGMENT,
CONFIGURABLE_OPERATION_FRAGMENT,
ERROR_RESULT_FRAGMENT,
} from './shared-definitions';
import { ERROR_RESULT_FRAGMENT } from './shared-definitions';

export const COUNTRY_FRAGMENT = gql`
fragment Country on Country {
Expand Down Expand Up @@ -433,79 +429,6 @@ export const DELETE_CHANNELS = gql`
}
`;

export const PAYMENT_METHOD_FRAGMENT = gql`
fragment PaymentMethod on PaymentMethod {
id
createdAt
updatedAt
name
code
description
enabled
translations {
id
languageCode
name
description
}
checker {
...ConfigurableOperation
}
handler {
...ConfigurableOperation
}
}
${CONFIGURABLE_OPERATION_FRAGMENT}
`;

export const GET_PAYMENT_METHOD_OPERATIONS = gql`
query GetPaymentMethodOperations {
paymentMethodEligibilityCheckers {
...ConfigurableOperationDef
}
paymentMethodHandlers {
...ConfigurableOperationDef
}
}
${CONFIGURABLE_OPERATION_DEF_FRAGMENT}
`;

export const CREATE_PAYMENT_METHOD = gql`
mutation CreatePaymentMethod($input: CreatePaymentMethodInput!) {
createPaymentMethod(input: $input) {
...PaymentMethod
}
}
${PAYMENT_METHOD_FRAGMENT}
`;

export const UPDATE_PAYMENT_METHOD = gql`
mutation UpdatePaymentMethod($input: UpdatePaymentMethodInput!) {
updatePaymentMethod(input: $input) {
...PaymentMethod
}
}
${PAYMENT_METHOD_FRAGMENT}
`;

export const DELETE_PAYMENT_METHOD = gql`
mutation DeletePaymentMethod($id: ID!, $force: Boolean) {
deletePaymentMethod(id: $id, force: $force) {
result
message
}
}
`;

export const DELETE_PAYMENT_METHODS = gql`
mutation DeletePaymentMethods($ids: [ID!]!, $force: Boolean) {
deletePaymentMethods(ids: $ids, force: $force) {
result
message
}
}
`;

export const GLOBAL_SETTINGS_FRAGMENT = gql`
fragment GlobalSettings on GlobalSettings {
id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { ProductDataService } from './product-data.service';
import { PromotionDataService } from './promotion-data.service';
import { SettingsDataService } from './settings-data.service';
import { ShippingMethodDataService } from './shipping-method-data.service';
import { PaymentMethodDataService } from './payment-method-data.service';

/**
* @description
Expand All @@ -43,6 +44,7 @@ export class DataService {
/** @internal */ settings: SettingsDataService;
/** @internal */ customer: CustomerDataService;
/** @internal */ shippingMethod: ShippingMethodDataService;
/** @internal */ paymentMethod: PaymentMethodDataService;

/** @internal */
constructor(private baseDataService: BaseDataService) {
Expand All @@ -57,6 +59,7 @@ export class DataService {
this.settings = new SettingsDataService(baseDataService);
this.customer = new CustomerDataService(baseDataService);
this.shippingMethod = new ShippingMethodDataService(baseDataService);
this.paymentMethod = new PaymentMethodDataService(baseDataService);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ export class FetchAdapter {
responseType: 'json',
withCredentials: true,
}),
).then(result => new Response(JSON.stringify(result.body), {
status: result.status,
statusText: result.statusText,
}));
).then(
result =>
new Response(JSON.stringify(result.body), {
status: result.status,
statusText: result.statusText,
}),
);
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { pick } from '@vendure/common/lib/pick';
import * as Codegen from '../../common/generated-types';
import {
GET_PAYMENT_METHOD,
GET_PAYMENT_METHOD_LIST,
CREATE_PAYMENT_METHOD,
DELETE_PAYMENT_METHOD,
DELETE_PAYMENT_METHODS,
GET_PAYMENT_METHOD_OPERATIONS,
UPDATE_PAYMENT_METHOD,
} from '../definitions/payment-method-definitions';
import { BaseDataService } from './base-data.service';

export class PaymentMethodDataService {
constructor(private baseDataService: BaseDataService) {}

getPaymentMethods(options: Codegen.PaymentMethodListOptions) {
return this.baseDataService.query<
Codegen.GetPaymentMethodListQuery,
Codegen.GetPaymentMethodListQueryVariables
>(GET_PAYMENT_METHOD_LIST, {
options,
});
}

getPaymentMethod(id: string) {
return this.baseDataService.query<
Codegen.GetPaymentMethodQuery,
Codegen.GetPaymentMethodQueryVariables
>(GET_PAYMENT_METHOD, { id });
}

createPaymentMethod(input: Codegen.CreatePaymentMethodInput) {
return this.baseDataService.mutate<
Codegen.CreatePaymentMethodMutation,
Codegen.CreatePaymentMethodMutationVariables
>(CREATE_PAYMENT_METHOD, {
input: pick(input, ['code', 'checker', 'handler', 'enabled', 'translations', 'customFields']),
});
}

updatePaymentMethod(input: Codegen.UpdatePaymentMethodInput) {
return this.baseDataService.mutate<
Codegen.UpdatePaymentMethodMutation,
Codegen.UpdatePaymentMethodMutationVariables
>(UPDATE_PAYMENT_METHOD, {
input: pick(input, [
'id',
'code',
'checker',
'handler',
'enabled',
'translations',
'customFields',
]),
});
}

deletePaymentMethod(id: string, force: boolean) {
return this.baseDataService.mutate<
Codegen.DeletePaymentMethodMutation,
Codegen.DeletePaymentMethodMutationVariables
>(DELETE_PAYMENT_METHOD, {
id,
force,
});
}

deletePaymentMethods(ids: string[], force: boolean) {
return this.baseDataService.mutate<
Codegen.DeletePaymentMethodsMutation,
Codegen.DeletePaymentMethodsMutationVariables
>(DELETE_PAYMENT_METHODS, {
ids,
force,
});
}

getPaymentMethodOperations() {
return this.baseDataService.query<Codegen.GetPaymentMethodOperationsQuery>(
GET_PAYMENT_METHOD_OPERATIONS,
);
}
}

0 comments on commit 101704b

Please sign in to comment.