Address embryo
This commit is contained in:
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
products(limit: 10000, browsable: true, visible: true) {
|
||||||
|
id
|
||||||
|
inserted
|
||||||
|
updated
|
||||||
|
visible
|
||||||
|
browsable
|
||||||
|
printProducts {
|
||||||
|
group
|
||||||
|
id
|
||||||
|
updated
|
||||||
|
}
|
||||||
|
blacklisting {
|
||||||
|
group
|
||||||
|
id
|
||||||
|
marketId
|
||||||
|
updated
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,19 @@
|
|||||||
import { SQLDataSource } from 'datasource-sql';
|
import { SQLDataSource } from 'datasource-sql';
|
||||||
|
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 {
|
interface Order {
|
||||||
id: number;
|
id: number;
|
||||||
inserted: Date;
|
inserted: Date;
|
||||||
@@ -44,11 +56,13 @@ interface Order {
|
|||||||
customerLastname: string;
|
customerLastname: string;
|
||||||
customerEmail: string;
|
customerEmail: string;
|
||||||
customerCellphone: string;
|
customerCellphone: string;
|
||||||
billingAddressId: number;
|
|
||||||
deliveryAddressId: number;
|
|
||||||
flyerIds: string;
|
flyerIds: string;
|
||||||
market: string;
|
market: string;
|
||||||
locale: string;
|
locale: string;
|
||||||
|
billingInformation: ContactInformation;
|
||||||
|
deliveryInformation: ContactInformation;
|
||||||
|
billingAddressId: number;
|
||||||
|
deliveryAddressId: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class OrderAPI extends SQLDataSource {
|
export class OrderAPI extends SQLDataSource {
|
||||||
@@ -56,19 +70,70 @@ export class OrderAPI extends SQLDataSource {
|
|||||||
super(config);
|
super(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getAddress(addressId: number): Promise<Maybe<Address>> {
|
||||||
|
const row = await this.knex
|
||||||
|
.select('*')
|
||||||
|
.from('addresses')
|
||||||
|
.where('id', addressId)
|
||||||
|
.first()
|
||||||
|
.cache(MINUTE);
|
||||||
|
console.log('HERE', row);
|
||||||
|
return row
|
||||||
|
? {
|
||||||
|
id: row.id,
|
||||||
|
firstname: row.firstName,
|
||||||
|
}
|
||||||
|
: 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 {
|
||||||
|
return {
|
||||||
|
email: 'niklas.fondberg@photowall.se',
|
||||||
|
phone: '+46761386397',
|
||||||
|
addressId: row.billingAddressId,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
getDeliveryInformation(row): ContactInformation {
|
||||||
|
return {
|
||||||
|
email: 'niklas.fondberg@photowall.se',
|
||||||
|
phone: '+46761386397',
|
||||||
|
addressId: row.deliveryAddressId,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
async getOrders() {
|
async getOrders() {
|
||||||
const data = await this.knex
|
return await this.knex
|
||||||
.select('*')
|
.select('*')
|
||||||
.from('orders')
|
.from('orders')
|
||||||
.where('inserted', '>=', '2021-03-01T00:00:00Z')
|
.where('inserted', '>=', '2021-03-01T00:00:00Z')
|
||||||
.cache(MINUTE);
|
.cache(MINUTE)
|
||||||
|
.then((rows) =>
|
||||||
console.log(data);
|
rows.map((row) => {
|
||||||
|
row.billingInformation = this.getBillingInformation(row);
|
||||||
return [
|
row.deliveryInformation = this.getDeliveryInformation(row);
|
||||||
{ id: 1, countryCode: 'SE' },
|
return row;
|
||||||
{ id: 2, countryCode: 'DK' },
|
}),
|
||||||
];
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getOrder(id: number): Promise<Order> {
|
async getOrder(id: number): Promise<Order> {
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import orders from './orders-resolver';
|
import orders, { ContactInformation } from './orders-resolver';
|
||||||
import products from './products-resolver';
|
import products from './products-resolver';
|
||||||
import { DateTimeScalar } from './datetime-type';
|
import { DateTimeScalar } from './datetime-type';
|
||||||
|
|
||||||
const resolvers = {
|
const resolvers = {
|
||||||
Query: { ...orders, ...products },
|
Query: { ...orders, ...products },
|
||||||
DateTime: DateTimeScalar,
|
DateTime: DateTimeScalar,
|
||||||
|
ContactInformation,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default resolvers;
|
export default resolvers;
|
||||||
|
|||||||
@@ -1,7 +1,23 @@
|
|||||||
|
import { IResolverObject } from 'graphql-tools';
|
||||||
|
|
||||||
|
export const ContactInformation: IResolverObject = {
|
||||||
// (parent, args, ctx, info)
|
// (parent, args, ctx, info)
|
||||||
|
async address({ addressId }, args, { dataSources }) {
|
||||||
|
return dataSources.orderApi.getAddress(addressId);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
async function getOrders(_, __, { dataSources }) {
|
||||||
|
return dataSources.orderApi.getOrders();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getOrder(_, { id }, { dataSources }) {
|
||||||
|
return dataSources.orderApi.getOrder(id);
|
||||||
|
}
|
||||||
|
|
||||||
const orders = {
|
const orders = {
|
||||||
orders: (_, __, { dataSources }) => dataSources.orderApi.getOrders(),
|
orders: getOrders,
|
||||||
order: (_, { id }, { dataSources }) => dataSources.orderApi.getOrder(id),
|
order: () => getOrder,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default orders;
|
export default orders;
|
||||||
|
|||||||
+149
-4
@@ -9,6 +9,17 @@ const typeDefs = gql`
|
|||||||
products(limit: Int, visible: Boolean, browsable: Boolean): [Product]
|
products(limit: Int, visible: Boolean, browsable: Boolean): [Product]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Address {
|
||||||
|
id: ID!
|
||||||
|
firstname: String
|
||||||
|
}
|
||||||
|
|
||||||
|
type ContactInformation {
|
||||||
|
email: String
|
||||||
|
phone: String
|
||||||
|
address: Address
|
||||||
|
}
|
||||||
|
|
||||||
type Order {
|
type Order {
|
||||||
id: ID!
|
id: ID!
|
||||||
inserted: DateTime!
|
inserted: DateTime!
|
||||||
@@ -51,11 +62,13 @@ const typeDefs = gql`
|
|||||||
customerLastname: String
|
customerLastname: String
|
||||||
customerEmail: String
|
customerEmail: String
|
||||||
customerCellphone: String
|
customerCellphone: String
|
||||||
billingAddressId: Int
|
|
||||||
deliveryAddressId: Int
|
|
||||||
flyerIds: String
|
flyerIds: String
|
||||||
market: String
|
market: String
|
||||||
locale: String
|
locale: String
|
||||||
|
billingInformation: ContactInformation
|
||||||
|
deliveryInformation: ContactInformation
|
||||||
|
billingAddressId: Int
|
||||||
|
deliveryAddressId: Int
|
||||||
}
|
}
|
||||||
|
|
||||||
type Product {
|
type Product {
|
||||||
@@ -97,9 +110,141 @@ const typeDefs = gql`
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
export { typeDefs };
|
||||||
/**
|
/**
|
||||||
|
schema {
|
||||||
|
query: Query
|
||||||
|
}
|
||||||
|
|
||||||
|
type Address {
|
||||||
|
id: ID!
|
||||||
|
firstname: String
|
||||||
|
lastname: String
|
||||||
|
recipientName: String
|
||||||
|
companyname: String
|
||||||
|
address1: String
|
||||||
|
address2: String
|
||||||
|
countryCode: String
|
||||||
|
city: String
|
||||||
|
zipcode: String
|
||||||
|
stateCountyOrRegion: String
|
||||||
|
}
|
||||||
|
|
||||||
|
type Category {
|
||||||
|
id: ID!
|
||||||
|
name: String
|
||||||
|
}
|
||||||
|
|
||||||
|
type ContactInformation {
|
||||||
|
email: String
|
||||||
|
phone: String
|
||||||
|
address: Address
|
||||||
|
}
|
||||||
|
|
||||||
|
scalar Date
|
||||||
|
|
||||||
|
scalar DateTime
|
||||||
|
|
||||||
|
type Designer {
|
||||||
|
id: ID!
|
||||||
|
name: String
|
||||||
|
orderRows(fromDate: Date, toDate: Date): [OrderRow]
|
||||||
|
}
|
||||||
|
|
||||||
|
enum Group {
|
||||||
|
PHOTO_WALLPAPER
|
||||||
|
CANVAS
|
||||||
|
WALLPAPER
|
||||||
|
DO_IT_YOURSELF_FRAME
|
||||||
|
DESIGNER_WALLPAPER
|
||||||
|
POSTER
|
||||||
|
FRAMED_PRINT
|
||||||
|
}
|
||||||
|
|
||||||
|
scalar JSONString
|
||||||
|
|
||||||
|
type Market {
|
||||||
|
id: ID!
|
||||||
|
name: String
|
||||||
|
}
|
||||||
|
|
||||||
|
type Order {
|
||||||
|
id: ID!
|
||||||
|
insertedDate: DateTime!
|
||||||
|
paid: Boolean!
|
||||||
|
confirmed: Boolean!
|
||||||
|
delivered: Boolean!
|
||||||
|
canceled: Boolean!
|
||||||
|
countryCode: String!
|
||||||
|
locale: String!
|
||||||
|
market: String!
|
||||||
|
currency: String
|
||||||
|
contractCustomerId: Int
|
||||||
|
exchangeRateEUR: Float
|
||||||
|
language: String
|
||||||
|
pwintyId: Int
|
||||||
|
email: String
|
||||||
|
phone: String
|
||||||
|
rows: [OrderRow]
|
||||||
|
billingInformation: ContactInformation
|
||||||
|
deliveryInformation: ContactInformation
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
json: JSONString
|
||||||
|
}
|
||||||
|
|
||||||
|
type PrintProduct {
|
||||||
|
id: ID!
|
||||||
|
group: Group!
|
||||||
|
insertedDate: DateTime!
|
||||||
|
updatedDate: DateTime
|
||||||
|
}
|
||||||
|
|
||||||
|
type Product {
|
||||||
|
id: ID!
|
||||||
|
path: String!
|
||||||
|
visible: Boolean
|
||||||
|
browsable: Boolean
|
||||||
|
insertedDate: DateTime!
|
||||||
|
updatedDate: DateTime!
|
||||||
|
categories: [Category]
|
||||||
|
designer: Designer
|
||||||
|
printProducts: [PrintProduct]
|
||||||
|
blacklisting: [ProductBlacklist]
|
||||||
|
}
|
||||||
|
|
||||||
|
type ProductBlacklist {
|
||||||
|
id: ID!
|
||||||
|
group: Group!
|
||||||
|
marketId: String!
|
||||||
|
insertedDate: DateTime!
|
||||||
|
updatedDate: DateTime!
|
||||||
|
market: Market
|
||||||
|
}
|
||||||
|
|
||||||
|
type Query {
|
||||||
|
products(limit: Int, visible: Boolean, browsable: Boolean): [Product]
|
||||||
|
product(id: Int!): Product
|
||||||
|
order(id: Int!): Order
|
||||||
|
designer(id: Int!): Designer
|
||||||
|
designers: [Designer]
|
||||||
|
}
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export { typeDefs };
|
|
||||||
|
|||||||
Reference in New Issue
Block a user