Seach CODE or DESCRIPTION. Strip % from inbound string
Signed-off-by: James Ketrenos <james_eikona@ketrenos.com>
This commit is contained in:
parent
afabcd057f
commit
e6616356a2
@ -183,16 +183,19 @@ var queryType = new graphql.GraphQLObjectType({
|
|||||||
Whiskies: {
|
Whiskies: {
|
||||||
type: graphql.GraphQLList(WhiskyType),
|
type: graphql.GraphQLList(WhiskyType),
|
||||||
args: {
|
args: {
|
||||||
code: { type: graphql.GraphQLString }
|
code: { type: graphql.GraphQLString },
|
||||||
},
|
},
|
||||||
resolve: (root, {code}, context, info) => {
|
resolve: (root, {code}, context, info) => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
database.all(
|
if (code && code.trim() != "") {
|
||||||
|
code = `${code.replace(/%/g, '')}%`;
|
||||||
|
}
|
||||||
|
database.all(
|
||||||
"SELECT w.*,i.quantity,i.updated " +
|
"SELECT w.*,i.quantity,i.updated " +
|
||||||
"FROM Whiskies AS w " +
|
"FROM Whiskies AS w " +
|
||||||
"LEFT JOIN Inventories AS i ON w.code=i.whisky " +
|
"LEFT JOIN Inventories AS i ON w.code=i.whisky " +
|
||||||
(code ? "WHERE w.code LIKE (?) " : "") +
|
(code ? "WHERE w.code LIKE (?) OR w.description LIKE (?)" : "") +
|
||||||
";", [code], function(err, rows) {
|
";", [code, code], function(err, rows) {
|
||||||
if (err) { console.error(err); return reject(null); }
|
if (err) { console.error(err); return reject(null); }
|
||||||
resolve(buildWhiskies(rows));
|
resolve(buildWhiskies(rows));
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user