Added orderrows
This commit is contained in:
@@ -20,6 +20,7 @@
|
|||||||
"pg": "^8.5.1",
|
"pg": "^8.5.1",
|
||||||
"pg-hstore": "^2.3.3",
|
"pg-hstore": "^2.3.3",
|
||||||
"prettier": "^2.2.1",
|
"prettier": "^2.2.1",
|
||||||
|
"stringcase": "^4.3.1",
|
||||||
"ts-node": "^9.1.1",
|
"ts-node": "^9.1.1",
|
||||||
"typescript": "^4.2.3",
|
"typescript": "^4.2.3",
|
||||||
"validator": "^13.5.2"
|
"validator": "^13.5.2"
|
||||||
|
|||||||
@@ -18,3 +18,69 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
order(id: 588274) {
|
||||||
|
id
|
||||||
|
rows {
|
||||||
|
id
|
||||||
|
}
|
||||||
|
billingInformation {
|
||||||
|
email
|
||||||
|
phone
|
||||||
|
address {
|
||||||
|
id
|
||||||
|
firstname
|
||||||
|
lastname
|
||||||
|
recipientName
|
||||||
|
companyname
|
||||||
|
address1
|
||||||
|
address2
|
||||||
|
countryCode
|
||||||
|
city
|
||||||
|
zipcode
|
||||||
|
stateCountyOrRegion
|
||||||
|
}
|
||||||
|
}
|
||||||
|
deliveryInformation {
|
||||||
|
email
|
||||||
|
phone
|
||||||
|
address {
|
||||||
|
id
|
||||||
|
firstname
|
||||||
|
lastname
|
||||||
|
recipientName
|
||||||
|
companyname
|
||||||
|
address1
|
||||||
|
address2
|
||||||
|
countryCode
|
||||||
|
city
|
||||||
|
zipcode
|
||||||
|
stateCountyOrRegion
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
order(id: 588274) {
|
||||||
|
id
|
||||||
|
rows {
|
||||||
|
id
|
||||||
|
insertedDate
|
||||||
|
orderId
|
||||||
|
productId
|
||||||
|
productGroup
|
||||||
|
artNo
|
||||||
|
path
|
||||||
|
name
|
||||||
|
price
|
||||||
|
designerId
|
||||||
|
commissionAmount
|
||||||
|
status
|
||||||
|
pwintyImageId
|
||||||
|
frameColor
|
||||||
|
pwintySku
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
export const dbConfig = {
|
export const dbConfig = {
|
||||||
client: 'pg',
|
client: 'pg',
|
||||||
connection: 'postgresql://fondberg:@docker.for.mac.localhost/photowall',
|
connection: process.env.DATABASE_URL,
|
||||||
pool: {
|
pool: {
|
||||||
min: 1,
|
min: 1,
|
||||||
max: 10,
|
max: 10,
|
||||||
|
|||||||
+101
-86
@@ -1,70 +1,9 @@
|
|||||||
import { SQLDataSource } from 'datasource-sql';
|
import { SQLDataSource } from 'datasource-sql';
|
||||||
|
import { camelcase } from 'stringcase';
|
||||||
|
import { Address, ContactInformation, Order, OrderRow } from './order-types';
|
||||||
import { Maybe } from './types';
|
import { Maybe } from './types';
|
||||||
|
|
||||||
const MINUTE = 60;
|
const MINUTE = 60;
|
||||||
|
|
||||||
interface Address {
|
|
||||||
id: number;
|
|
||||||
firstname: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface ContactInformation {
|
|
||||||
email: string;
|
|
||||||
phone: string;
|
|
||||||
addressId: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
flyerIds: string;
|
|
||||||
market: string;
|
|
||||||
locale: string;
|
|
||||||
billingInformation: ContactInformation;
|
|
||||||
deliveryInformation: ContactInformation;
|
|
||||||
billingAddressId: number;
|
|
||||||
deliveryAddressId: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class OrderAPI extends SQLDataSource {
|
export class OrderAPI extends SQLDataSource {
|
||||||
constructor(config) {
|
constructor(config) {
|
||||||
super(config);
|
super(config);
|
||||||
@@ -77,32 +16,18 @@ export class OrderAPI extends SQLDataSource {
|
|||||||
.where('id', addressId)
|
.where('id', addressId)
|
||||||
.first()
|
.first()
|
||||||
.cache(MINUTE);
|
.cache(MINUTE);
|
||||||
console.log('HERE', row);
|
|
||||||
return row
|
return row
|
||||||
? {
|
? {
|
||||||
id: row.id,
|
...row,
|
||||||
|
/* Change this later to camelCase but also need to change in Pwinty lambda */
|
||||||
firstname: row.firstName,
|
firstname: row.firstName,
|
||||||
|
lastname: row.lastName,
|
||||||
|
companyname: row.companyName,
|
||||||
|
recipientName: `${row.firstName} ${row.lastName}`.trim(),
|
||||||
|
stateCountyOrRegion: row.state ? row.state : null,
|
||||||
}
|
}
|
||||||
: null;
|
: null;
|
||||||
/**
|
|
||||||
* address = cls()
|
|
||||||
address.id = row["id"]
|
|
||||||
address.firstname = row["first_name"]
|
|
||||||
address.lastname = row["last_name"]
|
|
||||||
address.companyname = row["company_name"]
|
|
||||||
address.address1 = row["address1"]
|
|
||||||
address.address2 = row["address2"]
|
|
||||||
address.countryCode = row["country_code"]
|
|
||||||
address.city = row["city"]
|
|
||||||
address.zipcode = row["zipcode"]
|
|
||||||
address.stateCountyOrRegion = row["state"]
|
|
||||||
|
|
||||||
return address
|
|
||||||
|
|
||||||
def resolve_recipientName(self, info):
|
|
||||||
if self.firstname or self.lastname:
|
|
||||||
return "{} {}".format(self.firstname, self.lastname).strip()
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getBillingInformation(row): ContactInformation {
|
getBillingInformation(row): ContactInformation {
|
||||||
@@ -121,7 +46,7 @@ export class OrderAPI extends SQLDataSource {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async getOrders() {
|
async getOrders(): Promise<Array<Order>> {
|
||||||
return await this.knex
|
return await this.knex
|
||||||
.select('*')
|
.select('*')
|
||||||
.from('orders')
|
.from('orders')
|
||||||
@@ -142,6 +67,96 @@ export class OrderAPI extends SQLDataSource {
|
|||||||
.from('orders')
|
.from('orders')
|
||||||
.where('id', id)
|
.where('id', id)
|
||||||
.first()
|
.first()
|
||||||
.cache(MINUTE);
|
.cache(MINUTE)
|
||||||
|
.then((row) => {
|
||||||
|
row.billingInformation = this.getBillingInformation(row);
|
||||||
|
row.deliveryInformation = this.getDeliveryInformation(row);
|
||||||
|
return row;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async getOrderRows(orderId: number): Promise<Array<OrderRow>> {
|
||||||
|
// const fields = await this.knex.select('*').from('order-row_fields');
|
||||||
|
const fieldsRes = await this.knex
|
||||||
|
.raw('SELECT * from "order-row_fields"')
|
||||||
|
.then((data) => data.rows);
|
||||||
|
|
||||||
|
const fields = fieldsRes.reduce((obj, item) => {
|
||||||
|
obj[item.fieldid] = item.name;
|
||||||
|
return obj;
|
||||||
|
}, {});
|
||||||
|
|
||||||
|
const rows = await this.knex
|
||||||
|
.raw('SELECT * FROM "order-rows" WHERE orderid = ?', orderId)
|
||||||
|
.then((data) => data.rows);
|
||||||
|
|
||||||
|
let orderRows = [];
|
||||||
|
for (let i = 0; i < rows.length; i++) {
|
||||||
|
const rowId = rows[i].rowid;
|
||||||
|
const details = await this.knex
|
||||||
|
.raw('SELECT * FROM "order-rows_details" WHERE rowid = ?', rowId)
|
||||||
|
.then((data) => data.rows);
|
||||||
|
|
||||||
|
// Skip empty order rows
|
||||||
|
if (!details.length) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const orderRow = details.reduce((obj, item) => {
|
||||||
|
obj[camelcase(fields[item.fieldid])] = item.value;
|
||||||
|
obj['insertedDate'] = item.inserted;
|
||||||
|
return obj;
|
||||||
|
}, {});
|
||||||
|
|
||||||
|
if ('group' in orderRow) {
|
||||||
|
orderRow['productGroup'] = orderRow['group'];
|
||||||
|
}
|
||||||
|
|
||||||
|
orderRow['id'] = rowId;
|
||||||
|
orderRow['orderId'] = orderId;
|
||||||
|
orderRows.push(orderRow);
|
||||||
|
}
|
||||||
|
return orderRows;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
{
|
||||||
|
printId: '73963',
|
||||||
|
inserted: 2021-02-04T10:11:41.093Z,
|
||||||
|
productId: '54192',
|
||||||
|
group: 'photo-wallpaper',
|
||||||
|
type: 'scaling',
|
||||||
|
artNo: 'e50075',
|
||||||
|
path: 'flora-hysterica-4',
|
||||||
|
name: 'Flora Hysterica 4',
|
||||||
|
price: '587.092480',
|
||||||
|
width: '640',
|
||||||
|
height: '260',
|
||||||
|
x: '0.000000',
|
||||||
|
y: '0.135133',
|
||||||
|
weight: '1',
|
||||||
|
designer: 'martin-bergstrom',
|
||||||
|
designerId: '201',
|
||||||
|
commission: '0',
|
||||||
|
commissionResale: '0',
|
||||||
|
status: 'print',
|
||||||
|
process: 'true',
|
||||||
|
vat: '1.210000',
|
||||||
|
commissionAmount: '0.000000',
|
||||||
|
framed: '0',
|
||||||
|
mirrored: '0',
|
||||||
|
edge: '0',
|
||||||
|
imageprocessed: 'true',
|
||||||
|
imageprocessingrejected: 'false',
|
||||||
|
resolution: '150',
|
||||||
|
imagedonotprint: 'false',
|
||||||
|
material: 'premium-wallpaper',
|
||||||
|
discountType: '%',
|
||||||
|
discountValue: '25',
|
||||||
|
measureUnit: 'cm',
|
||||||
|
displayWidth: '640',
|
||||||
|
displayHeight: '260',
|
||||||
|
designerPath: 'martin-bergstrom'
|
||||||
|
},
|
||||||
|
|
||||||
|
*/
|
||||||
|
|||||||
@@ -0,0 +1,88 @@
|
|||||||
|
export interface Address {
|
||||||
|
id: number;
|
||||||
|
firstname: string;
|
||||||
|
lastname: string;
|
||||||
|
recipientName: string;
|
||||||
|
companyname: string;
|
||||||
|
address1: string;
|
||||||
|
address2: string;
|
||||||
|
countryCode: string;
|
||||||
|
city: string;
|
||||||
|
zipcode: string;
|
||||||
|
stateCountyOrRegion: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ContactInformation {
|
||||||
|
email: string;
|
||||||
|
phone: string;
|
||||||
|
addressId: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export 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;
|
||||||
|
flyerIds: string;
|
||||||
|
market: string;
|
||||||
|
locale: string;
|
||||||
|
billingInformation: ContactInformation;
|
||||||
|
deliveryInformation: ContactInformation;
|
||||||
|
billingAddressId: number;
|
||||||
|
deliveryAddressId: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface OrderRow {
|
||||||
|
id: number;
|
||||||
|
insertedDate: Date;
|
||||||
|
orderId: number;
|
||||||
|
productId: number;
|
||||||
|
productGroup: string;
|
||||||
|
artNo: string;
|
||||||
|
path: string;
|
||||||
|
name: string;
|
||||||
|
price: number;
|
||||||
|
designerId: string;
|
||||||
|
commissionAmount: string;
|
||||||
|
status: string;
|
||||||
|
pwintyImageId: number;
|
||||||
|
frameColor: string;
|
||||||
|
pwintySku: string;
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import orders, { ContactInformation } from './orders-resolver';
|
import orders, { ContactInformation, Order } from './orders-resolver';
|
||||||
import products from './products-resolver';
|
import products from './products-resolver';
|
||||||
import { DateTimeScalar } from './datetime-type';
|
import { DateTimeScalar } from './datetime-type';
|
||||||
|
|
||||||
@@ -6,6 +6,7 @@ const resolvers = {
|
|||||||
Query: { ...orders, ...products },
|
Query: { ...orders, ...products },
|
||||||
DateTime: DateTimeScalar,
|
DateTime: DateTimeScalar,
|
||||||
ContactInformation,
|
ContactInformation,
|
||||||
|
Order,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default resolvers;
|
export default resolvers;
|
||||||
|
|||||||
@@ -7,6 +7,12 @@ export const ContactInformation: IResolverObject = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const Order: IResolverObject = {
|
||||||
|
async rows({ id }, args, { dataSources }) {
|
||||||
|
return dataSources.orderApi.getOrderRows(id);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
async function getOrders(_, __, { dataSources }) {
|
async function getOrders(_, __, { dataSources }) {
|
||||||
return dataSources.orderApi.getOrders();
|
return dataSources.orderApi.getOrders();
|
||||||
}
|
}
|
||||||
@@ -17,7 +23,7 @@ async function getOrder(_, { id }, { dataSources }) {
|
|||||||
|
|
||||||
const orders = {
|
const orders = {
|
||||||
orders: getOrders,
|
orders: getOrders,
|
||||||
order: () => getOrder,
|
order: getOrder,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default orders;
|
export default orders;
|
||||||
|
|||||||
@@ -12,6 +12,15 @@ const typeDefs = gql`
|
|||||||
type Address {
|
type Address {
|
||||||
id: ID!
|
id: ID!
|
||||||
firstname: String
|
firstname: String
|
||||||
|
lastname: String
|
||||||
|
recipientName: String
|
||||||
|
companyname: String
|
||||||
|
address1: String
|
||||||
|
address2: String
|
||||||
|
countryCode: String
|
||||||
|
city: String
|
||||||
|
zipcode: String
|
||||||
|
stateCountyOrRegion: String
|
||||||
}
|
}
|
||||||
|
|
||||||
type ContactInformation {
|
type ContactInformation {
|
||||||
@@ -69,6 +78,26 @@ const typeDefs = gql`
|
|||||||
deliveryInformation: ContactInformation
|
deliveryInformation: ContactInformation
|
||||||
billingAddressId: Int
|
billingAddressId: Int
|
||||||
deliveryAddressId: Int
|
deliveryAddressId: Int
|
||||||
|
rows: [OrderRow]
|
||||||
|
}
|
||||||
|
|
||||||
|
type OrderRow {
|
||||||
|
id: ID!
|
||||||
|
order: Order
|
||||||
|
insertedDate: DateTime
|
||||||
|
orderId: Int
|
||||||
|
productId: Int
|
||||||
|
productGroup: String
|
||||||
|
artNo: String
|
||||||
|
path: String
|
||||||
|
name: String
|
||||||
|
price: Float
|
||||||
|
designerId: String
|
||||||
|
commissionAmount: String
|
||||||
|
status: String
|
||||||
|
pwintyImageId: Int
|
||||||
|
frameColor: String
|
||||||
|
pwintySku: String
|
||||||
}
|
}
|
||||||
|
|
||||||
type Product {
|
type Product {
|
||||||
|
|||||||
Reference in New Issue
Block a user