Add arguments
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
|||||||
PrintProduct,
|
PrintProduct,
|
||||||
ProductBlacklist,
|
ProductBlacklist,
|
||||||
} from './product-types';
|
} from './product-types';
|
||||||
|
import { Maybe } from './types';
|
||||||
|
|
||||||
const MINUTE = 60;
|
const MINUTE = 60;
|
||||||
|
|
||||||
@@ -34,17 +35,22 @@ export class ProductAPI extends SQLDataSource {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async getProducts(args: any): Promise<Product> {
|
async getProducts(
|
||||||
const query = sql.products(true, true, 10);
|
limit: Maybe<number>,
|
||||||
// console.log(query);
|
visible: Maybe<boolean>,
|
||||||
const data = await this.knex.raw(query).then((data) => {
|
browsable: Maybe<boolean>,
|
||||||
// console.log(data);
|
): Promise<Product> {
|
||||||
return data.rows.map((row) => {
|
// console.log(limit, browsable, visible);
|
||||||
|
limit = limit ?? 100;
|
||||||
|
const query = sql.products(limit, visible, browsable);
|
||||||
|
|
||||||
|
const data = await this.knex.raw(query).then((data) =>
|
||||||
|
data.rows.map((row) => {
|
||||||
row.blacklisting = this.getBlacklisting(row);
|
row.blacklisting = this.getBlacklisting(row);
|
||||||
row.printProducts = this.getPrintProducts(row);
|
row.printProducts = this.getPrintProducts(row);
|
||||||
return row;
|
return row;
|
||||||
});
|
}),
|
||||||
});
|
);
|
||||||
|
|
||||||
// console.log(JSON.stringify(data, null, 2));
|
// console.log(JSON.stringify(data, null, 2));
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
|
import { Maybe } from '../types';
|
||||||
|
|
||||||
// Get syntax highlighting with vscode by installing "Comment tagged templates2
|
// Get syntax highlighting with vscode by installing "Comment tagged templates2
|
||||||
|
|
||||||
export function products(
|
export function products(
|
||||||
visible: boolean | null,
|
|
||||||
browsable: boolean | null,
|
|
||||||
limit: number = 100,
|
limit: number = 100,
|
||||||
|
visible: Maybe<boolean>,
|
||||||
|
browsable: Maybe<boolean>,
|
||||||
) {
|
) {
|
||||||
const query = /* sql */ `
|
const query = /* sql */ `
|
||||||
|
|
||||||
@@ -55,7 +57,6 @@ export function products(
|
|||||||
AND products.browsable = ${browsable ? '1' : '0'}`
|
AND products.browsable = ${browsable ? '1' : '0'}`
|
||||||
: ``
|
: ``
|
||||||
}
|
}
|
||||||
GROUP BY products.productid
|
|
||||||
LIMIT ${limit}
|
LIMIT ${limit}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
export type Maybe<T> = T | undefined;
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
// (parent, args, ctx, info)
|
// (parent, args, ctx, info)
|
||||||
const products = {
|
const products = {
|
||||||
products: (_, args, { dataSources }) =>
|
products: (_, { limit, visible, browsable }, { dataSources }) =>
|
||||||
dataSources.productApi.getProducts(args),
|
dataSources.productApi.getProducts(limit, visible, browsable),
|
||||||
};
|
};
|
||||||
|
|
||||||
export default products;
|
export default products;
|
||||||
|
|||||||
Reference in New Issue
Block a user