Add external order id query for paypal and klarna ids (#80)

This commit is contained in:
Niklas Fondberg
2021-10-28 11:05:38 +02:00
committed by GitHub
parent 7fe6414723
commit ee16ff44c6
3 changed files with 32 additions and 0 deletions
+18
View File
@@ -102,6 +102,24 @@ export class OrderAPI extends BaseSQLDataSource {
.then((row) => this.createOrderFromRow(row));
}
async getOrderByExternalId(
klarnaOrderId: string,
paypalTransactionId: string,
): Promise<Order> {
const column = paypalTransactionId
? 'paypal_transaction_id'
: 'klarna_order_id';
const value = paypalTransactionId ?? klarnaOrderId;
return this.knex
.select('*')
.from('orders')
.where(column, value)
.first()
.cache(MINUTE)
.then((row) => this.createOrderFromRow(row));
}
async getOrderRowFieldMapping(): Promise<any> {
// const fields = await this.knex.select('*').from('order-row_fields'); doesn't work becuase of string case...
const fieldsRes = await this.cachedRaw('SELECT * from "order-row_fields"')
+13
View File
@@ -57,6 +57,18 @@ async function getOrder(_, { id }, { dataSources, auth }) {
return (<OrderAPI>dataSources.orderApi).getOrderById(id);
}
async function orderByExternalId(
_,
{ klarnaOrderId, paypalTransactionId },
{ dataSources, auth },
) {
checkAccess(['orders.read'], auth);
return (<OrderAPI>dataSources.orderApi).getOrderByExternalId(
klarnaOrderId,
paypalTransactionId,
);
}
export const orderTypeDefs = {
ContactInformation,
Order,
@@ -66,4 +78,5 @@ export const orderTypeDefs = {
export const orderQueryTypeDefs = {
orders: getOrdersResult,
order: getOrder,
orderByExternalId: orderByExternalId,
};
+1
View File
@@ -19,6 +19,7 @@ directive @cacheControl(
type Query {
orders(pagination: PaginationInput!, filter: DateFilterInput!): OrdersResult
order(id: ID!): Order
orderByExternalId(klarnaOrderId: ID, paypalTransactionId: ID): Order
products(
pagination: PaginationInput!
filter: ProductsFilterInput