|
|
@ -71,15 +71,16 @@ export class IngredientsGateway {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async getByLetter(letter: string): Promise<any> {
|
|
|
|
async getByLetter(letter: string): Promise<any> {
|
|
|
|
this.connection.connect();
|
|
|
|
const client = await this.connection.getPoolClient()
|
|
|
|
|
|
|
|
|
|
|
|
const query = {
|
|
|
|
const query = {
|
|
|
|
text: 'SELECT * FROM Ingredients i WHERE LOWER(SUBSTRING(i.name, 1, 1)) = $1',
|
|
|
|
text: 'SELECT * FROM Ingredients i WHERE LOWER(SUBSTRING(i.name, 1, 1)) = $1',
|
|
|
|
values: [letter.toLowerCase()],
|
|
|
|
values: [letter.toLowerCase()],
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const res = await this.connection.client.query(query);
|
|
|
|
const res = await client.query(query);
|
|
|
|
console.log(res)
|
|
|
|
|
|
|
|
|
|
|
|
client.release()
|
|
|
|
|
|
|
|
|
|
|
|
if (res.rowCount === 0) {
|
|
|
|
if (res.rowCount === 0) {
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
@ -96,15 +97,16 @@ export class IngredientsGateway {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async filter(prompt: string): Promise<any> {
|
|
|
|
async filter(prompt: string): Promise<any> {
|
|
|
|
this.connection.connect();
|
|
|
|
const client = await this.connection.getPoolClient()
|
|
|
|
|
|
|
|
|
|
|
|
const query = {
|
|
|
|
const query = {
|
|
|
|
text: 'SELECT * FROM Ingredients WHERE LOWER(name) LIKE $1',
|
|
|
|
text: 'SELECT * FROM Ingredients WHERE LOWER(name) LIKE $1',
|
|
|
|
values: [`%${prompt.toLowerCase()}%`],
|
|
|
|
values: [`%${prompt.toLowerCase()}%`],
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const res = await this.connection.client.query(query);
|
|
|
|
const res = await client.query(query);
|
|
|
|
console.log(res)
|
|
|
|
|
|
|
|
|
|
|
|
client.release()
|
|
|
|
|
|
|
|
|
|
|
|
if (res.rowCount === 0) {
|
|
|
|
if (res.rowCount === 0) {
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|