83 lines
1.7 KiB
TypeScript
83 lines
1.7 KiB
TypeScript
import { SQLDataSource } from 'datasource-sql';
|
|
|
|
const MINUTE = 60;
|
|
|
|
interface Order {
|
|
id: number;
|
|
inserted: Date;
|
|
paid: boolean;
|
|
confirmed: boolean;
|
|
delivered: boolean;
|
|
newsletter: boolean;
|
|
creditInvoice: boolean;
|
|
canceled: boolean;
|
|
reminder: boolean;
|
|
deliveredDate: Date;
|
|
countryCode: string;
|
|
language: string;
|
|
deliveryCountryCode: string;
|
|
deliveryMethod: string;
|
|
deliveryPrice: string;
|
|
deliveryVat: number;
|
|
customerType: string;
|
|
paymentType: string;
|
|
attention: string;
|
|
currency: string;
|
|
exchangeRate: number;
|
|
exchangeRateEur: number;
|
|
invoiceId: string;
|
|
contractCustomerId: number | null;
|
|
vatNumber: string;
|
|
comment: string;
|
|
cancelsOrderId: number;
|
|
cancelledByOrderId: number;
|
|
orderlogId: number;
|
|
resellerStore: string;
|
|
orderSum: number;
|
|
klarnaOrderId: string;
|
|
pwintyId: number;
|
|
email: string;
|
|
phone: string;
|
|
deliveryEmail: string;
|
|
deliveryPhone: string;
|
|
customerFirstname: string;
|
|
customerLastname: string;
|
|
customerEmail: string;
|
|
customerCellphone: string;
|
|
billingAddressId: number;
|
|
deliveryAddressId: number;
|
|
flyer_ids: string;
|
|
market: string;
|
|
locale: string;
|
|
}
|
|
|
|
export class OrderAPI extends SQLDataSource {
|
|
constructor(config) {
|
|
super(config);
|
|
}
|
|
|
|
async getOrders() {
|
|
const data = await this.knex
|
|
.select('*')
|
|
.from('orders')
|
|
.where('inserted', '>=', '2021-03-01T00:00:00Z')
|
|
.cache(MINUTE);
|
|
|
|
console.log(data);
|
|
|
|
return [
|
|
{ id: 1, countryCode: 'SE' },
|
|
{ id: 2, countryCode: 'DK' },
|
|
];
|
|
}
|
|
|
|
async getOrder(id: number): Promise<Order> {
|
|
return await this.knex
|
|
.select('*')
|
|
.from('orders')
|
|
.where('id', id)
|
|
.first()
|
|
.cache(MINUTE);
|
|
}
|
|
}
|