Add product

This commit is contained in:
Niklas Fondberg
2021-04-08 15:09:31 +02:00
parent e0f629d54d
commit f60a51a94b
11 changed files with 184 additions and 171 deletions
+26 -2
View File
@@ -1,6 +1,12 @@
import { SQLDataSource } from 'datasource-sql';
import { camelcase } from 'stringcase';
import { Address, ContactInformation, Order, OrderRow } from './order-types';
import {
Address,
ContactInformation,
Market,
Order,
OrderRow,
} from './order-types';
import { Maybe } from './types';
const MINUTE = 60;
@@ -9,6 +15,24 @@ export class OrderAPI extends SQLDataSource {
super(config);
}
async getMarketById(id: number): Promise<Market> {
return await this.knex
.select('*')
.from('markets')
.where('id', id)
.first()
.cache(MINUTE);
}
async getMarketByName(name: string): Promise<Market> {
return await this.knex
.select('*')
.from('markets')
.where('name', name)
.first()
.cache(MINUTE);
}
async getAddress(addressId: number): Promise<Maybe<Address>> {
const row = await this.knex
.select('*')
@@ -103,7 +127,6 @@ export class OrderAPI extends SQLDataSource {
}
const orderRow = details.reduce((obj, item) => {
obj[camelcase(fields[item.fieldid])] = item.value;
obj['insertedDate'] = item.inserted;
return obj;
}, {});
@@ -120,6 +143,7 @@ export class OrderAPI extends SQLDataSource {
}
/**
* row
{
printId: '73963',
inserted: 2021-02-04T10:11:41.093Z,