export const GadgetApiOrderRepository = (
gadgetApi: Client
): IOrderRepository => ({
byId: (shopId, orderId) =>
Effect.tryPromise({
try: async () => {
const record = await gadgetApi.shopifyOrder.maybeFindFirst({
filter: {
AND: [
{
shopId: { equals: shopId },
},
{
id: { equals: orderId },
},
],
},
select: {
id: true,
currency: true,
totalPrice: true,
// ...
},
});
if (!record) {
throw new OrderNotFoundError({ shopId, orderId });
}
const order = createOrder({
id: record.id,
currency: decodeUnknownISO4217CurrencyCode(record.currency),
totalPrice: decodeUnknownNonNegativeMonetaryAmount(record.totalPrice),
// ...
});
return order;
},
catch: (unknown) =>
new RepositoryConnectionError({
unknown,
metadata: { shopId, orderId },
}),
}),
});
export const GadgetApiOrderRepository = (
gadgetApi: Client
): IOrderRepository => ({
byId: (shopId, orderId) =>
Effect.tryPromise({
try: async () => {
const record = await gadgetApi.shopifyOrder.maybeFindFirst({
filter: {
AND: [
{
shopId: { equals: shopId },
},
{
id: { equals: orderId },
},
],
},
select: {
id: true,
currency: true,
totalPrice: true,
// ...
},
});
if (!record) {
throw new OrderNotFoundError({ shopId, orderId });
}
const order = createOrder({
id: record.id,
currency: decodeUnknownISO4217CurrencyCode(record.currency),
totalPrice: decodeUnknownNonNegativeMonetaryAmount(record.totalPrice),
// ...
});
return order;
},
catch: (unknown) =>
new RepositoryConnectionError({
unknown,
metadata: { shopId, orderId },
}),
}),
});