sqlquerybuilder
Advanced tools
Comparing version 0.0.42 to 0.0.43
263
lib/where.js
@@ -75,4 +75,4 @@ var _ = require('lodash'), | ||
for (var i = 0; i < filters.length; i++) { | ||
var filter = filters[i]; | ||
if(filter === "") continue; | ||
var filter = filters[i].trim(); | ||
if (filter === "") continue; | ||
@@ -98,142 +98,155 @@ if (whereString !== "") | ||
// String filters | ||
opIndex = filter.indexOf(".Contains"); | ||
if (opIndex !== -1) { | ||
reference = filter.substr(0, opIndex); | ||
whereString += self._whereJoin(reference) + " LIKE '%" + | ||
filter.substr(opIndex + 11, filter.lastIndexOf("\"") - (opIndex + 11)) + | ||
"%'"; | ||
continue; | ||
} | ||
// filter could be or'd combination | ||
var subFilters = filter.split("||"); | ||
var ored = (subFilters.length > 1); | ||
if (ored) whereString += "("; | ||
opIndex = filter.indexOf(".StartsWith"); | ||
if (opIndex != -1) { | ||
reference = filter.substr(0, opIndex); | ||
whereString += self._whereJoin(reference) + | ||
" LIKE '" + | ||
filter.substr(opIndex + 13, filter.lastIndexOf("\"") - (opIndex + 13)) + | ||
"%'"; | ||
continue; | ||
} | ||
for (var s = 0; s < subFilters.length; s++) { | ||
var subFilter = subFilters[s].trim(); | ||
opIndex = filter.indexOf(".EndsWith"); | ||
if (opIndex != -1) { | ||
reference = filter.substr(0, opIndex); | ||
whereString += self._whereJoin(reference) + | ||
" LIKE '%" + | ||
filter.substr(opIndex + 11, filter.lastIndexOf("\"") - (opIndex + 11)) + | ||
"'"; | ||
continue; | ||
} | ||
if (ored && s > 0) | ||
whereString += " OR "; | ||
opIndex = filter.indexOf(".Equals"); | ||
var shouldAppendParenth = false; | ||
if (opIndex !== -1) { | ||
if (filter.charAt(0) === '(') { | ||
whereString += '('; | ||
filter = filter.substr(1); | ||
opIndex = filter.indexOf(".Equals"); | ||
shouldAppendParenth = true; | ||
// String filters | ||
opIndex = subFilter.indexOf(".Contains"); | ||
if (opIndex !== -1) { | ||
reference = subFilter.substr(0, opIndex); | ||
whereString += self._whereJoin(reference) + " LIKE '%" + | ||
subFilter.substr(opIndex + 11, subFilter.lastIndexOf("\"") - (opIndex + 11)) + | ||
"%'"; | ||
continue; | ||
} | ||
reference = filter.substr(0, opIndex); | ||
whereString += self._whereJoin(reference) + | ||
" = '" + | ||
filter.substr(opIndex + 9, filter.lastIndexOf("\"") - (opIndex + 9)) + | ||
"'"; | ||
if (shouldAppendParenth) | ||
whereString += ')'; | ||
opIndex = subFilter.indexOf(".StartsWith"); | ||
if (opIndex != -1) { | ||
reference = subFilter.substr(0, opIndex); | ||
whereString += self._whereJoin(reference) + | ||
" LIKE '" + | ||
subFilter.substr(opIndex + 13, subFilter.lastIndexOf("\"") - (opIndex + 13)) + | ||
"%'"; | ||
continue; | ||
} | ||
continue; | ||
} | ||
opIndex = subFilter.indexOf(".EndsWith"); | ||
if (opIndex != -1) { | ||
reference = subFilter.substr(0, opIndex); | ||
whereString += self._whereJoin(reference) + | ||
" LIKE '%" + | ||
subFilter.substr(opIndex + 11, subFilter.lastIndexOf("\"") - (opIndex + 11)) + | ||
"'"; | ||
continue; | ||
} | ||
// Date filters, strict inequalities need to come after their non strict versions | ||
opIndex = filter.indexOf(">="); | ||
if (opIndex != -1) { | ||
reference = filter.substr(0, opIndex); | ||
whereString += self._whereJoin(reference) + | ||
" >= '" + | ||
filter.substr(opIndex + 2, filter.length - opIndex) + | ||
"'"; | ||
continue; | ||
} | ||
opIndex = subFilter.indexOf(".Equals"); | ||
var shouldAppendParenth = false; | ||
if (opIndex !== -1) { | ||
if (subFilter.charAt(0) === '(') { | ||
whereString += '('; | ||
subFilter = subFilter.substr(1); | ||
opIndex = subFilter.indexOf(".Equals"); | ||
shouldAppendParenth = true; | ||
} | ||
reference = subFilter.substr(0, opIndex); | ||
opIndex = filter.indexOf(">"); | ||
if (opIndex != -1) { | ||
reference = filter.substr(0, opIndex); | ||
whereString += self._whereJoin(reference) + | ||
" > '" + | ||
filter.substr(opIndex + 1, filter.length - opIndex)+ //.replace(/-/g, "/") + | ||
"'"; | ||
continue; | ||
} | ||
whereString += self._whereJoin(reference) + | ||
" = '" + | ||
subFilter.substr(opIndex + 9, subFilter.lastIndexOf("\"") - (opIndex + 9)) + | ||
"'"; | ||
if (shouldAppendParenth) | ||
whereString += ')'; | ||
opIndex = filter.indexOf("<="); | ||
if (opIndex != -1) { | ||
reference = filter.substr(0, opIndex); | ||
whereString += self._whereJoin(reference) + | ||
" <= '" + | ||
filter.substr(opIndex + 2, filter.length - opIndex - 1)+ //.replace(/-/g, "/") + | ||
"'"; | ||
continue; | ||
} | ||
continue; | ||
} | ||
opIndex = filter.indexOf("<"); | ||
if (opIndex != -1) { | ||
reference = filter.substr(0, opIndex); | ||
whereString += self._whereJoin(reference) + | ||
" < '" + | ||
filter.substr(opIndex + 1, filter.length - opIndex - 1) + | ||
"'"; | ||
continue; | ||
} | ||
// Date filters, strict inequalities need to come after their non strict versions | ||
opIndex = subFilter.indexOf(">="); | ||
if (opIndex != -1) { | ||
reference = subFilter.substr(0, opIndex); | ||
whereString += self._whereJoin(reference) + | ||
" >= '" + | ||
subFilter.substr(opIndex + 2, subFilter.length - opIndex) + | ||
"'"; | ||
continue; | ||
} | ||
// Dropdown filters | ||
opIndex = filter.indexOf("=="); | ||
if (opIndex != -1) { | ||
reference = filter.substr(1, opIndex - 1); | ||
whereString += "(" + self._whereJoin(reference) + | ||
" = " + | ||
convertTrueFalse(filter.substr(opIndex + 2, filter.length - opIndex - 3)) + | ||
")"; | ||
continue; | ||
} | ||
opIndex = subFilter.indexOf(">"); | ||
if (opIndex != -1) { | ||
reference = subFilter.substr(0, opIndex); | ||
whereString += self._whereJoin(reference) + | ||
" > '" + | ||
subFilter.substr(opIndex + 1, subFilter.length - opIndex) + //.replace(/-/g, "/") + | ||
"'"; | ||
continue; | ||
} | ||
opIndex = filter.indexOf('!='); | ||
var pars; | ||
if(opIndex != - 1){ | ||
pars = filter.split('!='); | ||
reference = pars[0]; | ||
whereString += "(" + self._whereJoin(reference) + (pars[1].toUpperCase() === "NULL" ? " IS NOT " : " != "); | ||
if (isNaN(pars[1]) && pars[1].toUpperCase() !== "NULL") { | ||
whereString += "'"; | ||
whereString += convertTrueFalse(pars[1]) + "'" + ")"; | ||
} else { | ||
whereString += convertTrueFalse(pars[1]) + | ||
")"; | ||
opIndex = subFilter.indexOf("<="); | ||
if (opIndex != -1) { | ||
reference = subFilter.substr(0, opIndex); | ||
whereString += self._whereJoin(reference) + | ||
" <= '" + | ||
subFilter.substr(opIndex + 2, subFilter.length - opIndex - 1) + //.replace(/-/g, "/") + | ||
"'"; | ||
continue; | ||
} | ||
continue; | ||
} | ||
opIndex = filter.indexOf("="); | ||
if (opIndex != -1) { | ||
pars = filter.split('='); | ||
reference = pars[0]; | ||
whereString += "(" + self._whereJoin(reference) + (pars[1].toUpperCase() === "NULL" ? " IS " : " = "); | ||
if (isNaN(pars[1]) && pars[1].toUpperCase() !== "NULL") { | ||
whereString += "'"; | ||
whereString += convertTrueFalse(pars[1]) + "'" + ")"; | ||
} else { | ||
whereString += convertTrueFalse(pars[1]) + | ||
opIndex = subFilter.indexOf("<"); | ||
if (opIndex != -1) { | ||
reference = subFilter.substr(0, opIndex); | ||
whereString += self._whereJoin(reference) + | ||
" < '" + | ||
subFilter.substr(opIndex + 1, subFilter.length - opIndex - 1) + | ||
"'"; | ||
continue; | ||
} | ||
// Dropdown filters | ||
opIndex = subFilter.indexOf("=="); | ||
if (opIndex != -1) { | ||
reference = subFilter.substr(1, opIndex - 1); | ||
whereString += "(" + self._whereJoin(reference) + | ||
" = " + | ||
convertTrueFalse(subFilter.substr(opIndex + 2, subFilter.length - opIndex - 3)) + | ||
")"; | ||
continue; | ||
} | ||
continue; | ||
opIndex = subFilter.indexOf('!='); | ||
var pars; | ||
if (opIndex != -1) { | ||
pars = subFilter.split('!='); | ||
reference = pars[0]; | ||
whereString += "(" + self._whereJoin(reference) + (pars[1].toUpperCase() === "NULL" ? " IS NOT " : " != "); | ||
if (isNaN(pars[1]) && pars[1].toUpperCase() !== "NULL") { | ||
whereString += "'"; | ||
whereString += convertTrueFalse(pars[1]) + "'" + ")"; | ||
} else { | ||
whereString += convertTrueFalse(pars[1]) + | ||
")"; | ||
} | ||
continue; | ||
} | ||
opIndex = subFilter.indexOf("="); | ||
if (opIndex != -1) { | ||
pars = subFilter.split('='); | ||
reference = pars[0]; | ||
whereString += "(" + self._whereJoin(reference) + (pars[1].toUpperCase() === "NULL" ? " IS " : " = "); | ||
if (isNaN(pars[1]) && pars[1].toUpperCase() !== "NULL") { | ||
whereString += "'"; | ||
whereString += convertTrueFalse(pars[1]) + "'" + ")"; | ||
} else { | ||
whereString += convertTrueFalse(pars[1]) + | ||
")"; | ||
} | ||
continue; | ||
} | ||
// Yes/No filters | ||
opIndex = subFilter.indexOf("!"); | ||
reference = opIndex == -1 ? subFilter : subFilter.substr(1); | ||
whereString += self._whereJoin(reference) + | ||
" = " + | ||
(opIndex == -1 ? "1" : "0"); | ||
} | ||
// Yes/No filters | ||
opIndex = filter.indexOf("!"); | ||
reference = opIndex == -1 ? filter : filter.substr(1); | ||
whereString += self._whereJoin(reference) + | ||
" = " + | ||
(opIndex == -1 ? "1" : "0"); | ||
if (ored) whereString += ")"; | ||
} | ||
@@ -240,0 +253,0 @@ return self._where(whereString, ' AND '); |
{ | ||
"name": "sqlquerybuilder", | ||
"version": "0.0.42", | ||
"version": "0.0.43", | ||
"description": "Highly opinionated Sql Server Query Writer, mostly for internal use.", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index", |
@@ -44,746 +44,917 @@ /** | ||
it('it is called with filters', function(done){ | ||
var req = { | ||
query: { | ||
sidx: "Address.Description", | ||
sord: "ASC", | ||
rows: 100, | ||
page: 10, | ||
filters: 'IsActive=true' | ||
} | ||
}; | ||
// it('it is called with filters', function(done){ | ||
// var req = { | ||
// query: { | ||
// sidx: "Address.Description", | ||
// sord: "ASC", | ||
// rows: 100, | ||
// page: 10, | ||
// filters: 'IsActive=true' | ||
// } | ||
// }; | ||
// | ||
// (sqlBuilder() | ||
// .select({"y.Id" : "Id", "y.Name": "Name", "a.City": "Address.City", "a.State": "Address.State", "(a.City+', '+a.State)" : "Address.Description"}) | ||
// .from("Yards y") | ||
// .join("Addresses a", "y.address_id", "a.Id") | ||
// .processListRequest(req.query) | ||
// .build()) | ||
// .should.equal("WITH SelectedItems AS (" + | ||
// "SELECT y.Id AS 'Id', y.Name AS 'Name', a.City AS 'Address.City', a.State AS 'Address.State', (a.City+', '+a.State) AS 'Address.Description', " + | ||
// "ROW_NUMBER() OVER (ORDER BY (a.City+', '+a.State) ASC) AS Position " + | ||
// "FROM Yards y JOIN Addresses a ON y.address_id = a.Id " + | ||
// "WHERE y.IsActive = 1" + | ||
// ") " + | ||
// "SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 900 AND Position <= 1000 "); | ||
// done(); | ||
// }); | ||
// | ||
// it('it is called with no page', function(done){ | ||
// var req = { | ||
// query: { | ||
// sidx: "Address.Description", | ||
// sord: "ASC", | ||
// rows: 100, | ||
// filters: 'IsActive=true' | ||
// } | ||
// }; | ||
// | ||
// (sqlBuilder() | ||
// .select({"y.Id" : "Id", "y.Name": "Name", "a.City": "Address.City", "a.State": "Address.State", "(a.City+', '+a.State)" : "Address.Description"}) | ||
// .from("Yards y") | ||
// .join("Addresses a", "y.address_id", "a.Id") | ||
// .processListRequest(req.query) | ||
// .build()) | ||
// .should.equal("WITH SelectedItems AS (SELECT y.Id AS 'Id', y.Name AS 'Name', a.City AS 'Address.City', a.State AS 'Address.State', " + | ||
// "(a.City+', '+a.State) AS 'Address.Description', ROW_NUMBER() OVER (ORDER BY (a.City+', '+a.State) ASC) AS Position FROM Yards y " + | ||
// "JOIN Addresses a ON y.address_id = a.Id WHERE y.IsActive = 1) SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 0 AND Position <= 100 "); | ||
// done(); | ||
// }); | ||
// | ||
// it('it is called with no orderby or order direction', function(done){ | ||
// var req = { | ||
// query: { | ||
// rows: 100, | ||
// page: 10, | ||
// filters: 'IsActive=true' | ||
// } | ||
// }; | ||
// | ||
// (sqlBuilder() | ||
// .select({"y.Id" : "Id", "y.Name": "Name", "a.City": "Address.City", "a.State": "Address.State", "(a.City+', '+a.State)" : "Address.Description"}) | ||
// .from("Yards y") | ||
// .join("Addresses a", "y.address_id", "a.Id") | ||
// .processListRequest(req.query) | ||
// .build()) | ||
// .should.equal("WITH SelectedItems AS (" + | ||
// "SELECT y.Id AS 'Id', y.Name AS 'Name', a.City AS 'Address.City', a.State AS 'Address.State', (a.City+', '+a.State) AS 'Address.Description', " + | ||
// "ROW_NUMBER() OVER (ORDER BY y.Created) AS Position " + | ||
// "FROM Yards y JOIN Addresses a ON y.address_id = a.Id " + | ||
// "WHERE y.IsActive = 1" + | ||
// ") " + | ||
// "SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 900 AND Position <= 1000 "); | ||
// done(); | ||
// }); | ||
// | ||
// it('it is called with no rows', function(done){ | ||
// var req = { | ||
// query: { | ||
// page: 10, | ||
// filters: 'IsActive=true' | ||
// } | ||
// }; | ||
// | ||
// (sqlBuilder() | ||
// .select({"y.Id" : "Id", "y.Name": "Name", "a.City": "Address.City", "a.State": "Address.State", "(a.City+', '+a.State)" : "Address.Description"}) | ||
// .from("Yards y") | ||
// .join("Addresses a", "y.address_id", "a.Id") | ||
// .processListRequest(req.query) | ||
// .build()) | ||
// .should.equal("WITH SelectedItems AS (" + | ||
// "SELECT y.Id AS 'Id', y.Name AS 'Name', a.City AS 'Address.City', a.State AS 'Address.State', (a.City+', '+a.State) AS 'Address.Description', " + | ||
// "ROW_NUMBER() OVER (ORDER BY y.Created) AS Position " + | ||
// "FROM Yards y JOIN Addresses a ON y.address_id = a.Id " + | ||
// "WHERE y.IsActive = 1" + | ||
// ") " + | ||
// "SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 900 AND Position <= 1000 "); | ||
// done(); | ||
// }); | ||
// | ||
// it('it is called with rows of -1', function(done){ | ||
// var req = { | ||
// query: { | ||
// page: 10, | ||
// rows: -1, | ||
// filters: 'IsActive=true' | ||
// } | ||
// }; | ||
// | ||
// (sqlBuilder() | ||
// .select({"y.Id" : "Id", "y.Name": "Name", "a.City": "Address.City", "a.State": "Address.State", "(a.City+', '+a.State)" : "Address.Description"}) | ||
// .from("Yards y") | ||
// .join("Addresses a", "y.address_id", "a.Id") | ||
// .processListRequest(req.query) | ||
// .build()) | ||
// .should.equal("WITH SelectedItems AS (" + | ||
// "SELECT y.Id AS 'Id', y.Name AS 'Name', a.City AS 'Address.City', a.State AS 'Address.State', (a.City+', '+a.State) AS 'Address.Description', " + | ||
// "ROW_NUMBER() OVER (ORDER BY y.Created) AS Position " + | ||
// "FROM Yards y JOIN Addresses a ON y.address_id = a.Id " + | ||
// "WHERE y.IsActive = 1" + | ||
// ") " + | ||
// "SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 0 "); | ||
// done(); | ||
// }); | ||
// | ||
// it('it is called with only filters in req.query', function(done){ | ||
// var req = { | ||
// query: { | ||
// filters: 'IsActive=true' | ||
// } | ||
// }; | ||
// | ||
// (sqlBuilder() | ||
// .select({"y.Id" : "Id", "y.Name": "Name", "a.City": "Address.City", "a.State": "Address.State", "(a.City+', '+a.State)" : "Address.Description"}) | ||
// .from("Yards y") | ||
// .join("Addresses a", "y.address_id", "a.Id") | ||
// .processListRequest(req.query) | ||
// .build()) | ||
// .should.equal("WITH SelectedItems AS (" + | ||
// "SELECT y.Id AS 'Id', y.Name AS 'Name', a.City AS 'Address.City', a.State AS 'Address.State', (a.City+', '+a.State) AS 'Address.Description', " + | ||
// "ROW_NUMBER() OVER (ORDER BY y.Created) AS Position " + | ||
// "FROM Yards y JOIN Addresses a ON y.address_id = a.Id " + | ||
// "WHERE y.IsActive = 1" + | ||
// ") " + | ||
// "SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 0 AND Position <= 100 "); | ||
// done(); | ||
// }); | ||
// | ||
// it('it is called with .Contains', function(done){ | ||
// var req = { | ||
// query: { | ||
// sidx: "Address.Description", | ||
// sord: "ASC", | ||
// rows: 100, | ||
// page: 10, | ||
// filters: 'IsActive=true&&Name.Contains("Greg")' | ||
// } | ||
// }; | ||
// | ||
// (sqlBuilder() | ||
// .select({"y.Id" : "Id", "y.Name": "Name", "a.City": "Address.City", "a.State": "Address.State", "(a.City+', '+a.State)" : "Address.Description"}) | ||
// .from("Yards y") | ||
// .join("Addresses a", "y.address_id", "a.Id") | ||
// .processListRequest(req.query) | ||
// .build()) | ||
// .should.equal("WITH SelectedItems AS (" + | ||
// "SELECT y.Id AS 'Id', y.Name AS 'Name', a.City AS 'Address.City', a.State AS 'Address.State', (a.City+', '+a.State) AS 'Address.Description', " + | ||
// "ROW_NUMBER() OVER (ORDER BY (a.City+', '+a.State) ASC) AS Position " + | ||
// "FROM Yards y JOIN Addresses a ON y.address_id = a.Id " + | ||
// "WHERE y.IsActive = 1 AND y.Name LIKE '%Greg%'" + | ||
// ") " + | ||
// "SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 900 AND Position <= 1000 "); | ||
// done(); | ||
// }); | ||
// | ||
// it('it is called only with .Contains', function(done){ | ||
// var req = { | ||
// query: { | ||
// sidx: "Address.Description", | ||
// sord: "ASC", | ||
// rows: 100, | ||
// page: 10, | ||
// filters: 'Name.Contains("Greg")' | ||
// } | ||
// }; | ||
// | ||
// (sqlBuilder() | ||
// .select({"y.Id" : "Id", "y.Name": "Name", "a.City": "Address.City", "a.State": "Address.State", "(a.City+', '+a.State)" : "Address.Description"}) | ||
// .from("Yards y") | ||
// .join("Addresses a", "y.address_id", "a.Id") | ||
// .processListRequest(req.query) | ||
// .build()) | ||
// .should.equal("WITH SelectedItems AS (" + | ||
// "SELECT y.Id AS 'Id', y.Name AS 'Name', a.City AS 'Address.City', a.State AS 'Address.State', (a.City+', '+a.State) AS 'Address.Description', " + | ||
// "ROW_NUMBER() OVER (ORDER BY (a.City+', '+a.State) ASC) AS Position " + | ||
// "FROM Yards y JOIN Addresses a ON y.address_id = a.Id " + | ||
// "WHERE y.Name LIKE '%Greg%'" + | ||
// ") " + | ||
// "SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 900 AND Position <= 1000 "); | ||
// done(); | ||
// }); | ||
// | ||
// it('it is called with .Equals', function(done){ | ||
// var req = { | ||
// query: { | ||
// sidx: "Address.Description", | ||
// sord: "ASC", | ||
// rows: 100, | ||
// page: 10, | ||
// filters: 'IsActive=true&&Name.Equals("Greg")' | ||
// } | ||
// }; | ||
// | ||
// (sqlBuilder() | ||
// .select({"y.Id" : "Id", "y.Name": "Name", "a.City": "Address.City", "a.State": "Address.State", "(a.City+', '+a.State)" : "Address.Description"}) | ||
// .from("Yards y") | ||
// .join("Addresses a", "y.address_id", "a.Id") | ||
// .processListRequest(req.query) | ||
// .build()) | ||
// .should.equal("WITH SelectedItems AS (" + | ||
// "SELECT y.Id AS 'Id', y.Name AS 'Name', a.City AS 'Address.City', a.State AS 'Address.State', (a.City+', '+a.State) AS 'Address.Description', " + | ||
// "ROW_NUMBER() OVER (ORDER BY (a.City+', '+a.State) ASC) AS Position " + | ||
// "FROM Yards y JOIN Addresses a ON y.address_id = a.Id " + | ||
// "WHERE y.IsActive = 1 AND y.Name = 'Greg'" + | ||
// ") " + | ||
// "SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 900 AND Position <= 1000 "); | ||
// done(); | ||
// }); | ||
// | ||
// | ||
// | ||
// it('it is called with .StartsWith', function(done){ | ||
// var req = { | ||
// query: { | ||
// sidx: "Address.Description", | ||
// sord: "ASC", | ||
// rows: 100, | ||
// page: 10, | ||
// filters: 'IsActive=true&&Name.StartsWith("Greg")' | ||
// } | ||
// }; | ||
// | ||
// (sqlBuilder() | ||
// .select({"y.Id" : "Id", "y.Name": "Name", "a.City": "Address.City", "a.State": "Address.State", "(a.City+', '+a.State)" : "Address.Description"}) | ||
// .from("Yards y") | ||
// .join("Addresses a", "y.address_id", "a.Id") | ||
// .processListRequest(req.query) | ||
// .build()) | ||
// .should.equal("WITH SelectedItems AS (" + | ||
// "SELECT y.Id AS 'Id', y.Name AS 'Name', a.City AS 'Address.City', a.State AS 'Address.State', (a.City+', '+a.State) AS 'Address.Description', " + | ||
// "ROW_NUMBER() OVER (ORDER BY (a.City+', '+a.State) ASC) AS Position " + | ||
// "FROM Yards y JOIN Addresses a ON y.address_id = a.Id " + | ||
// "WHERE y.IsActive = 1 AND y.Name LIKE 'Greg%'" + | ||
// ") " + | ||
// "SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 900 AND Position <= 1000 "); | ||
// done(); | ||
// }); | ||
// | ||
// it('it is called with .EndsWith', function(done){ | ||
// var req = { | ||
// query: { | ||
// sidx: "Address.Description", | ||
// sord: "ASC", | ||
// rows: 100, | ||
// page: 10, | ||
// filters: 'Name.EndsWith("Greg")&&IsActive=true' | ||
// } | ||
// }; | ||
// | ||
// (sqlBuilder() | ||
// .select({"y.Id" : "Id", "y.Name": "Name", "a.City": "Address.City", "a.State": "Address.State", "(a.City+', '+a.State)" : "Address.Description"}) | ||
// .from("Yards y") | ||
// .join("Addresses a", "y.address_id", "a.Id") | ||
// .processListRequest(req.query) | ||
// .build()) | ||
// .should.equal("WITH SelectedItems AS (" + | ||
// "SELECT y.Id AS 'Id', y.Name AS 'Name', a.City AS 'Address.City', a.State AS 'Address.State', (a.City+', '+a.State) AS 'Address.Description', " + | ||
// "ROW_NUMBER() OVER (ORDER BY (a.City+', '+a.State) ASC) AS Position " + | ||
// "FROM Yards y JOIN Addresses a ON y.address_id = a.Id " + | ||
// "WHERE y.Name LIKE '%Greg' AND y.IsActive = 1" + | ||
// ") " + | ||
// "SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 900 AND Position <= 1000 "); | ||
// done(); | ||
// }); | ||
// | ||
// it('it is called with a DATE filter', function(done){ | ||
// var req = { | ||
// query: { | ||
// sidx: "Address.Description", | ||
// sord: "ASC", | ||
// rows: 100, | ||
// page: 10, | ||
// filters: 'InvoiceDate>=08-18-2014&&InvoiceDate<08-19-2014&&IsActive=true' | ||
// } | ||
// }; | ||
// | ||
// (sqlBuilder() | ||
// .select({"y.Id" : "Id", "y.Name": "Name", "a.City": "Address.City", "a.State": "Address.State", "(a.City+', '+a.State)" : "Address.Description", "y.InvoiceDate" : "InvoiceDate"}) | ||
// .from("Yards y") | ||
// .join("Addresses a", "y.address_id", "a.Id") | ||
// .processListRequest(req.query) | ||
// .build()) | ||
// .should.equal("WITH SelectedItems AS (" + | ||
// "SELECT y.Id AS 'Id', y.Name AS 'Name', a.City AS 'Address.City', a.State AS 'Address.State', (a.City+', '+a.State) AS 'Address.Description', y.InvoiceDate AS 'InvoiceDate', " + | ||
// "ROW_NUMBER() OVER (ORDER BY (a.City+', '+a.State) ASC) AS Position " + | ||
// "FROM Yards y JOIN Addresses a ON y.address_id = a.Id " + | ||
// "WHERE y.InvoiceDate >= '08-18-2014' AND y.InvoiceDate < '08-19-2014' AND y.IsActive = 1" + | ||
// ") " + | ||
// "SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 900 AND Position <= 1000 "); | ||
// done(); | ||
// }); | ||
// | ||
// it('it is called with a DROPDOWN filter', function(done){ | ||
// var req = { | ||
// query: { | ||
// sidx: "Address.Description", | ||
// sord: "ASC", | ||
// rows: 100, | ||
// page: 10, | ||
// filters: '(Status.Value==3)&&IsActive=true' | ||
// } | ||
// }; | ||
// | ||
// (sqlBuilder() | ||
// .select({"y.Id" : "Id", "y.Name": "Name", "a.City": "Address.City", "a.State": "Address.State", "(a.City+', '+a.State)" : "Address.Description", "y.StatusValue" : "Status.Value"}) | ||
// .from("Yards y") | ||
// .join("Addresses a", "y.address_id", "a.Id") | ||
// .processListRequest(req.query) | ||
// .build()) | ||
// .should.equal("WITH SelectedItems AS (" + | ||
// "SELECT y.Id AS 'Id', y.Name AS 'Name', a.City AS 'Address.City', a.State AS 'Address.State', (a.City+', '+a.State) AS 'Address.Description', y.StatusValue AS 'Status.Value', " + | ||
// "ROW_NUMBER() OVER (ORDER BY (a.City+', '+a.State) ASC) AS Position " + | ||
// "FROM Yards y JOIN Addresses a ON y.address_id = a.Id " + | ||
// "WHERE (y.StatusValue = 3) AND y.IsActive = 1" + | ||
// ") " + | ||
// "SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 900 AND Position <= 1000 "); | ||
// done(); | ||
// }); | ||
// | ||
// it('it is called with a YES filter', function(done){ | ||
// var req = { | ||
// query: { | ||
// sidx: "Address.Description", | ||
// sord: "ASC", | ||
// rows: 100, | ||
// page: 10, | ||
// filters: 'IsActive=true&&IsTurnedIn' | ||
// } | ||
// }; | ||
// | ||
// (sqlBuilder() | ||
// .select({"y.Id" : "Id", "y.Name": "Name", "a.City": "Address.City", "a.State": "Address.State", "(a.City+', '+a.State)" : "Address.Description", "y.IsTurnedIn" : "IsTurnedIn"}) | ||
// .from("Yards y") | ||
// .join("Addresses a", "y.address_id", "a.Id") | ||
// .processListRequest(req.query) | ||
// .build()) | ||
// .should.equal("WITH SelectedItems AS (" + | ||
// "SELECT y.Id AS 'Id', y.Name AS 'Name', a.City AS 'Address.City', a.State AS 'Address.State', (a.City+', '+a.State) AS 'Address.Description', y.IsTurnedIn AS 'IsTurnedIn', " + | ||
// "ROW_NUMBER() OVER (ORDER BY (a.City+', '+a.State) ASC) AS Position " + | ||
// "FROM Yards y JOIN Addresses a ON y.address_id = a.Id " + | ||
// "WHERE y.IsActive = 1 AND y.IsTurnedIn = 1" + | ||
// ") " + | ||
// "SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 900 AND Position <= 1000 "); | ||
// done(); | ||
// }); | ||
// | ||
// it('it is called with a NO filter', function(done){ | ||
// var req = { | ||
// query: { | ||
// sidx: "Address.Description", | ||
// sord: "ASC", | ||
// rows: 100, | ||
// page: 10, | ||
// filters: 'IsActive=true&&!IsTurnedIn' | ||
// } | ||
// }; | ||
// | ||
// (sqlBuilder() | ||
// .select({"y.Id" : "Id", "y.Name": "Name", "a.City": "Address.City", "a.State": "Address.State", "(a.City+', '+a.State)" : "Address.Description", "y.IsTurnedIn" : "IsTurnedIn"}) | ||
// .from("Yards y") | ||
// .join("Addresses a", "y.address_id", "a.Id") | ||
// .processListRequest(req.query) | ||
// .build()) | ||
// .should.equal("WITH SelectedItems AS (" + | ||
// "SELECT y.Id AS 'Id', y.Name AS 'Name', a.City AS 'Address.City', a.State AS 'Address.State', (a.City+', '+a.State) AS 'Address.Description', y.IsTurnedIn AS 'IsTurnedIn', " + | ||
// "ROW_NUMBER() OVER (ORDER BY (a.City+', '+a.State) ASC) AS Position " + | ||
// "FROM Yards y JOIN Addresses a ON y.address_id = a.Id " + | ||
// "WHERE y.IsActive = 1 AND y.IsTurnedIn = 0" + | ||
// ") " + | ||
// "SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 900 AND Position <= 1000 "); | ||
// done(); | ||
// }); | ||
// | ||
// it('it is called with STRING notation in SELECT clause', function(done){ | ||
// var req = { | ||
// query: { | ||
// rows: 100, | ||
// page: 10, | ||
// filters: 'IsActive=true&&DaysBeforeTicketAged.Contains("7")' | ||
// } | ||
// }; | ||
// | ||
// (sqlBuilder() | ||
// .select("Id, Name, DaysBeforeTicketAged, LeaseRequired") | ||
// .from("Phases") | ||
// .processListRequest(req.query) | ||
// .build()) | ||
// .should.equal("WITH SelectedItems AS (" + | ||
// "SELECT Id, Name, DaysBeforeTicketAged, LeaseRequired, " + | ||
// "ROW_NUMBER() OVER (ORDER BY Phases.Created) AS Position " + | ||
// "FROM Phases " + | ||
// "WHERE Phases.IsActive = 1 AND Phases.DaysBeforeTicketAged LIKE '%7%'" + | ||
// ") " + | ||
// "SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 900 AND Position <= 1000 "); | ||
// done(); | ||
// }); | ||
// | ||
// it('lots of filters are passed in', function(done){ | ||
// var req = { | ||
// query: { | ||
// rows: 100, | ||
// page: undefined, | ||
// filters: 'IsActive=true', | ||
// sidx:'Name', | ||
// sord:'ASC' | ||
// } | ||
// }; | ||
// | ||
// (sqlBuilder() | ||
// .select("Id, Name, DaysBeforeTicketAged, LeaseRequired") | ||
// .from("Phases") | ||
// .processListRequest(req.query) | ||
// .build()) | ||
// .should.equal("WITH SelectedItems AS (" + | ||
// "SELECT Id, Name, DaysBeforeTicketAged, LeaseRequired, " + | ||
// "ROW_NUMBER() OVER (ORDER BY Phases.Name ASC) AS Position " + | ||
// "FROM Phases " + | ||
// "WHERE Phases.IsActive = 1" + | ||
// ") " + | ||
// "SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 0 AND Position <= 100 "); | ||
// done(); | ||
// }); | ||
// | ||
// it('it is called with IsActive in beginning', function(done){ | ||
// var req = { | ||
// query: { | ||
// rows: 100, | ||
// page: 10, | ||
// filters: 'IsActive=true&&DaysBeforeTicketAged.Contains("7")' | ||
// } | ||
// }; | ||
// | ||
// (sqlBuilder() | ||
// .select("Id, Name, DaysBeforeTicketAged, LeaseRequired") | ||
// .from("Phases") | ||
// .processListRequest(req.query) | ||
// .build()) | ||
// .should.equal("WITH SelectedItems AS (" + | ||
// "SELECT Id, Name, DaysBeforeTicketAged, LeaseRequired, " + | ||
// "ROW_NUMBER() OVER (ORDER BY Phases.Created) AS Position " + | ||
// "FROM Phases " + | ||
// "WHERE Phases.IsActive = 1 AND Phases.DaysBeforeTicketAged LIKE '%7%'" + | ||
// ") " + | ||
// "SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 900 AND Position <= 1000 "); | ||
// done(); | ||
// }); | ||
// | ||
// it('it is called with filters with an alias that includes a tablename', function(done){ | ||
// var req = { | ||
// query: { | ||
// rows: 100, | ||
// page: 1, | ||
// filters: 'Yard.Name.Contains("athen")' | ||
// } | ||
// }; | ||
// | ||
// (sqlBuilder() | ||
// .select("al.Id, al.Name, al.Code, y.Name as [Yard.Name]") | ||
// .from("AccountLocations al") | ||
// .leftJoin("Yards y") | ||
// .processListRequest(req.query) | ||
// .build()) | ||
// .should.equal("WITH SelectedItems AS (SELECT al.Id, al.Name, al.Code, y.Name as [Yard.Name], ROW_NUMBER() OVER (ORDER BY al.Created) AS Position FROM AccountLocations al " + | ||
// "LEFT JOIN Yards y ON al.Yard_id = y.Id WHERE Yards.Name LIKE '%athen%') SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' " + | ||
// "FROM SelectedItems WHERE Position > 0 AND Position <= 100 "); | ||
// done(); | ||
// }); | ||
// | ||
// it('Should filter by yard name properly', function (done) { | ||
// var reqquery ={ filters: 'Yard.Name.Contains("Okla")&&IsActive=true', | ||
// sidx: 'AcquiredDate', | ||
// sord: 'desc', | ||
// RenderFormat: 'paged', | ||
// page: '1', | ||
// pagePercent: '0.3333333333333333', | ||
// total: '238', | ||
// rows: '100', | ||
// totalPages: '3' }; | ||
// | ||
// var query = sqlBuilder() | ||
// .select({"f.Id" : null,"AssetNumber":null,"ShortDescription":null,"glc.Name":"GLCategory.Name","ac.Number":"AccountCode", | ||
// "oc.Name":"OperationalCategory.Name","f.InitialCost":null,"f.AcquiredDate":null,"y.Name":"Yard.Name", | ||
// "dep.Name":"Department.Name", "f.FixedAssetTypeDisplayName":"FixedAssetType.DisplayName","f.VIN":null, | ||
// "po.Number":"PONumber"}) | ||
// .from("FixedAssets f") | ||
// .join("AccountingProcessTypes glc", "glc.Id", "f.GLCategory_id") | ||
// .join("AccountCodes ac","ac.Id","glc.AccountCode_id") | ||
// .join("EquipmentTypes oc", "oc.Id", "f.OperationalCategory_id") | ||
// .join("Yards y") | ||
// .join("Departments dep") | ||
// .leftJoin("Receivers r") | ||
// .leftJoin("PurchaseOrders po", "po.Id", "r.PurchaseOrder_id") | ||
// .processListRequest(reqquery) | ||
// .build(); | ||
// | ||
// query.should | ||
// .equal("WITH SelectedItems AS (SELECT f.Id, AssetNumber, ShortDescription, glc.Name AS 'GLCategory.Name', ac.Number AS 'AccountCode', oc.Name AS 'OperationalCategory.Name', f.InitialCost, f.AcquiredDate, y.Name AS 'Yard.Name', dep.Name AS 'Department.Name', f.FixedAssetTypeDisplayName AS 'FixedAssetType.DisplayName', f.VIN, po.Number AS 'PONumber', ROW_NUMBER() OVER (ORDER BY f.AcquiredDate DESC) AS Position FROM FixedAssets f JOIN AccountingProcessTypes glc ON glc.Id = f.GLCategory_id JOIN AccountCodes ac ON ac.Id = glc.AccountCode_id JOIN EquipmentTypes oc ON oc.Id = f.OperationalCategory_id JOIN Yards y ON f.Yard_id = y.Id JOIN Departments dep ON f.Department_id = dep.Id LEFT JOIN Receivers r ON f.Receiver_id = r.Id LEFT JOIN PurchaseOrders po ON po.Id = r.PurchaseOrder_id WHERE y.Name LIKE '%Okla%' AND f.IsActive = 1) SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 0 AND Position <= 100 ") | ||
// | ||
// | ||
// done(); | ||
// }); | ||
// | ||
// it('Should filter by enumeration displayname properly', function (done) { | ||
// var reqquery ={ filters: '(AcquiredSource.DisplayName.Equals("Purchased"))&&IsActive=true', | ||
// sidx: 'AcquiredSource', | ||
// sord: 'desc', | ||
// RenderFormat: 'paged', | ||
// page: '1', | ||
// pagePercent: '0.3333333333333333', | ||
// total: '238', | ||
// rows: '100', | ||
// totalPages: '3' }; | ||
// | ||
// var query = sqlBuilder() | ||
// .select({"f.Id" : null,"AssetNumber":null,"ShortDescription":null,"glc.Name":"GLCategory.Name","ac.Number":"AccountCode", | ||
// "oc.Name":"OperationalCategory.Name","f.InitialCost":null,"f.AcquiredDate":null,"y.Name":"Yard.Name", | ||
// "dep.Name":"Department.Name", "f.FixedAssetTypeDisplayName":"FixedAssetType.DisplayName","f.VIN":null, | ||
// "po.Number":"PONumber"}) | ||
// .from("FixedAssets f") | ||
// .join("AccountingProcessTypes glc", "glc.Id", "f.GLCategory_id") | ||
// .join("AccountCodes ac","ac.Id","glc.AccountCode_id") | ||
// .join("EquipmentTypes oc", "oc.Id", "f.OperationalCategory_id") | ||
// .join("Yards y") | ||
// .join("Departments dep") | ||
// .leftJoin("Receivers r") | ||
// .leftJoin("PurchaseOrders po", "po.Id", "r.PurchaseOrder_id") | ||
// .processListRequest(reqquery) | ||
// .build(); | ||
// | ||
// query.should | ||
// .equal("WITH SelectedItems AS (SELECT f.Id, AssetNumber, ShortDescription, glc.Name AS 'GLCategory.Name', ac.Number AS 'AccountCode', oc.Name AS 'OperationalCategory.Name', f.InitialCost, f.AcquiredDate, y.Name AS 'Yard.Name', dep.Name AS 'Department.Name', f.FixedAssetTypeDisplayName AS 'FixedAssetType.DisplayName', f.VIN, po.Number AS 'PONumber', ROW_NUMBER() OVER (ORDER BY f.AcquiredSource DESC) AS Position FROM FixedAssets f JOIN AccountingProcessTypes glc ON glc.Id = f.GLCategory_id JOIN AccountCodes ac ON ac.Id = glc.AccountCode_id JOIN EquipmentTypes oc ON oc.Id = f.OperationalCategory_id JOIN Yards y ON f.Yard_id = y.Id JOIN Departments dep ON f.Department_id = dep.Id LEFT JOIN Receivers r ON f.Receiver_id = r.Id LEFT JOIN PurchaseOrders po ON po.Id = r.PurchaseOrder_id WHERE (f.AcquiredSourceDisplayName = 'Purchased') AND f.IsActive = 1) SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 0 AND Position <= 100 ") | ||
// | ||
// | ||
// done(); | ||
// }); | ||
// | ||
// it('Should filter by contains properly', function (done) { | ||
// var reqquery ={ filters: 'InvoiceCustomerName.Contains("EOG Re")&&IsActive=true', | ||
// sidx: 'InvoiceNumber', | ||
// sord: 'asc', | ||
// RenderFormat: 'paged', | ||
// page: '1', | ||
// pagePercent: '0.3333333333333333', | ||
// total: '205', | ||
// rows: '100', | ||
// totalPages: '3' }; | ||
// | ||
// var req = { query: reqquery }; | ||
// | ||
// var query = sqlBuilder().from('InvoiceSalesTaxInfoView') | ||
// .select({ | ||
// Id: null, | ||
// Created: null, | ||
// LastModified: null, | ||
// IsActive: null, | ||
// ModifiedBy: null, | ||
// 'TotalTax':null, | ||
// 'Total':null, | ||
// 'TaxableTotal':null, | ||
// 'NonTaxableTotal':null, | ||
// TaxRate:null, | ||
// InvoiceNumber:null, | ||
// InvoiceCustomerName:null, | ||
// InvoiceYard:null, | ||
// InvoiceDate:null, | ||
// InvoiceStateDisplayName:'InvoiceState.DisplayName', | ||
// InvoiceStateValue:'InvoiceState.Value', | ||
// StatusDisplayName:'Status.DisplayName', | ||
// StatusValue:'Status.Value', | ||
// InvoiceIsProcessed:null, | ||
// SalesTaxZoneState:null, | ||
// SalesTaxZoneName:null | ||
// }) | ||
// | ||
// .processListRequest(req) | ||
// .build(); | ||
// | ||
// query.should | ||
// .equal("WITH SelectedItems AS (SELECT Id, Created, LastModified, IsActive, ModifiedBy, TotalTax, Total, TaxableTotal, NonTaxableTotal, TaxRate, InvoiceNumber, InvoiceCustomerName, InvoiceYard, InvoiceDate, InvoiceStateDisplayName AS 'InvoiceState.DisplayName', InvoiceStateValue AS 'InvoiceState.Value', StatusDisplayName AS 'Status.DisplayName', StatusValue AS 'Status.Value', InvoiceIsProcessed, SalesTaxZoneState, SalesTaxZoneName, ROW_NUMBER() OVER (ORDER BY InvoiceNumber ASC) AS Position FROM InvoiceSalesTaxInfoView WHERE InvoiceCustomerName LIKE '%EOG Re%' AND InvoiceSalesTaxInfoView.IsActive = 1) SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 0 AND Position <= 100 ") | ||
// | ||
// | ||
// done(); | ||
// | ||
// }); | ||
// | ||
// it('Should give the propery query for a view', function (done) { | ||
// var reqquery ={ filters: 'IsActive=true&&TerritoryId=null', | ||
// sidx: 'Created', | ||
// sord: 'asc', | ||
// RenderFormat: 'paged', | ||
// page: '', | ||
// pagePercent: '0', | ||
// total: '', | ||
// rows: '100', | ||
// totalPages: '' }; | ||
// | ||
// var query = sqlBuilder() | ||
// .from('MaintenanceAssignmentView') | ||
// .select({ | ||
// 'Status': null, | ||
// 'Description': 'Description', | ||
// 'CreatorFirstName': 'CreatorFirstName', | ||
// 'TerritoryId': 'TerritoryId', | ||
// 'ServiceTicketId': 'ServiceTicketId', | ||
// 'ServiceTicketNumber': 'ServiceTicketNumber', | ||
// 'YardId': 'YardId', | ||
// 'Yard': 'Yard', | ||
// 'Equipment': 'Equipment', | ||
// 'JobInstructions': 'JobInstructions', | ||
// 'Categories': 'Categories', | ||
// 'Created': 'Created', | ||
// 'Id': 'Id', | ||
// "(CreatorFirstName + ' ' + CreatorLastName)": 'CreatorName', | ||
// "(CASE WHEN Status = 'Rejected' Then 1 else 1 END)": 'IsRejected' | ||
// }) | ||
// .where({Status: 'Complete'}) | ||
// .processListRequest(reqquery) | ||
// .build(); | ||
// | ||
// query.should | ||
// .equal("WITH SelectedItems AS (SELECT Status, Description AS 'Description', CreatorFirstName AS 'CreatorFirstName', TerritoryId AS 'TerritoryId', ServiceTicketId AS 'ServiceTicketId', ServiceTicketNumber AS 'ServiceTicketNumber', YardId AS 'YardId', Yard AS 'Yard', Equipment AS 'Equipment', JobInstructions AS 'JobInstructions', Categories AS 'Categories', Created AS 'Created', Id AS 'Id', (CreatorFirstName + ' ' + CreatorLastName) AS 'CreatorName', (CASE WHEN Status = 'Rejected' Then 1 else 1 END) AS 'IsRejected', ROW_NUMBER() OVER (ORDER BY Created ASC) AS Position FROM MaintenanceAssignmentView WHERE MaintenanceAssignmentView.Status = 'Complete' AND MaintenanceAssignmentView.IsActive = 1 AND (TerritoryId IS null)) SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 0 AND Position <= 100 ") | ||
// | ||
// | ||
// done(); | ||
// }); | ||
// it('Should give the propery query for a view with guid and single equals', function (done) { | ||
// var reqquery ={ filters: 'IsActive=true&&TerritoryId=A1139D28-CE9E-4EF9-A595-A31401026A65', | ||
// sidx: 'Created', | ||
// sord: 'desc', | ||
// RenderFormat: 'paged', | ||
// page: '1', | ||
// pagePercent: 'Infinity', | ||
// total: '0', | ||
// rows: '100', | ||
// totalPages: '0' }; | ||
// | ||
// var query = sqlBuilder() | ||
// .from('MaintenanceAssignmentView') | ||
// .select({ | ||
// 'Status': null, | ||
// 'Description': 'Description', | ||
// 'CreatorFirstName': 'CreatorFirstName', | ||
// 'TerritoryId': 'TerritoryId', | ||
// 'ServiceTicketId': 'ServiceTicketId', | ||
// 'ServiceTicketNumber': 'ServiceTicketNumber', | ||
// 'YardId': 'YardId', | ||
// 'Yard': 'Yard', | ||
// 'Equipment': 'Equipment', | ||
// 'JobInstructions': 'JobInstructions', | ||
// 'Categories': 'Categories', | ||
// 'Created': 'Created', | ||
// 'Id': 'Id', | ||
// "(CreatorFirstName + ' ' + CreatorLastName)": 'CreatorName', | ||
// "(CASE WHEN Status = 'Rejected' Then 1 else 1 END)": 'IsRejected' | ||
// }) | ||
// .where({Status: 'Complete'}) | ||
// .processListRequest(reqquery) | ||
// .build(); | ||
// | ||
// query.should | ||
// .equal("WITH SelectedItems AS (SELECT Status, Description AS 'Description', CreatorFirstName AS 'CreatorFirstName', TerritoryId AS 'TerritoryId', ServiceTicketId AS 'ServiceTicketId', ServiceTicketNumber AS 'ServiceTicketNumber', YardId AS 'YardId', Yard AS 'Yard', Equipment AS 'Equipment', JobInstructions AS 'JobInstructions', Categories AS 'Categories', Created AS 'Created', Id AS 'Id', (CreatorFirstName + ' ' + CreatorLastName) AS 'CreatorName', (CASE WHEN Status = 'Rejected' Then 1 else 1 END) AS 'IsRejected', ROW_NUMBER() OVER (ORDER BY Created DESC) AS Position FROM MaintenanceAssignmentView WHERE MaintenanceAssignmentView.Status = 'Complete' AND MaintenanceAssignmentView.IsActive = 1 AND (TerritoryId = 'A1139D28-CE9E-4EF9-A595-A31401026A65')) SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 0 AND Position <= 100 ") | ||
// | ||
// | ||
// done(); | ||
// }); | ||
// | ||
// it('Should give the replace false with 0', function (done) { | ||
// var reqquery ={ filters: 'IsActive=true&&(Status.Value==3)&&(IsApproved==false)', | ||
// sidx: 'OperationalCategoryName', | ||
// sord: 'asc', | ||
// RenderFormat: 'paged', | ||
// page: '1', | ||
// pagePercent: 'Infinity', | ||
// total: '0', | ||
// rows: '100', | ||
// totalPages: '0' }; | ||
// | ||
// var query = sqlBuilder() | ||
// .from('ServiceTicketView') | ||
// .select({ OperationalCategoryName: 'OperationalCategoryName', | ||
// 'count(OperationalCategoryName)': 'Count' }) | ||
// .groupBy('OperationalCategoryName') | ||
// .processListRequest(reqquery) | ||
// .build(); | ||
// | ||
// query.should | ||
// .equal("WITH SelectedItems AS (SELECT OperationalCategoryName AS 'OperationalCategoryName', count(OperationalCategoryName) AS 'Count', ROW_NUMBER() OVER (ORDER BY OperationalCategoryName ASC) AS Position FROM ServiceTicketView WHERE ServiceTicketView.IsActive = 1 AND (ServiceTicketView.StatusValue = 3) AND (ServiceTicketView.IsApproved = 0) GROUP BY OperationalCategoryName) SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 0 AND Position <= 100 "); | ||
// | ||
// | ||
// done(); | ||
// }); | ||
// | ||
// it('should work for tickets with additional filters from monthly closing page', function(done){ | ||
// var reqquery = { | ||
// filters: 'IsActive=true&&&&Created>2014-10-15T10:29:38.000Z&&Date<=2014-06-30T00:00:00.000Z&&StatusValue!=3&&StatusValue!=4&&StatusValue!=5', | ||
// sidx: 'Number', | ||
// sord: 'asc', | ||
// RenderFormat: 'paged', | ||
// page: '', | ||
// pagePercent: '0', | ||
// total: '', | ||
// rows: '100', | ||
// totalPages: '' }; | ||
// | ||
// var query = sqlBuilder().from("Tickets").selectJoin({ | ||
// 'Tickets.Id': 'Id', | ||
// 'Tickets.Total': 'Total', | ||
// 'Tickets.IsTurnedIn': 'IsTurnedIn', | ||
// 'Tickets.IsSigned': 'IsSigned', | ||
// 'Tickets.Date': 'Date', | ||
// 'CustomerShipTos.CustomerName': 'CustomerShipTo.CustomerName', | ||
// 'Leases.Name': 'Lease.Name', | ||
// 'Phases.Name': 'Phase.Name', | ||
// 'Yards.Name': 'Yard.Name' | ||
// }).processListRequest(reqquery).build(); | ||
// | ||
// query.should.equal( | ||
// "WITH SelectedItems AS (SELECT Tickets.Id AS 'Id', Tickets.Total AS 'Total', Tickets.IsTurnedIn AS 'IsTurnedIn', Tickets.IsSigned AS 'IsSigned', Tickets.Date AS 'Date', CustomerShipTos.CustomerName AS 'CustomerShipTo.CustomerName', " | ||
// +"Leases.Name AS 'Lease.Name', Phases.Name AS 'Phase.Name', Yards.Name AS 'Yard.Name', ROW_NUMBER() OVER (ORDER BY Tickets.Number ASC) AS Position FROM Tickets LEFT JOIN CustomerShipTos ON Tickets.CustomerShipTo_id = CustomerShipTos.Id LEFT JOIN Leases ON Tickets.Lease_id = Leases.Id LEFT JOIN Phases ON Tickets.Phase_id = Phases.Id LEFT JOIN " | ||
// +"Yards ON Tickets.Yard_id = Yards.Id WHERE Tickets.IsActive = 1 AND Tickets.Created > '2014-10-15T10:29:38.000Z' AND Tickets.Date <= '2014-06-30T00:00:00.000Z' " | ||
// +"AND (Tickets.StatusValue != 3) AND (Tickets.StatusValue != 4) AND (Tickets.StatusValue != 5)) SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 0 AND Position <= 100 " | ||
// ); | ||
// done(); | ||
// }); | ||
// | ||
// it('Should filter on the nested enumeration', function (done) { | ||
// var selection = { | ||
// 'fa.Id': 'Id', | ||
// 'fa.Created': 'Created', | ||
// 'fa.LastModified': 'LastModified', | ||
// 'fa.IsActive': 'IsActive', | ||
// 'fa.ModifiedBy': 'ModifiedBy', | ||
// 'fa.ShortDescription': 'ShortDescription', | ||
// 'fa.LongDescription': 'LongDescription', | ||
// 'fa.VIN': 'VIN', | ||
// 'RentalType = NULL': null, | ||
// 'rst.Id': 'CurrentRentalStatus.Id', | ||
// 'rst.Created': 'CurrentRentalStatus.Created', | ||
// 'rst.LastModified': 'CurrentRentalStatus.LastModified', | ||
// 'rst.IsActive': 'CurrentRentalStatus.IsActive', | ||
// 'rst.ModifiedBy': 'CurrentRentalStatus.ModifiedBy', | ||
// 'rst.RentalStatusValue': 'CurrentRentalStatus.RentalStatus.Value', | ||
// 'rst.RentalStatusDisplayName': 'CurrentRentalStatus.RentalStatus.DisplayName', | ||
// "'CurrentRentalStatus.DisplayTime' = NULL": null, | ||
// 'rst.Time': 'CurrentRentalStatus.Time', | ||
// "'CurrentRentalStatus.TimeParts' = NULL": null, | ||
// 'rst.Notes': 'CurrentRentalStatus.Notes', | ||
// 'rst.TicketNumber': 'CurrentRentalStatus.TicketNumber', | ||
// "'CurrentRentalStatus.TicketId' = NULL": null, | ||
// 'rst.Phase': 'CurrentRentalStatus.Phase', | ||
// 'l.Name': 'CurrentRentalStatus.Lease', | ||
// "'CurrentRentalStatus.PhaseType' = NULL": null, | ||
// 'l.Id': 'CurrentRentalStatus.LeaseId', | ||
// 'RevenueAccount = NULL': null, | ||
// 'ExpenseAccount = NULL': null, | ||
// 'AssetAccount = NULL': null, | ||
// 'UseParentsAccounts = 0': null, | ||
// 'Vendor = NULL': null, | ||
// 'Uom = NULL': null, | ||
// 'Quantity = 0' : null | ||
// }; | ||
// | ||
// var reqquery ={ filters: '(CurrentRentalStatus.RentalStatus.Value==1)', | ||
// RenderFormat: 'paged', | ||
// page: '1', | ||
// rows: '100'}; | ||
// | ||
// var query = sqlBuilder() | ||
// .select(selection) | ||
// .from('FixedAssets fa') | ||
// .join('RentalStatusTracks rst', 'fa.CurrentRentalStatus_id', 'rst.Id') | ||
// .leftJoin('Leases l ON rst.Lease_id = l.Id') | ||
// .where('(NOT fa.RentalSelectionValue = 1)') | ||
// .processListRequest(reqquery) | ||
// .build(); | ||
// | ||
// query.should | ||
// .equal("WITH SelectedItems AS (SELECT fa.Id AS 'Id', fa.Created AS 'Created', fa.LastModified AS 'LastModified', fa.IsActive AS 'IsActive', fa.ModifiedBy AS 'ModifiedBy', fa.ShortDescription AS 'ShortDescription', fa.LongDescription AS 'LongDescription', fa.VIN AS 'VIN', RentalType = NULL, rst.Id AS 'CurrentRentalStatus.Id', rst.Created AS 'CurrentRentalStatus.Created', rst.LastModified AS 'CurrentRentalStatus.LastModified', rst.IsActive AS 'CurrentRentalStatus.IsActive', rst.ModifiedBy AS 'CurrentRentalStatus.ModifiedBy', rst.RentalStatusValue AS 'CurrentRentalStatus.RentalStatus.Value', rst.RentalStatusDisplayName AS 'CurrentRentalStatus.RentalStatus.DisplayName', 'CurrentRentalStatus.DisplayTime' = NULL, rst.Time AS 'CurrentRentalStatus.Time', 'CurrentRentalStatus.TimeParts' = NULL, rst.Notes AS 'CurrentRentalStatus.Notes', rst.TicketNumber AS 'CurrentRentalStatus.TicketNumber', 'CurrentRentalStatus.TicketId' = NULL, rst.Phase AS 'CurrentRentalStatus.Phase', l.Name AS 'CurrentRentalStatus.Lease', 'CurrentRentalStatus.PhaseType' = NULL, l.Id AS 'CurrentRentalStatus.LeaseId', RevenueAccount = NULL, ExpenseAccount = NULL, AssetAccount = NULL, UseParentsAccounts = 0, Vendor = NULL, Uom = NULL, Quantity = 0, ROW_NUMBER() OVER (ORDER BY fa.Created) AS Position FROM FixedAssets fa JOIN RentalStatusTracks rst ON fa.CurrentRentalStatus_id = rst.Id LEFT JOIN Leases l ON rst.Lease_id = l.Id WHERE (NOT fa.RentalSelectionValue = 1) AND (rst.RentalStatusValue = 1)) SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 0 AND Position <= 100 "); | ||
// | ||
// done(); | ||
// }); | ||
// | ||
// it('Should handle multiple aliases to the same field', function (done) { | ||
// var selection = { | ||
// 'fa.Id': 'Id', | ||
// 'fa.Created': 'Created', | ||
// 'fa.LastModified': 'LastModified', | ||
// 'fa.IsActive': 'IsActive', | ||
// 'fa.ModifiedBy': 'ModifiedBy', | ||
// 'fa.ShortDescription': 'ShortDescription', | ||
// 'fa.LongDescription': 'LongDescription', | ||
// 'fa.VIN': 'VIN', | ||
// 'RentalType = NULL': null, | ||
// 'rst.Id': 'CurrentRentalStatus.Id', | ||
// 'rst.Created': 'CurrentRentalStatus.Created', | ||
// 'rst.LastModified': 'CurrentRentalStatus.LastModified', | ||
// 'rst.IsActive': 'CurrentRentalStatus.IsActive', | ||
// 'rst.ModifiedBy': 'CurrentRentalStatus.ModifiedBy', | ||
// 'rst.RentalStatusValue': 'CurrentRentalStatus.RentalStatus.Value, RentalStatusValue', | ||
// 'rst.RentalStatusDisplayName': 'CurrentRentalStatus.RentalStatus.DisplayName, RentalStatusDisplayName', | ||
// "'CurrentRentalStatus.DisplayTime' = NULL": null, | ||
// 'rst.Time': 'CurrentRentalStatus.Time', | ||
// "'CurrentRentalStatus.TimeParts' = NULL": null, | ||
// 'rst.Notes': 'CurrentRentalStatus.Notes', | ||
// 'rst.TicketNumber': 'CurrentRentalStatus.TicketNumber', | ||
// "'CurrentRentalStatus.TicketId' = NULL": null, | ||
// 'rst.Phase': 'CurrentRentalStatus.Phase', | ||
// 'l.Name': 'CurrentRentalStatus.Lease', | ||
// "'CurrentRentalStatus.PhaseType' = NULL": null, | ||
// 'l.Id': 'CurrentRentalStatus.LeaseId', | ||
// 'RevenueAccount = NULL': null, | ||
// 'ExpenseAccount = NULL': null, | ||
// 'AssetAccount = NULL': null, | ||
// 'UseParentsAccounts = 0': null, | ||
// 'Vendor = NULL': null, | ||
// 'Uom = NULL': null, | ||
// 'Quantity = 0' : null | ||
// }; | ||
// | ||
// var reqquery ={ filters: '(RentalStatusValue==1)', | ||
// RenderFormat: 'paged', | ||
// page: '1', | ||
// rows: '100'}; | ||
// | ||
// var query = sqlBuilder() | ||
// .select(selection) | ||
// .from('FixedAssets fa') | ||
// .join('RentalStatusTracks rst', 'fa.CurrentRentalStatus_id', 'rst.Id') | ||
// .leftJoin('Leases l ON rst.Lease_id = l.Id') | ||
// .where('(NOT fa.RentalSelectionValue = 1)') | ||
// .processListRequest(reqquery) | ||
// .build(); | ||
// | ||
// query.should | ||
// .equal("WITH SelectedItems AS (SELECT fa.Id AS 'Id', fa.Created AS 'Created', fa.LastModified AS 'LastModified', fa.IsActive AS 'IsActive', fa.ModifiedBy AS 'ModifiedBy', fa.ShortDescription AS 'ShortDescription', fa.LongDescription AS 'LongDescription', fa.VIN AS 'VIN', RentalType = NULL, rst.Id AS 'CurrentRentalStatus.Id', rst.Created AS 'CurrentRentalStatus.Created', rst.LastModified AS 'CurrentRentalStatus.LastModified', rst.IsActive AS 'CurrentRentalStatus.IsActive', rst.ModifiedBy AS 'CurrentRentalStatus.ModifiedBy', rst.RentalStatusValue AS 'CurrentRentalStatus.RentalStatus.Value', rst.RentalStatusValue AS 'RentalStatusValue', rst.RentalStatusDisplayName AS 'CurrentRentalStatus.RentalStatus.DisplayName', rst.RentalStatusDisplayName AS 'RentalStatusDisplayName', 'CurrentRentalStatus.DisplayTime' = NULL, rst.Time AS 'CurrentRentalStatus.Time', 'CurrentRentalStatus.TimeParts' = NULL, rst.Notes AS 'CurrentRentalStatus.Notes', rst.TicketNumber AS 'CurrentRentalStatus.TicketNumber', 'CurrentRentalStatus.TicketId' = NULL, rst.Phase AS 'CurrentRentalStatus.Phase', l.Name AS 'CurrentRentalStatus.Lease', 'CurrentRentalStatus.PhaseType' = NULL, l.Id AS 'CurrentRentalStatus.LeaseId', RevenueAccount = NULL, ExpenseAccount = NULL, AssetAccount = NULL, UseParentsAccounts = 0, Vendor = NULL, Uom = NULL, Quantity = 0, ROW_NUMBER() OVER (ORDER BY fa.Created) AS Position FROM FixedAssets fa JOIN RentalStatusTracks rst ON fa.CurrentRentalStatus_id = rst.Id LEFT JOIN Leases l ON rst.Lease_id = l.Id WHERE (NOT fa.RentalSelectionValue = 1) AND (rst.RentalStatusValue = 1)) SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 0 AND Position <= 100 "); | ||
// | ||
// done(); | ||
// }); | ||
// | ||
// it('Should filter on the nested enumeration', function (done) { | ||
// var selection = { | ||
// 'fa.Id': 'Id', | ||
// 'fa.Created': 'Created', | ||
// 'fa.LastModified': 'LastModified', | ||
// 'fa.IsActive': 'IsActive', | ||
// 'fa.ModifiedBy': 'ModifiedBy', | ||
// 'fa.ShortDescription': 'ShortDescription', | ||
// 'fa.LongDescription': 'LongDescription', | ||
// 'fa.VIN': 'VIN', | ||
// 'RentalType = NULL': null, | ||
// 'rst.Id': 'CurrentRentalStatus.Id', | ||
// 'rst.Created': 'CurrentRentalStatus.Created', | ||
// 'rst.LastModified': 'CurrentRentalStatus.LastModified', | ||
// 'rst.IsActive': 'CurrentRentalStatus.IsActive', | ||
// 'rst.ModifiedBy': 'CurrentRentalStatus.ModifiedBy', | ||
// 'rst.RentalStatusValue': 'CurrentRentalStatus.RentalStatus.Value', | ||
// 'rst.RentalStatusDisplayName': 'CurrentRentalStatus.RentalStatus.DisplayName', | ||
// "'CurrentRentalStatus.DisplayTime' = NULL": null, | ||
// 'rst.Time': 'CurrentRentalStatus.Time', | ||
// "'CurrentRentalStatus.TimeParts' = NULL": null, | ||
// 'rst.Notes': 'CurrentRentalStatus.Notes', | ||
// 'rst.TicketNumber': 'CurrentRentalStatus.TicketNumber', | ||
// "'CurrentRentalStatus.TicketId' = NULL": null, | ||
// 'rst.Phase': 'CurrentRentalStatus.Phase', | ||
// 'l.Name': 'CurrentRentalStatus.Lease', | ||
// "'CurrentRentalStatus.PhaseType' = NULL": null, | ||
// 'l.Id': 'CurrentRentalStatus.LeaseId', | ||
// 'RevenueAccount = NULL': null, | ||
// 'ExpenseAccount = NULL': null, | ||
// 'AssetAccount = NULL': null, | ||
// 'UseParentsAccounts = 0': null, | ||
// 'Vendor = NULL': null, | ||
// 'Uom = NULL': null, | ||
// 'Quantity = 0' : null | ||
// }; | ||
// | ||
// var reqquery ={ filters: '(CurrentRentalStatus.RentalStatus.Value==1)', | ||
// RenderFormat: 'paged', | ||
// page: '1', | ||
// rows: '100'}; | ||
// | ||
// var query = sqlBuilder() | ||
// .select(selection) | ||
// .from('FixedAssets fa') | ||
// .join('RentalStatusTracks rst', 'fa.CurrentRentalStatus_id', 'rst.Id') | ||
// .leftJoin('Leases l ON rst.Lease_id = l.Id') | ||
// .where('(NOT fa.RentalSelectionValue = 1)') | ||
// .processListRequest(reqquery) | ||
// .build(); | ||
// | ||
// query.should | ||
// .equal("WITH SelectedItems AS (SELECT fa.Id AS 'Id', fa.Created AS 'Created', fa.LastModified AS 'LastModified', fa.IsActive AS 'IsActive', fa.ModifiedBy AS 'ModifiedBy', fa.ShortDescription AS 'ShortDescription', fa.LongDescription AS 'LongDescription', fa.VIN AS 'VIN', RentalType = NULL, rst.Id AS 'CurrentRentalStatus.Id', rst.Created AS 'CurrentRentalStatus.Created', rst.LastModified AS 'CurrentRentalStatus.LastModified', rst.IsActive AS 'CurrentRentalStatus.IsActive', rst.ModifiedBy AS 'CurrentRentalStatus.ModifiedBy', rst.RentalStatusValue AS 'CurrentRentalStatus.RentalStatus.Value', rst.RentalStatusDisplayName AS 'CurrentRentalStatus.RentalStatus.DisplayName', 'CurrentRentalStatus.DisplayTime' = NULL, rst.Time AS 'CurrentRentalStatus.Time', 'CurrentRentalStatus.TimeParts' = NULL, rst.Notes AS 'CurrentRentalStatus.Notes', rst.TicketNumber AS 'CurrentRentalStatus.TicketNumber', 'CurrentRentalStatus.TicketId' = NULL, rst.Phase AS 'CurrentRentalStatus.Phase', l.Name AS 'CurrentRentalStatus.Lease', 'CurrentRentalStatus.PhaseType' = NULL, l.Id AS 'CurrentRentalStatus.LeaseId', RevenueAccount = NULL, ExpenseAccount = NULL, AssetAccount = NULL, UseParentsAccounts = 0, Vendor = NULL, Uom = NULL, Quantity = 0, ROW_NUMBER() OVER (ORDER BY fa.Created) AS Position FROM FixedAssets fa JOIN RentalStatusTracks rst ON fa.CurrentRentalStatus_id = rst.Id LEFT JOIN Leases l ON rst.Lease_id = l.Id WHERE (NOT fa.RentalSelectionValue = 1) AND (rst.RentalStatusValue = 1)) SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 0 AND Position <= 100 "); | ||
// | ||
// done(); | ||
// }); | ||
(sqlBuilder() | ||
.select({"y.Id" : "Id", "y.Name": "Name", "a.City": "Address.City", "a.State": "Address.State", "(a.City+', '+a.State)" : "Address.Description"}) | ||
.from("Yards y") | ||
.join("Addresses a", "y.address_id", "a.Id") | ||
.processListRequest(req.query) | ||
.build()) | ||
.should.equal("WITH SelectedItems AS (" + | ||
"SELECT y.Id AS 'Id', y.Name AS 'Name', a.City AS 'Address.City', a.State AS 'Address.State', (a.City+', '+a.State) AS 'Address.Description', " + | ||
"ROW_NUMBER() OVER (ORDER BY (a.City+', '+a.State) ASC) AS Position " + | ||
"FROM Yards y JOIN Addresses a ON y.address_id = a.Id " + | ||
"WHERE y.IsActive = 1" + | ||
") " + | ||
"SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 900 AND Position <= 1000 "); | ||
done(); | ||
}); | ||
it('it is called with no page', function(done){ | ||
var req = { | ||
query: { | ||
sidx: "Address.Description", | ||
sord: "ASC", | ||
rows: 100, | ||
filters: 'IsActive=true' | ||
} | ||
}; | ||
(sqlBuilder() | ||
.select({"y.Id" : "Id", "y.Name": "Name", "a.City": "Address.City", "a.State": "Address.State", "(a.City+', '+a.State)" : "Address.Description"}) | ||
.from("Yards y") | ||
.join("Addresses a", "y.address_id", "a.Id") | ||
.processListRequest(req.query) | ||
.build()) | ||
.should.equal("WITH SelectedItems AS (SELECT y.Id AS 'Id', y.Name AS 'Name', a.City AS 'Address.City', a.State AS 'Address.State', " + | ||
"(a.City+', '+a.State) AS 'Address.Description', ROW_NUMBER() OVER (ORDER BY (a.City+', '+a.State) ASC) AS Position FROM Yards y " + | ||
"JOIN Addresses a ON y.address_id = a.Id WHERE y.IsActive = 1) SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 0 AND Position <= 100 "); | ||
done(); | ||
}); | ||
it('it is called with no orderby or order direction', function(done){ | ||
var req = { | ||
query: { | ||
rows: 100, | ||
page: 10, | ||
filters: 'IsActive=true' | ||
} | ||
}; | ||
(sqlBuilder() | ||
.select({"y.Id" : "Id", "y.Name": "Name", "a.City": "Address.City", "a.State": "Address.State", "(a.City+', '+a.State)" : "Address.Description"}) | ||
.from("Yards y") | ||
.join("Addresses a", "y.address_id", "a.Id") | ||
.processListRequest(req.query) | ||
.build()) | ||
.should.equal("WITH SelectedItems AS (" + | ||
"SELECT y.Id AS 'Id', y.Name AS 'Name', a.City AS 'Address.City', a.State AS 'Address.State', (a.City+', '+a.State) AS 'Address.Description', " + | ||
"ROW_NUMBER() OVER (ORDER BY y.Created) AS Position " + | ||
"FROM Yards y JOIN Addresses a ON y.address_id = a.Id " + | ||
"WHERE y.IsActive = 1" + | ||
") " + | ||
"SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 900 AND Position <= 1000 "); | ||
done(); | ||
}); | ||
it('it is called with no rows', function(done){ | ||
var req = { | ||
query: { | ||
page: 10, | ||
filters: 'IsActive=true' | ||
} | ||
}; | ||
(sqlBuilder() | ||
.select({"y.Id" : "Id", "y.Name": "Name", "a.City": "Address.City", "a.State": "Address.State", "(a.City+', '+a.State)" : "Address.Description"}) | ||
.from("Yards y") | ||
.join("Addresses a", "y.address_id", "a.Id") | ||
.processListRequest(req.query) | ||
.build()) | ||
.should.equal("WITH SelectedItems AS (" + | ||
"SELECT y.Id AS 'Id', y.Name AS 'Name', a.City AS 'Address.City', a.State AS 'Address.State', (a.City+', '+a.State) AS 'Address.Description', " + | ||
"ROW_NUMBER() OVER (ORDER BY y.Created) AS Position " + | ||
"FROM Yards y JOIN Addresses a ON y.address_id = a.Id " + | ||
"WHERE y.IsActive = 1" + | ||
") " + | ||
"SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 900 AND Position <= 1000 "); | ||
done(); | ||
}); | ||
it('it is called with rows of -1', function(done){ | ||
var req = { | ||
query: { | ||
page: 10, | ||
rows: -1, | ||
filters: 'IsActive=true' | ||
} | ||
}; | ||
(sqlBuilder() | ||
.select({"y.Id" : "Id", "y.Name": "Name", "a.City": "Address.City", "a.State": "Address.State", "(a.City+', '+a.State)" : "Address.Description"}) | ||
.from("Yards y") | ||
.join("Addresses a", "y.address_id", "a.Id") | ||
.processListRequest(req.query) | ||
.build()) | ||
.should.equal("WITH SelectedItems AS (" + | ||
"SELECT y.Id AS 'Id', y.Name AS 'Name', a.City AS 'Address.City', a.State AS 'Address.State', (a.City+', '+a.State) AS 'Address.Description', " + | ||
"ROW_NUMBER() OVER (ORDER BY y.Created) AS Position " + | ||
"FROM Yards y JOIN Addresses a ON y.address_id = a.Id " + | ||
"WHERE y.IsActive = 1" + | ||
") " + | ||
"SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 0 "); | ||
done(); | ||
}); | ||
it('it is called with only filters in req.query', function(done){ | ||
var req = { | ||
query: { | ||
filters: 'IsActive=true' | ||
} | ||
}; | ||
(sqlBuilder() | ||
.select({"y.Id" : "Id", "y.Name": "Name", "a.City": "Address.City", "a.State": "Address.State", "(a.City+', '+a.State)" : "Address.Description"}) | ||
.from("Yards y") | ||
.join("Addresses a", "y.address_id", "a.Id") | ||
.processListRequest(req.query) | ||
.build()) | ||
.should.equal("WITH SelectedItems AS (" + | ||
"SELECT y.Id AS 'Id', y.Name AS 'Name', a.City AS 'Address.City', a.State AS 'Address.State', (a.City+', '+a.State) AS 'Address.Description', " + | ||
"ROW_NUMBER() OVER (ORDER BY y.Created) AS Position " + | ||
"FROM Yards y JOIN Addresses a ON y.address_id = a.Id " + | ||
"WHERE y.IsActive = 1" + | ||
") " + | ||
"SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 0 AND Position <= 100 "); | ||
done(); | ||
}); | ||
it('it is called with .Contains', function(done){ | ||
var req = { | ||
query: { | ||
sidx: "Address.Description", | ||
sord: "ASC", | ||
rows: 100, | ||
page: 10, | ||
filters: 'IsActive=true&&Name.Contains("Greg")' | ||
} | ||
}; | ||
(sqlBuilder() | ||
.select({"y.Id" : "Id", "y.Name": "Name", "a.City": "Address.City", "a.State": "Address.State", "(a.City+', '+a.State)" : "Address.Description"}) | ||
.from("Yards y") | ||
.join("Addresses a", "y.address_id", "a.Id") | ||
.processListRequest(req.query) | ||
.build()) | ||
.should.equal("WITH SelectedItems AS (" + | ||
"SELECT y.Id AS 'Id', y.Name AS 'Name', a.City AS 'Address.City', a.State AS 'Address.State', (a.City+', '+a.State) AS 'Address.Description', " + | ||
"ROW_NUMBER() OVER (ORDER BY (a.City+', '+a.State) ASC) AS Position " + | ||
"FROM Yards y JOIN Addresses a ON y.address_id = a.Id " + | ||
"WHERE y.IsActive = 1 AND y.Name LIKE '%Greg%'" + | ||
") " + | ||
"SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 900 AND Position <= 1000 "); | ||
done(); | ||
}); | ||
it('it is called only with .Contains', function(done){ | ||
var req = { | ||
query: { | ||
sidx: "Address.Description", | ||
sord: "ASC", | ||
rows: 100, | ||
page: 10, | ||
filters: 'Name.Contains("Greg")' | ||
} | ||
}; | ||
(sqlBuilder() | ||
.select({"y.Id" : "Id", "y.Name": "Name", "a.City": "Address.City", "a.State": "Address.State", "(a.City+', '+a.State)" : "Address.Description"}) | ||
.from("Yards y") | ||
.join("Addresses a", "y.address_id", "a.Id") | ||
.processListRequest(req.query) | ||
.build()) | ||
.should.equal("WITH SelectedItems AS (" + | ||
"SELECT y.Id AS 'Id', y.Name AS 'Name', a.City AS 'Address.City', a.State AS 'Address.State', (a.City+', '+a.State) AS 'Address.Description', " + | ||
"ROW_NUMBER() OVER (ORDER BY (a.City+', '+a.State) ASC) AS Position " + | ||
"FROM Yards y JOIN Addresses a ON y.address_id = a.Id " + | ||
"WHERE y.Name LIKE '%Greg%'" + | ||
") " + | ||
"SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 900 AND Position <= 1000 "); | ||
done(); | ||
}); | ||
it('it is called with .Equals', function(done){ | ||
var req = { | ||
query: { | ||
sidx: "Address.Description", | ||
sord: "ASC", | ||
rows: 100, | ||
page: 10, | ||
filters: 'IsActive=true&&Name.Equals("Greg")' | ||
} | ||
}; | ||
(sqlBuilder() | ||
.select({"y.Id" : "Id", "y.Name": "Name", "a.City": "Address.City", "a.State": "Address.State", "(a.City+', '+a.State)" : "Address.Description"}) | ||
.from("Yards y") | ||
.join("Addresses a", "y.address_id", "a.Id") | ||
.processListRequest(req.query) | ||
.build()) | ||
.should.equal("WITH SelectedItems AS (" + | ||
"SELECT y.Id AS 'Id', y.Name AS 'Name', a.City AS 'Address.City', a.State AS 'Address.State', (a.City+', '+a.State) AS 'Address.Description', " + | ||
"ROW_NUMBER() OVER (ORDER BY (a.City+', '+a.State) ASC) AS Position " + | ||
"FROM Yards y JOIN Addresses a ON y.address_id = a.Id " + | ||
"WHERE y.IsActive = 1 AND y.Name = 'Greg'" + | ||
") " + | ||
"SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 900 AND Position <= 1000 "); | ||
done(); | ||
}); | ||
it('it is called with .StartsWith', function(done){ | ||
var req = { | ||
query: { | ||
sidx: "Address.Description", | ||
sord: "ASC", | ||
rows: 100, | ||
page: 10, | ||
filters: 'IsActive=true&&Name.StartsWith("Greg")' | ||
} | ||
}; | ||
(sqlBuilder() | ||
.select({"y.Id" : "Id", "y.Name": "Name", "a.City": "Address.City", "a.State": "Address.State", "(a.City+', '+a.State)" : "Address.Description"}) | ||
.from("Yards y") | ||
.join("Addresses a", "y.address_id", "a.Id") | ||
.processListRequest(req.query) | ||
.build()) | ||
.should.equal("WITH SelectedItems AS (" + | ||
"SELECT y.Id AS 'Id', y.Name AS 'Name', a.City AS 'Address.City', a.State AS 'Address.State', (a.City+', '+a.State) AS 'Address.Description', " + | ||
"ROW_NUMBER() OVER (ORDER BY (a.City+', '+a.State) ASC) AS Position " + | ||
"FROM Yards y JOIN Addresses a ON y.address_id = a.Id " + | ||
"WHERE y.IsActive = 1 AND y.Name LIKE 'Greg%'" + | ||
") " + | ||
"SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 900 AND Position <= 1000 "); | ||
done(); | ||
}); | ||
it('it is called with .EndsWith', function(done){ | ||
var req = { | ||
query: { | ||
sidx: "Address.Description", | ||
sord: "ASC", | ||
rows: 100, | ||
page: 10, | ||
filters: 'Name.EndsWith("Greg")&&IsActive=true' | ||
} | ||
}; | ||
(sqlBuilder() | ||
.select({"y.Id" : "Id", "y.Name": "Name", "a.City": "Address.City", "a.State": "Address.State", "(a.City+', '+a.State)" : "Address.Description"}) | ||
.from("Yards y") | ||
.join("Addresses a", "y.address_id", "a.Id") | ||
.processListRequest(req.query) | ||
.build()) | ||
.should.equal("WITH SelectedItems AS (" + | ||
"SELECT y.Id AS 'Id', y.Name AS 'Name', a.City AS 'Address.City', a.State AS 'Address.State', (a.City+', '+a.State) AS 'Address.Description', " + | ||
"ROW_NUMBER() OVER (ORDER BY (a.City+', '+a.State) ASC) AS Position " + | ||
"FROM Yards y JOIN Addresses a ON y.address_id = a.Id " + | ||
"WHERE y.Name LIKE '%Greg' AND y.IsActive = 1" + | ||
") " + | ||
"SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 900 AND Position <= 1000 "); | ||
done(); | ||
}); | ||
it('it is called with a DATE filter', function(done){ | ||
var req = { | ||
query: { | ||
sidx: "Address.Description", | ||
sord: "ASC", | ||
rows: 100, | ||
page: 10, | ||
filters: 'InvoiceDate>=08-18-2014&&InvoiceDate<08-19-2014&&IsActive=true' | ||
} | ||
}; | ||
(sqlBuilder() | ||
.select({"y.Id" : "Id", "y.Name": "Name", "a.City": "Address.City", "a.State": "Address.State", "(a.City+', '+a.State)" : "Address.Description", "y.InvoiceDate" : "InvoiceDate"}) | ||
.from("Yards y") | ||
.join("Addresses a", "y.address_id", "a.Id") | ||
.processListRequest(req.query) | ||
.build()) | ||
.should.equal("WITH SelectedItems AS (" + | ||
"SELECT y.Id AS 'Id', y.Name AS 'Name', a.City AS 'Address.City', a.State AS 'Address.State', (a.City+', '+a.State) AS 'Address.Description', y.InvoiceDate AS 'InvoiceDate', " + | ||
"ROW_NUMBER() OVER (ORDER BY (a.City+', '+a.State) ASC) AS Position " + | ||
"FROM Yards y JOIN Addresses a ON y.address_id = a.Id " + | ||
"WHERE y.InvoiceDate >= '08-18-2014' AND y.InvoiceDate < '08-19-2014' AND y.IsActive = 1" + | ||
") " + | ||
"SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 900 AND Position <= 1000 "); | ||
done(); | ||
}); | ||
it('it is called with a DROPDOWN filter', function(done){ | ||
var req = { | ||
query: { | ||
sidx: "Address.Description", | ||
sord: "ASC", | ||
rows: 100, | ||
page: 10, | ||
filters: '(Status.Value==3)&&IsActive=true' | ||
} | ||
}; | ||
(sqlBuilder() | ||
.select({"y.Id" : "Id", "y.Name": "Name", "a.City": "Address.City", "a.State": "Address.State", "(a.City+', '+a.State)" : "Address.Description", "y.StatusValue" : "Status.Value"}) | ||
.from("Yards y") | ||
.join("Addresses a", "y.address_id", "a.Id") | ||
.processListRequest(req.query) | ||
.build()) | ||
.should.equal("WITH SelectedItems AS (" + | ||
"SELECT y.Id AS 'Id', y.Name AS 'Name', a.City AS 'Address.City', a.State AS 'Address.State', (a.City+', '+a.State) AS 'Address.Description', y.StatusValue AS 'Status.Value', " + | ||
"ROW_NUMBER() OVER (ORDER BY (a.City+', '+a.State) ASC) AS Position " + | ||
"FROM Yards y JOIN Addresses a ON y.address_id = a.Id " + | ||
"WHERE (y.StatusValue = 3) AND y.IsActive = 1" + | ||
") " + | ||
"SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 900 AND Position <= 1000 "); | ||
done(); | ||
}); | ||
it('it is called with a YES filter', function(done){ | ||
var req = { | ||
query: { | ||
sidx: "Address.Description", | ||
sord: "ASC", | ||
rows: 100, | ||
page: 10, | ||
filters: 'IsActive=true&&IsTurnedIn' | ||
} | ||
}; | ||
(sqlBuilder() | ||
.select({"y.Id" : "Id", "y.Name": "Name", "a.City": "Address.City", "a.State": "Address.State", "(a.City+', '+a.State)" : "Address.Description", "y.IsTurnedIn" : "IsTurnedIn"}) | ||
.from("Yards y") | ||
.join("Addresses a", "y.address_id", "a.Id") | ||
.processListRequest(req.query) | ||
.build()) | ||
.should.equal("WITH SelectedItems AS (" + | ||
"SELECT y.Id AS 'Id', y.Name AS 'Name', a.City AS 'Address.City', a.State AS 'Address.State', (a.City+', '+a.State) AS 'Address.Description', y.IsTurnedIn AS 'IsTurnedIn', " + | ||
"ROW_NUMBER() OVER (ORDER BY (a.City+', '+a.State) ASC) AS Position " + | ||
"FROM Yards y JOIN Addresses a ON y.address_id = a.Id " + | ||
"WHERE y.IsActive = 1 AND y.IsTurnedIn = 1" + | ||
") " + | ||
"SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 900 AND Position <= 1000 "); | ||
done(); | ||
}); | ||
it('it is called with a NO filter', function(done){ | ||
var req = { | ||
query: { | ||
sidx: "Address.Description", | ||
sord: "ASC", | ||
rows: 100, | ||
page: 10, | ||
filters: 'IsActive=true&&!IsTurnedIn' | ||
} | ||
}; | ||
(sqlBuilder() | ||
.select({"y.Id" : "Id", "y.Name": "Name", "a.City": "Address.City", "a.State": "Address.State", "(a.City+', '+a.State)" : "Address.Description", "y.IsTurnedIn" : "IsTurnedIn"}) | ||
.from("Yards y") | ||
.join("Addresses a", "y.address_id", "a.Id") | ||
.processListRequest(req.query) | ||
.build()) | ||
.should.equal("WITH SelectedItems AS (" + | ||
"SELECT y.Id AS 'Id', y.Name AS 'Name', a.City AS 'Address.City', a.State AS 'Address.State', (a.City+', '+a.State) AS 'Address.Description', y.IsTurnedIn AS 'IsTurnedIn', " + | ||
"ROW_NUMBER() OVER (ORDER BY (a.City+', '+a.State) ASC) AS Position " + | ||
"FROM Yards y JOIN Addresses a ON y.address_id = a.Id " + | ||
"WHERE y.IsActive = 1 AND y.IsTurnedIn = 0" + | ||
") " + | ||
"SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 900 AND Position <= 1000 "); | ||
done(); | ||
}); | ||
it('it is called with STRING notation in SELECT clause', function(done){ | ||
var req = { | ||
query: { | ||
rows: 100, | ||
page: 10, | ||
filters: 'IsActive=true&&DaysBeforeTicketAged.Contains("7")' | ||
} | ||
}; | ||
(sqlBuilder() | ||
.select("Id, Name, DaysBeforeTicketAged, LeaseRequired") | ||
.from("Phases") | ||
.processListRequest(req.query) | ||
.build()) | ||
.should.equal("WITH SelectedItems AS (" + | ||
"SELECT Id, Name, DaysBeforeTicketAged, LeaseRequired, " + | ||
"ROW_NUMBER() OVER (ORDER BY Phases.Created) AS Position " + | ||
"FROM Phases " + | ||
"WHERE Phases.IsActive = 1 AND Phases.DaysBeforeTicketAged LIKE '%7%'" + | ||
") " + | ||
"SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 900 AND Position <= 1000 "); | ||
done(); | ||
}); | ||
it('lots of filters are passed in', function(done){ | ||
var req = { | ||
query: { | ||
rows: 100, | ||
page: undefined, | ||
filters: 'IsActive=true', | ||
sidx:'Name', | ||
sord:'ASC' | ||
} | ||
}; | ||
(sqlBuilder() | ||
.select("Id, Name, DaysBeforeTicketAged, LeaseRequired") | ||
.from("Phases") | ||
.processListRequest(req.query) | ||
.build()) | ||
.should.equal("WITH SelectedItems AS (" + | ||
"SELECT Id, Name, DaysBeforeTicketAged, LeaseRequired, " + | ||
"ROW_NUMBER() OVER (ORDER BY Phases.Name ASC) AS Position " + | ||
"FROM Phases " + | ||
"WHERE Phases.IsActive = 1" + | ||
") " + | ||
"SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 0 AND Position <= 100 "); | ||
done(); | ||
}); | ||
it('it is called with IsActive in beginning', function(done){ | ||
var req = { | ||
query: { | ||
rows: 100, | ||
page: 10, | ||
filters: 'IsActive=true&&DaysBeforeTicketAged.Contains("7")' | ||
} | ||
}; | ||
(sqlBuilder() | ||
.select("Id, Name, DaysBeforeTicketAged, LeaseRequired") | ||
.from("Phases") | ||
.processListRequest(req.query) | ||
.build()) | ||
.should.equal("WITH SelectedItems AS (" + | ||
"SELECT Id, Name, DaysBeforeTicketAged, LeaseRequired, " + | ||
"ROW_NUMBER() OVER (ORDER BY Phases.Created) AS Position " + | ||
"FROM Phases " + | ||
"WHERE Phases.IsActive = 1 AND Phases.DaysBeforeTicketAged LIKE '%7%'" + | ||
") " + | ||
"SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 900 AND Position <= 1000 "); | ||
done(); | ||
}); | ||
it('it is called with filters with an alias that includes a tablename', function(done){ | ||
var req = { | ||
query: { | ||
rows: 100, | ||
page: 1, | ||
filters: 'Yard.Name.Contains("athen")' | ||
} | ||
}; | ||
(sqlBuilder() | ||
.select("al.Id, al.Name, al.Code, y.Name as [Yard.Name]") | ||
.from("AccountLocations al") | ||
.leftJoin("Yards y") | ||
.processListRequest(req.query) | ||
.build()) | ||
.should.equal("WITH SelectedItems AS (SELECT al.Id, al.Name, al.Code, y.Name as [Yard.Name], ROW_NUMBER() OVER (ORDER BY al.Created) AS Position FROM AccountLocations al " + | ||
"LEFT JOIN Yards y ON al.Yard_id = y.Id WHERE Yards.Name LIKE '%athen%') SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' " + | ||
"FROM SelectedItems WHERE Position > 0 AND Position <= 100 "); | ||
done(); | ||
}); | ||
it('Should filter by yard name properly', function (done) { | ||
var reqquery ={ filters: 'Yard.Name.Contains("Okla")&&IsActive=true', | ||
sidx: 'AcquiredDate', | ||
sord: 'desc', | ||
RenderFormat: 'paged', | ||
page: '1', | ||
pagePercent: '0.3333333333333333', | ||
total: '238', | ||
rows: '100', | ||
totalPages: '3' }; | ||
var query = sqlBuilder() | ||
.select({"f.Id" : null,"AssetNumber":null,"ShortDescription":null,"glc.Name":"GLCategory.Name","ac.Number":"AccountCode", | ||
"oc.Name":"OperationalCategory.Name","f.InitialCost":null,"f.AcquiredDate":null,"y.Name":"Yard.Name", | ||
"dep.Name":"Department.Name", "f.FixedAssetTypeDisplayName":"FixedAssetType.DisplayName","f.VIN":null, | ||
"po.Number":"PONumber"}) | ||
.from("FixedAssets f") | ||
.join("AccountingProcessTypes glc", "glc.Id", "f.GLCategory_id") | ||
.join("AccountCodes ac","ac.Id","glc.AccountCode_id") | ||
.join("EquipmentTypes oc", "oc.Id", "f.OperationalCategory_id") | ||
.join("Yards y") | ||
.join("Departments dep") | ||
.leftJoin("Receivers r") | ||
.leftJoin("PurchaseOrders po", "po.Id", "r.PurchaseOrder_id") | ||
.processListRequest(reqquery) | ||
.build(); | ||
query.should | ||
.equal("WITH SelectedItems AS (SELECT f.Id, AssetNumber, ShortDescription, glc.Name AS 'GLCategory.Name', ac.Number AS 'AccountCode', oc.Name AS 'OperationalCategory.Name', f.InitialCost, f.AcquiredDate, y.Name AS 'Yard.Name', dep.Name AS 'Department.Name', f.FixedAssetTypeDisplayName AS 'FixedAssetType.DisplayName', f.VIN, po.Number AS 'PONumber', ROW_NUMBER() OVER (ORDER BY f.AcquiredDate DESC) AS Position FROM FixedAssets f JOIN AccountingProcessTypes glc ON glc.Id = f.GLCategory_id JOIN AccountCodes ac ON ac.Id = glc.AccountCode_id JOIN EquipmentTypes oc ON oc.Id = f.OperationalCategory_id JOIN Yards y ON f.Yard_id = y.Id JOIN Departments dep ON f.Department_id = dep.Id LEFT JOIN Receivers r ON f.Receiver_id = r.Id LEFT JOIN PurchaseOrders po ON po.Id = r.PurchaseOrder_id WHERE y.Name LIKE '%Okla%' AND f.IsActive = 1) SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 0 AND Position <= 100 ") | ||
done(); | ||
}); | ||
it('Should filter by enumeration displayname properly', function (done) { | ||
var reqquery ={ filters: '(AcquiredSource.DisplayName.Equals("Purchased"))&&IsActive=true', | ||
sidx: 'AcquiredSource', | ||
sord: 'desc', | ||
RenderFormat: 'paged', | ||
page: '1', | ||
pagePercent: '0.3333333333333333', | ||
total: '238', | ||
rows: '100', | ||
totalPages: '3' }; | ||
var query = sqlBuilder() | ||
.select({"f.Id" : null,"AssetNumber":null,"ShortDescription":null,"glc.Name":"GLCategory.Name","ac.Number":"AccountCode", | ||
"oc.Name":"OperationalCategory.Name","f.InitialCost":null,"f.AcquiredDate":null,"y.Name":"Yard.Name", | ||
"dep.Name":"Department.Name", "f.FixedAssetTypeDisplayName":"FixedAssetType.DisplayName","f.VIN":null, | ||
"po.Number":"PONumber"}) | ||
.from("FixedAssets f") | ||
.join("AccountingProcessTypes glc", "glc.Id", "f.GLCategory_id") | ||
.join("AccountCodes ac","ac.Id","glc.AccountCode_id") | ||
.join("EquipmentTypes oc", "oc.Id", "f.OperationalCategory_id") | ||
.join("Yards y") | ||
.join("Departments dep") | ||
.leftJoin("Receivers r") | ||
.leftJoin("PurchaseOrders po", "po.Id", "r.PurchaseOrder_id") | ||
.processListRequest(reqquery) | ||
.build(); | ||
query.should | ||
.equal("WITH SelectedItems AS (SELECT f.Id, AssetNumber, ShortDescription, glc.Name AS 'GLCategory.Name', ac.Number AS 'AccountCode', oc.Name AS 'OperationalCategory.Name', f.InitialCost, f.AcquiredDate, y.Name AS 'Yard.Name', dep.Name AS 'Department.Name', f.FixedAssetTypeDisplayName AS 'FixedAssetType.DisplayName', f.VIN, po.Number AS 'PONumber', ROW_NUMBER() OVER (ORDER BY f.AcquiredSource DESC) AS Position FROM FixedAssets f JOIN AccountingProcessTypes glc ON glc.Id = f.GLCategory_id JOIN AccountCodes ac ON ac.Id = glc.AccountCode_id JOIN EquipmentTypes oc ON oc.Id = f.OperationalCategory_id JOIN Yards y ON f.Yard_id = y.Id JOIN Departments dep ON f.Department_id = dep.Id LEFT JOIN Receivers r ON f.Receiver_id = r.Id LEFT JOIN PurchaseOrders po ON po.Id = r.PurchaseOrder_id WHERE (f.AcquiredSourceDisplayName = 'Purchased') AND f.IsActive = 1) SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 0 AND Position <= 100 ") | ||
done(); | ||
}); | ||
it('Should filter by contains properly', function (done) { | ||
var reqquery ={ filters: 'InvoiceCustomerName.Contains("EOG Re")&&IsActive=true', | ||
sidx: 'InvoiceNumber', | ||
sord: 'asc', | ||
RenderFormat: 'paged', | ||
page: '1', | ||
pagePercent: '0.3333333333333333', | ||
total: '205', | ||
rows: '100', | ||
totalPages: '3' }; | ||
var req = { query: reqquery }; | ||
var query = sqlBuilder().from('InvoiceSalesTaxInfoView') | ||
.select({ | ||
Id: null, | ||
Created: null, | ||
LastModified: null, | ||
IsActive: null, | ||
ModifiedBy: null, | ||
'TotalTax':null, | ||
'Total':null, | ||
'TaxableTotal':null, | ||
'NonTaxableTotal':null, | ||
TaxRate:null, | ||
InvoiceNumber:null, | ||
InvoiceCustomerName:null, | ||
InvoiceYard:null, | ||
InvoiceDate:null, | ||
InvoiceStateDisplayName:'InvoiceState.DisplayName', | ||
InvoiceStateValue:'InvoiceState.Value', | ||
StatusDisplayName:'Status.DisplayName', | ||
StatusValue:'Status.Value', | ||
InvoiceIsProcessed:null, | ||
SalesTaxZoneState:null, | ||
SalesTaxZoneName:null | ||
}) | ||
.processListRequest(req) | ||
.build(); | ||
query.should | ||
.equal("WITH SelectedItems AS (SELECT Id, Created, LastModified, IsActive, ModifiedBy, TotalTax, Total, TaxableTotal, NonTaxableTotal, TaxRate, InvoiceNumber, InvoiceCustomerName, InvoiceYard, InvoiceDate, InvoiceStateDisplayName AS 'InvoiceState.DisplayName', InvoiceStateValue AS 'InvoiceState.Value', StatusDisplayName AS 'Status.DisplayName', StatusValue AS 'Status.Value', InvoiceIsProcessed, SalesTaxZoneState, SalesTaxZoneName, ROW_NUMBER() OVER (ORDER BY InvoiceNumber ASC) AS Position FROM InvoiceSalesTaxInfoView WHERE InvoiceCustomerName LIKE '%EOG Re%' AND InvoiceSalesTaxInfoView.IsActive = 1) SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 0 AND Position <= 100 ") | ||
done(); | ||
}); | ||
it('Should give the propery query for a view', function (done) { | ||
var reqquery ={ filters: 'IsActive=true&&TerritoryId=null', | ||
sidx: 'Created', | ||
sord: 'asc', | ||
RenderFormat: 'paged', | ||
page: '', | ||
pagePercent: '0', | ||
total: '', | ||
rows: '100', | ||
totalPages: '' }; | ||
var query = sqlBuilder() | ||
.from('MaintenanceAssignmentView') | ||
.select({ | ||
'Status': null, | ||
'Description': 'Description', | ||
'CreatorFirstName': 'CreatorFirstName', | ||
'TerritoryId': 'TerritoryId', | ||
'ServiceTicketId': 'ServiceTicketId', | ||
'ServiceTicketNumber': 'ServiceTicketNumber', | ||
'YardId': 'YardId', | ||
'Yard': 'Yard', | ||
'Equipment': 'Equipment', | ||
'JobInstructions': 'JobInstructions', | ||
'Categories': 'Categories', | ||
'Created': 'Created', | ||
'Id': 'Id', | ||
"(CreatorFirstName + ' ' + CreatorLastName)": 'CreatorName', | ||
"(CASE WHEN Status = 'Rejected' Then 1 else 1 END)": 'IsRejected' | ||
}) | ||
.where({Status: 'Complete'}) | ||
.processListRequest(reqquery) | ||
.build(); | ||
query.should | ||
.equal("WITH SelectedItems AS (SELECT Status, Description AS 'Description', CreatorFirstName AS 'CreatorFirstName', TerritoryId AS 'TerritoryId', ServiceTicketId AS 'ServiceTicketId', ServiceTicketNumber AS 'ServiceTicketNumber', YardId AS 'YardId', Yard AS 'Yard', Equipment AS 'Equipment', JobInstructions AS 'JobInstructions', Categories AS 'Categories', Created AS 'Created', Id AS 'Id', (CreatorFirstName + ' ' + CreatorLastName) AS 'CreatorName', (CASE WHEN Status = 'Rejected' Then 1 else 1 END) AS 'IsRejected', ROW_NUMBER() OVER (ORDER BY Created ASC) AS Position FROM MaintenanceAssignmentView WHERE MaintenanceAssignmentView.Status = 'Complete' AND MaintenanceAssignmentView.IsActive = 1 AND (TerritoryId IS null)) SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 0 AND Position <= 100 ") | ||
done(); | ||
}); | ||
it('Should give the propery query for a view with guid and single equals', function (done) { | ||
var reqquery ={ filters: 'IsActive=true&&TerritoryId=A1139D28-CE9E-4EF9-A595-A31401026A65', | ||
sidx: 'Created', | ||
sord: 'desc', | ||
RenderFormat: 'paged', | ||
page: '1', | ||
pagePercent: 'Infinity', | ||
total: '0', | ||
rows: '100', | ||
totalPages: '0' }; | ||
var query = sqlBuilder() | ||
.from('MaintenanceAssignmentView') | ||
.select({ | ||
'Status': null, | ||
'Description': 'Description', | ||
'CreatorFirstName': 'CreatorFirstName', | ||
'TerritoryId': 'TerritoryId', | ||
'ServiceTicketId': 'ServiceTicketId', | ||
'ServiceTicketNumber': 'ServiceTicketNumber', | ||
'YardId': 'YardId', | ||
'Yard': 'Yard', | ||
'Equipment': 'Equipment', | ||
'JobInstructions': 'JobInstructions', | ||
'Categories': 'Categories', | ||
'Created': 'Created', | ||
'Id': 'Id', | ||
"(CreatorFirstName + ' ' + CreatorLastName)": 'CreatorName', | ||
"(CASE WHEN Status = 'Rejected' Then 1 else 1 END)": 'IsRejected' | ||
}) | ||
.where({Status: 'Complete'}) | ||
.processListRequest(reqquery) | ||
.build(); | ||
query.should | ||
.equal("WITH SelectedItems AS (SELECT Status, Description AS 'Description', CreatorFirstName AS 'CreatorFirstName', TerritoryId AS 'TerritoryId', ServiceTicketId AS 'ServiceTicketId', ServiceTicketNumber AS 'ServiceTicketNumber', YardId AS 'YardId', Yard AS 'Yard', Equipment AS 'Equipment', JobInstructions AS 'JobInstructions', Categories AS 'Categories', Created AS 'Created', Id AS 'Id', (CreatorFirstName + ' ' + CreatorLastName) AS 'CreatorName', (CASE WHEN Status = 'Rejected' Then 1 else 1 END) AS 'IsRejected', ROW_NUMBER() OVER (ORDER BY Created DESC) AS Position FROM MaintenanceAssignmentView WHERE MaintenanceAssignmentView.Status = 'Complete' AND MaintenanceAssignmentView.IsActive = 1 AND (TerritoryId = 'A1139D28-CE9E-4EF9-A595-A31401026A65')) SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 0 AND Position <= 100 ") | ||
done(); | ||
}); | ||
it('Should give the replace false with 0', function (done) { | ||
var reqquery ={ filters: 'IsActive=true&&(Status.Value==3)&&(IsApproved==false)', | ||
sidx: 'OperationalCategoryName', | ||
sord: 'asc', | ||
RenderFormat: 'paged', | ||
page: '1', | ||
pagePercent: 'Infinity', | ||
total: '0', | ||
rows: '100', | ||
totalPages: '0' }; | ||
var query = sqlBuilder() | ||
.from('ServiceTicketView') | ||
.select({ OperationalCategoryName: 'OperationalCategoryName', | ||
'count(OperationalCategoryName)': 'Count' }) | ||
.groupBy('OperationalCategoryName') | ||
.processListRequest(reqquery) | ||
.build(); | ||
query.should | ||
.equal("WITH SelectedItems AS (SELECT OperationalCategoryName AS 'OperationalCategoryName', count(OperationalCategoryName) AS 'Count', ROW_NUMBER() OVER (ORDER BY OperationalCategoryName ASC) AS Position FROM ServiceTicketView WHERE ServiceTicketView.IsActive = 1 AND (ServiceTicketView.StatusValue = 3) AND (ServiceTicketView.IsApproved = 0) GROUP BY OperationalCategoryName) SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 0 AND Position <= 100 "); | ||
done(); | ||
}); | ||
it('should work for tickets with additional filters from monthly closing page', function(done){ | ||
var reqquery = { | ||
filters: 'IsActive=true&&&&Created>2014-10-15T10:29:38.000Z&&Date<=2014-06-30T00:00:00.000Z&&StatusValue!=3&&StatusValue!=4&&StatusValue!=5', | ||
sidx: 'Number', | ||
sord: 'asc', | ||
RenderFormat: 'paged', | ||
page: '', | ||
pagePercent: '0', | ||
total: '', | ||
rows: '100', | ||
totalPages: '' }; | ||
var query = sqlBuilder().from("Tickets").selectJoin({ | ||
'Tickets.Id': 'Id', | ||
'Tickets.Total': 'Total', | ||
'Tickets.IsTurnedIn': 'IsTurnedIn', | ||
'Tickets.IsSigned': 'IsSigned', | ||
'Tickets.Date': 'Date', | ||
'CustomerShipTos.CustomerName': 'CustomerShipTo.CustomerName', | ||
'Leases.Name': 'Lease.Name', | ||
'Phases.Name': 'Phase.Name', | ||
'Yards.Name': 'Yard.Name' | ||
}).processListRequest(reqquery).build(); | ||
query.should.equal( | ||
"WITH SelectedItems AS (SELECT Tickets.Id AS 'Id', Tickets.Total AS 'Total', Tickets.IsTurnedIn AS 'IsTurnedIn', Tickets.IsSigned AS 'IsSigned', Tickets.Date AS 'Date', CustomerShipTos.CustomerName AS 'CustomerShipTo.CustomerName', " | ||
+"Leases.Name AS 'Lease.Name', Phases.Name AS 'Phase.Name', Yards.Name AS 'Yard.Name', ROW_NUMBER() OVER (ORDER BY Tickets.Number ASC) AS Position FROM Tickets LEFT JOIN CustomerShipTos ON Tickets.CustomerShipTo_id = CustomerShipTos.Id LEFT JOIN Leases ON Tickets.Lease_id = Leases.Id LEFT JOIN Phases ON Tickets.Phase_id = Phases.Id LEFT JOIN " | ||
+"Yards ON Tickets.Yard_id = Yards.Id WHERE Tickets.IsActive = 1 AND Tickets.Created > '2014-10-15T10:29:38.000Z' AND Tickets.Date <= '2014-06-30T00:00:00.000Z' " | ||
+"AND (Tickets.StatusValue != 3) AND (Tickets.StatusValue != 4) AND (Tickets.StatusValue != 5)) SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 0 AND Position <= 100 " | ||
); | ||
done(); | ||
}); | ||
it('Should filter on the nested enumeration', function (done) { | ||
it("Should handle or'd filters", function (done) { | ||
var selection = { | ||
@@ -825,3 +996,3 @@ 'fa.Id': 'Id', | ||
var reqquery ={ filters: '(CurrentRentalStatus.RentalStatus.Value==1)', | ||
var reqquery ={ filters: 'CurrentRentalStatus.RentalStatus.Value=1 || CurrentRentalStatus.RentalStatus.Value=2 || CurrentRentalStatus.RentalStatus.Value=3', | ||
RenderFormat: 'paged', | ||
@@ -841,120 +1012,6 @@ page: '1', | ||
query.should | ||
.equal("WITH SelectedItems AS (SELECT fa.Id AS 'Id', fa.Created AS 'Created', fa.LastModified AS 'LastModified', fa.IsActive AS 'IsActive', fa.ModifiedBy AS 'ModifiedBy', fa.ShortDescription AS 'ShortDescription', fa.LongDescription AS 'LongDescription', fa.VIN AS 'VIN', RentalType = NULL, rst.Id AS 'CurrentRentalStatus.Id', rst.Created AS 'CurrentRentalStatus.Created', rst.LastModified AS 'CurrentRentalStatus.LastModified', rst.IsActive AS 'CurrentRentalStatus.IsActive', rst.ModifiedBy AS 'CurrentRentalStatus.ModifiedBy', rst.RentalStatusValue AS 'CurrentRentalStatus.RentalStatus.Value', rst.RentalStatusDisplayName AS 'CurrentRentalStatus.RentalStatus.DisplayName', 'CurrentRentalStatus.DisplayTime' = NULL, rst.Time AS 'CurrentRentalStatus.Time', 'CurrentRentalStatus.TimeParts' = NULL, rst.Notes AS 'CurrentRentalStatus.Notes', rst.TicketNumber AS 'CurrentRentalStatus.TicketNumber', 'CurrentRentalStatus.TicketId' = NULL, rst.Phase AS 'CurrentRentalStatus.Phase', l.Name AS 'CurrentRentalStatus.Lease', 'CurrentRentalStatus.PhaseType' = NULL, l.Id AS 'CurrentRentalStatus.LeaseId', RevenueAccount = NULL, ExpenseAccount = NULL, AssetAccount = NULL, UseParentsAccounts = 0, Vendor = NULL, Uom = NULL, Quantity = 0, ROW_NUMBER() OVER (ORDER BY fa.Created) AS Position FROM FixedAssets fa JOIN RentalStatusTracks rst ON fa.CurrentRentalStatus_id = rst.Id LEFT JOIN Leases l ON rst.Lease_id = l.Id WHERE (NOT fa.RentalSelectionValue = 1) AND (rst.RentalStatusValue = 1)) SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 0 AND Position <= 100 "); | ||
.equal("WITH SelectedItems AS (SELECT fa.Id AS 'Id', fa.Created AS 'Created', fa.LastModified AS 'LastModified', fa.IsActive AS 'IsActive', fa.ModifiedBy AS 'ModifiedBy', fa.ShortDescription AS 'ShortDescription', fa.LongDescription AS 'LongDescription', fa.VIN AS 'VIN', RentalType = NULL, rst.Id AS 'CurrentRentalStatus.Id', rst.Created AS 'CurrentRentalStatus.Created', rst.LastModified AS 'CurrentRentalStatus.LastModified', rst.IsActive AS 'CurrentRentalStatus.IsActive', rst.ModifiedBy AS 'CurrentRentalStatus.ModifiedBy', rst.RentalStatusValue AS 'CurrentRentalStatus.RentalStatus.Value', rst.RentalStatusDisplayName AS 'CurrentRentalStatus.RentalStatus.DisplayName', 'CurrentRentalStatus.DisplayTime' = NULL, rst.Time AS 'CurrentRentalStatus.Time', 'CurrentRentalStatus.TimeParts' = NULL, rst.Notes AS 'CurrentRentalStatus.Notes', rst.TicketNumber AS 'CurrentRentalStatus.TicketNumber', 'CurrentRentalStatus.TicketId' = NULL, rst.Phase AS 'CurrentRentalStatus.Phase', l.Name AS 'CurrentRentalStatus.Lease', 'CurrentRentalStatus.PhaseType' = NULL, l.Id AS 'CurrentRentalStatus.LeaseId', RevenueAccount = NULL, ExpenseAccount = NULL, AssetAccount = NULL, UseParentsAccounts = 0, Vendor = NULL, Uom = NULL, Quantity = 0, ROW_NUMBER() OVER (ORDER BY fa.Created) AS Position FROM FixedAssets fa JOIN RentalStatusTracks rst ON fa.CurrentRentalStatus_id = rst.Id LEFT JOIN Leases l ON rst.Lease_id = l.Id WHERE (NOT fa.RentalSelectionValue = 1) AND ((rst.RentalStatusValue = 1) OR (rst.RentalStatusValue = 2) OR (rst.RentalStatusValue = 3))) SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 0 AND Position <= 100 "); | ||
done(); | ||
}); | ||
it('Should handle multiple aliases to the same field', function (done) { | ||
var selection = { | ||
'fa.Id': 'Id', | ||
'fa.Created': 'Created', | ||
'fa.LastModified': 'LastModified', | ||
'fa.IsActive': 'IsActive', | ||
'fa.ModifiedBy': 'ModifiedBy', | ||
'fa.ShortDescription': 'ShortDescription', | ||
'fa.LongDescription': 'LongDescription', | ||
'fa.VIN': 'VIN', | ||
'RentalType = NULL': null, | ||
'rst.Id': 'CurrentRentalStatus.Id', | ||
'rst.Created': 'CurrentRentalStatus.Created', | ||
'rst.LastModified': 'CurrentRentalStatus.LastModified', | ||
'rst.IsActive': 'CurrentRentalStatus.IsActive', | ||
'rst.ModifiedBy': 'CurrentRentalStatus.ModifiedBy', | ||
'rst.RentalStatusValue': 'CurrentRentalStatus.RentalStatus.Value, RentalStatusValue', | ||
'rst.RentalStatusDisplayName': 'CurrentRentalStatus.RentalStatus.DisplayName, RentalStatusDisplayName', | ||
"'CurrentRentalStatus.DisplayTime' = NULL": null, | ||
'rst.Time': 'CurrentRentalStatus.Time', | ||
"'CurrentRentalStatus.TimeParts' = NULL": null, | ||
'rst.Notes': 'CurrentRentalStatus.Notes', | ||
'rst.TicketNumber': 'CurrentRentalStatus.TicketNumber', | ||
"'CurrentRentalStatus.TicketId' = NULL": null, | ||
'rst.Phase': 'CurrentRentalStatus.Phase', | ||
'l.Name': 'CurrentRentalStatus.Lease', | ||
"'CurrentRentalStatus.PhaseType' = NULL": null, | ||
'l.Id': 'CurrentRentalStatus.LeaseId', | ||
'RevenueAccount = NULL': null, | ||
'ExpenseAccount = NULL': null, | ||
'AssetAccount = NULL': null, | ||
'UseParentsAccounts = 0': null, | ||
'Vendor = NULL': null, | ||
'Uom = NULL': null, | ||
'Quantity = 0' : null | ||
}; | ||
var reqquery ={ filters: '(RentalStatusValue==1)', | ||
RenderFormat: 'paged', | ||
page: '1', | ||
rows: '100'}; | ||
var query = sqlBuilder() | ||
.select(selection) | ||
.from('FixedAssets fa') | ||
.join('RentalStatusTracks rst', 'fa.CurrentRentalStatus_id', 'rst.Id') | ||
.leftJoin('Leases l ON rst.Lease_id = l.Id') | ||
.where('(NOT fa.RentalSelectionValue = 1)') | ||
.processListRequest(reqquery) | ||
.build(); | ||
query.should | ||
.equal("WITH SelectedItems AS (SELECT fa.Id AS 'Id', fa.Created AS 'Created', fa.LastModified AS 'LastModified', fa.IsActive AS 'IsActive', fa.ModifiedBy AS 'ModifiedBy', fa.ShortDescription AS 'ShortDescription', fa.LongDescription AS 'LongDescription', fa.VIN AS 'VIN', RentalType = NULL, rst.Id AS 'CurrentRentalStatus.Id', rst.Created AS 'CurrentRentalStatus.Created', rst.LastModified AS 'CurrentRentalStatus.LastModified', rst.IsActive AS 'CurrentRentalStatus.IsActive', rst.ModifiedBy AS 'CurrentRentalStatus.ModifiedBy', rst.RentalStatusValue AS 'CurrentRentalStatus.RentalStatus.Value', rst.RentalStatusValue AS 'RentalStatusValue', rst.RentalStatusDisplayName AS 'CurrentRentalStatus.RentalStatus.DisplayName', rst.RentalStatusDisplayName AS 'RentalStatusDisplayName', 'CurrentRentalStatus.DisplayTime' = NULL, rst.Time AS 'CurrentRentalStatus.Time', 'CurrentRentalStatus.TimeParts' = NULL, rst.Notes AS 'CurrentRentalStatus.Notes', rst.TicketNumber AS 'CurrentRentalStatus.TicketNumber', 'CurrentRentalStatus.TicketId' = NULL, rst.Phase AS 'CurrentRentalStatus.Phase', l.Name AS 'CurrentRentalStatus.Lease', 'CurrentRentalStatus.PhaseType' = NULL, l.Id AS 'CurrentRentalStatus.LeaseId', RevenueAccount = NULL, ExpenseAccount = NULL, AssetAccount = NULL, UseParentsAccounts = 0, Vendor = NULL, Uom = NULL, Quantity = 0, ROW_NUMBER() OVER (ORDER BY fa.Created) AS Position FROM FixedAssets fa JOIN RentalStatusTracks rst ON fa.CurrentRentalStatus_id = rst.Id LEFT JOIN Leases l ON rst.Lease_id = l.Id WHERE (NOT fa.RentalSelectionValue = 1) AND (rst.RentalStatusValue = 1)) SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 0 AND Position <= 100 "); | ||
done(); | ||
}); | ||
it('Should filter on the nested enumeration', function (done) { | ||
var selection = { | ||
'fa.Id': 'Id', | ||
'fa.Created': 'Created', | ||
'fa.LastModified': 'LastModified', | ||
'fa.IsActive': 'IsActive', | ||
'fa.ModifiedBy': 'ModifiedBy', | ||
'fa.ShortDescription': 'ShortDescription', | ||
'fa.LongDescription': 'LongDescription', | ||
'fa.VIN': 'VIN', | ||
'RentalType = NULL': null, | ||
'rst.Id': 'CurrentRentalStatus.Id', | ||
'rst.Created': 'CurrentRentalStatus.Created', | ||
'rst.LastModified': 'CurrentRentalStatus.LastModified', | ||
'rst.IsActive': 'CurrentRentalStatus.IsActive', | ||
'rst.ModifiedBy': 'CurrentRentalStatus.ModifiedBy', | ||
'rst.RentalStatusValue': 'CurrentRentalStatus.RentalStatus.Value', | ||
'rst.RentalStatusDisplayName': 'CurrentRentalStatus.RentalStatus.DisplayName', | ||
"'CurrentRentalStatus.DisplayTime' = NULL": null, | ||
'rst.Time': 'CurrentRentalStatus.Time', | ||
"'CurrentRentalStatus.TimeParts' = NULL": null, | ||
'rst.Notes': 'CurrentRentalStatus.Notes', | ||
'rst.TicketNumber': 'CurrentRentalStatus.TicketNumber', | ||
"'CurrentRentalStatus.TicketId' = NULL": null, | ||
'rst.Phase': 'CurrentRentalStatus.Phase', | ||
'l.Name': 'CurrentRentalStatus.Lease', | ||
"'CurrentRentalStatus.PhaseType' = NULL": null, | ||
'l.Id': 'CurrentRentalStatus.LeaseId', | ||
'RevenueAccount = NULL': null, | ||
'ExpenseAccount = NULL': null, | ||
'AssetAccount = NULL': null, | ||
'UseParentsAccounts = 0': null, | ||
'Vendor = NULL': null, | ||
'Uom = NULL': null, | ||
'Quantity = 0' : null | ||
}; | ||
var reqquery ={ filters: '(CurrentRentalStatus.RentalStatus.Value==1)', | ||
RenderFormat: 'paged', | ||
page: '1', | ||
rows: '100'}; | ||
var query = sqlBuilder() | ||
.select(selection) | ||
.from('FixedAssets fa') | ||
.join('RentalStatusTracks rst', 'fa.CurrentRentalStatus_id', 'rst.Id') | ||
.leftJoin('Leases l ON rst.Lease_id = l.Id') | ||
.where('(NOT fa.RentalSelectionValue = 1)') | ||
.processListRequest(reqquery) | ||
.build(); | ||
query.should | ||
.equal("WITH SelectedItems AS (SELECT fa.Id AS 'Id', fa.Created AS 'Created', fa.LastModified AS 'LastModified', fa.IsActive AS 'IsActive', fa.ModifiedBy AS 'ModifiedBy', fa.ShortDescription AS 'ShortDescription', fa.LongDescription AS 'LongDescription', fa.VIN AS 'VIN', RentalType = NULL, rst.Id AS 'CurrentRentalStatus.Id', rst.Created AS 'CurrentRentalStatus.Created', rst.LastModified AS 'CurrentRentalStatus.LastModified', rst.IsActive AS 'CurrentRentalStatus.IsActive', rst.ModifiedBy AS 'CurrentRentalStatus.ModifiedBy', rst.RentalStatusValue AS 'CurrentRentalStatus.RentalStatus.Value', rst.RentalStatusDisplayName AS 'CurrentRentalStatus.RentalStatus.DisplayName', 'CurrentRentalStatus.DisplayTime' = NULL, rst.Time AS 'CurrentRentalStatus.Time', 'CurrentRentalStatus.TimeParts' = NULL, rst.Notes AS 'CurrentRentalStatus.Notes', rst.TicketNumber AS 'CurrentRentalStatus.TicketNumber', 'CurrentRentalStatus.TicketId' = NULL, rst.Phase AS 'CurrentRentalStatus.Phase', l.Name AS 'CurrentRentalStatus.Lease', 'CurrentRentalStatus.PhaseType' = NULL, l.Id AS 'CurrentRentalStatus.LeaseId', RevenueAccount = NULL, ExpenseAccount = NULL, AssetAccount = NULL, UseParentsAccounts = 0, Vendor = NULL, Uom = NULL, Quantity = 0, ROW_NUMBER() OVER (ORDER BY fa.Created) AS Position FROM FixedAssets fa JOIN RentalStatusTracks rst ON fa.CurrentRentalStatus_id = rst.Id LEFT JOIN Leases l ON rst.Lease_id = l.Id WHERE (NOT fa.RentalSelectionValue = 1) AND (rst.RentalStatusValue = 1)) SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 0 AND Position <= 100 "); | ||
done(); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
215421
4521
7