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));
|
.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> {
|
async getOrderRowFieldMapping(): Promise<any> {
|
||||||
// const fields = await this.knex.select('*').from('order-row_fields'); doesn't work becuase of string case...
|
// 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"')
|
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);
|
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 = {
|
export const orderTypeDefs = {
|
||||||
ContactInformation,
|
ContactInformation,
|
||||||
Order,
|
Order,
|
||||||
@@ -66,4 +78,5 @@ export const orderTypeDefs = {
|
|||||||
export const orderQueryTypeDefs = {
|
export const orderQueryTypeDefs = {
|
||||||
orders: getOrdersResult,
|
orders: getOrdersResult,
|
||||||
order: getOrder,
|
order: getOrder,
|
||||||
|
orderByExternalId: orderByExternalId,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ directive @cacheControl(
|
|||||||
type Query {
|
type Query {
|
||||||
orders(pagination: PaginationInput!, filter: DateFilterInput!): OrdersResult
|
orders(pagination: PaginationInput!, filter: DateFilterInput!): OrdersResult
|
||||||
order(id: ID!): Order
|
order(id: ID!): Order
|
||||||
|
orderByExternalId(klarnaOrderId: ID, paypalTransactionId: ID): Order
|
||||||
products(
|
products(
|
||||||
pagination: PaginationInput!
|
pagination: PaginationInput!
|
||||||
filter: ProductsFilterInput
|
filter: ProductsFilterInput
|
||||||
|
|||||||
Reference in New Issue
Block a user