Fixed small bugs

This commit is contained in:
Niklas Fondberg
2021-04-08 23:27:55 +02:00
parent 3c648cee29
commit a296ead1ca
7 changed files with 78 additions and 84 deletions
+16 -17
View File
@@ -58,20 +58,28 @@ export class OrderAPI extends BaseSQLDataSource {
getBillingInformation(row): ContactInformation {
return {
email: 'niklas.fondberg@photowall.se',
phone: '+46761386397',
email: row.email,
phone: row.phone,
addressId: row.billingAddressId,
};
}
getDeliveryInformation(row): ContactInformation {
return {
email: 'niklas.fondberg@photowall.se', // TODO: fix hardcoded
phone: '+46761386397',
email: row.deliveryEmail,
phone: row.deliveryPhone,
addressId: row.deliveryAddressId,
};
}
createOrderFromRow(row: any): Order {
row.billingInformation = this.getBillingInformation(row);
row.deliveryInformation = this.getDeliveryInformation(row);
row.marketName = row.market;
row.localeName = row.locale;
return row;
}
async getOrders(input: Maybe<GeneralInput>): Promise<Array<Order>> {
let query = this.knex.select('*').from('orders');
// .where('inserted', '>=', '2021-03-01T00:00:00Z')
@@ -89,14 +97,9 @@ export class OrderAPI extends BaseSQLDataSource {
query = query.limit(input?.limit);
}
// console.log(query.toString());
return await query.cache(MINUTE).then((rows) =>
rows.map((row) => {
row.billingInformation = this.getBillingInformation(row);
row.deliveryInformation = this.getDeliveryInformation(row);
return row;
}),
);
return await query
.cache(MINUTE)
.then((rows) => rows.map((row) => this.createOrderFromRow(row)));
}
async getOrderById(id: number): Promise<Order> {
@@ -106,11 +109,7 @@ export class OrderAPI extends BaseSQLDataSource {
.where('id', id)
.first()
.cache(MINUTE)
.then((row) => {
row.billingInformation = this.getBillingInformation(row);
row.deliveryInformation = this.getDeliveryInformation(row);
return row;
});
.then((row) => this.createOrderFromRow(row));
}
async getOrderRowFieldMapping(): Promise<any> {
+13 -17
View File
@@ -55,6 +55,13 @@ export class ProductAPI extends SQLDataSource {
});
}
createProductFromRow(row: any) {
row.blacklisting = this.getBlacklisting(row);
row.printProducts = this.getPrintProducts(row);
row.designerId = row.designerid;
return row;
}
async getProducts(
limit: Maybe<number>,
visible: Maybe<boolean>,
@@ -63,28 +70,17 @@ export class ProductAPI extends SQLDataSource {
limit = limit ?? 100;
const query = sql.products(limit, visible, browsable);
return await this.knex.raw(query).then((data) =>
data.rows.map((row) => {
row.blacklisting = this.getBlacklisting(row);
row.printProducts = this.getPrintProducts(row);
row.designerId = row.designerid;
return row;
}),
);
return await this.knex
.raw(query)
.then((data) => data.rows.map((row) => this.createProductFromRow(row)));
}
async getProduct(id: number): Promise<Maybe<Product>> {
const query = sql.product(id);
const res = await this.knex.raw(query).then((data) =>
data.rows.map((row) => {
console.log(row);
row.blacklisting = this.getBlacklisting(row);
row.printProducts = this.getPrintProducts(row);
row.designerId = row.designerid;
return row;
}),
);
const res = await this.knex
.raw(query)
.then((data) => data.rows.map((row) => this.createProductFromRow(row)));
return res.find(Boolean);
}
}
-43
View File
@@ -1,43 +0,0 @@
import { GraphQLScalarType } from 'graphql';
import { Kind } from 'graphql/language';
// possible switch to https://github.com/Urigo/graphql-scalars
const DateTimeScalar = new GraphQLScalarType({
name: 'DateTime',
description: 'Date time custom scalar type',
parseValue(value) {
return new Date(value); // value from the client
},
serialize(value) {
return new Date(value).toISOString(); // value sent to the client
},
parseLiteral(ast) {
if (ast.kind === Kind.INT) {
return parseInt(ast.value, 10); // ast value is always in string format
}
return null;
},
});
const DateScalar = new GraphQLScalarType({
name: 'DateTime',
description: 'Date custom scalar type',
parseValue(value) {
console.log('FROM CLIENT:', value);
return new Date(value); // value from the client
},
serialize(value) {
return new Date(value).toISOString().split('T')[0]; // value sent to the client
},
parseLiteral(ast) {
if (ast.kind === Kind.INT) {
return parseInt(ast.value, 10); // ast value is always in string format
}
return null;
},
});
export const CustomTypes = {
DateTime: DateTimeScalar,
Date: DateScalar,
};
+2 -1
View File
@@ -13,7 +13,8 @@ const Order: IResolverObject = {
async rows({ id }, args, { dataSources }) {
return (<OrderAPI>dataSources.orderApi).getOrderRowsByOrderId(id);
},
async marketObject({ market }, args, { dataSources }) {
// TODO change to market
async market({ market }, args, { dataSources }) {
return (<OrderAPI>dataSources.orderApi).getMarketByName(market);
},
};
+3 -3
View File
@@ -94,14 +94,14 @@ const typeDefs = gql`
customerEmail: String
customerCellphone: String
flyerIds: String
market: String
locale: String
marketName: String
localeName: String
billingInformation: ContactInformation
deliveryInformation: ContactInformation
billingAddressId: Int
deliveryAddressId: Int
rows: [OrderRow]
marketObject: Market
market: Market
}
type OrderRow {