Fixed small bugs
This commit is contained in:
@@ -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> {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user