Seach CODE or DESCRIPTION. Strip % from inbound string

Signed-off-by: James Ketrenos <james_eikona@ketrenos.com>
This commit is contained in:
James Ketrenos 2021-08-16 15:59:00 -07:00
parent afabcd057f
commit e6616356a2

View File

@ -183,16 +183,19 @@ var queryType = new graphql.GraphQLObjectType({
Whiskies: {
type: graphql.GraphQLList(WhiskyType),
args: {
code: { type: graphql.GraphQLString }
code: { type: graphql.GraphQLString },
},
resolve: (root, {code}, context, info) => {
return new Promise((resolve, reject) => {
if (code && code.trim() != "") {
code = `${code.replace(/%/g, '')}%`;
}
database.all(
"SELECT w.*,i.quantity,i.updated " +
"FROM Whiskies AS w " +
"LEFT JOIN Inventories AS i ON w.code=i.whisky " +
(code ? "WHERE w.code LIKE (?) " : "") +
";", [code], function(err, rows) {
(code ? "WHERE w.code LIKE (?) OR w.description LIKE (?)" : "") +
";", [code, code], function(err, rows) {
if (err) { console.error(err); return reject(null); }
resolve(buildWhiskies(rows));
});