Add external order id query for paypal and klarna ids (#80)
This commit is contained in:
@@ -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"')
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user