attempt to reduce complexity

deepsource-autofix-76c6eb20
Dan Gowans 2022-12-30 13:22:29 -05:00
parent 95ac39b054
commit 677a0f33bd
2 changed files with 7 additions and 10 deletions

View File

@ -69,7 +69,7 @@ export function getLotOccupancies(filters, options, connectedDatabase) {
});
database.function("userFn_dateIntegerToString", dateIntegerToString);
const { sqlWhereClause, sqlParameters } = buildWhereClause(filters);
let count = 0;
let count = options.limit;
const isLimited = options.limit !== -1;
if (isLimited) {
count = database
@ -80,7 +80,7 @@ export function getLotOccupancies(filters, options, connectedDatabase) {
.get(sqlParameters).recordCount;
}
let lotOccupancies = [];
if (!isLimited || count > 0) {
if (count !== 0) {
lotOccupancies = database
.prepare(`select o.lotOccupancyId,
o.occupancyTypeId, t.occupancyType,
@ -95,7 +95,7 @@ export function getLotOccupancies(filters, options, connectedDatabase) {
left join Maps m on l.mapId = m.mapId
${sqlWhereClause}
order by o.occupancyStartDate desc, ifnull(o.occupancyEndDate, 99999999) desc, l.lotName, o.lotId, o.lotOccupancyId desc` +
(isLimited ? " limit " + options.limit + " offset " + options.offset : ""))
(isLimited ? ` limit ${options.limit} offset ${options.offset}` : ""))
.all(sqlParameters);
if (!isLimited) {
count = lotOccupancies.length;

View File

@ -134,11 +134,8 @@ export function getLotOccupancies(
const { sqlWhereClause, sqlParameters } = buildWhereClause(filters);
let count = 0;
let count = options.limit;
/**
* options.limit !== -1
*/
const isLimited = options.limit !== -1;
if (isLimited) {
@ -154,7 +151,7 @@ export function getLotOccupancies(
let lotOccupancies: recordTypes.LotOccupancy[] = [];
if (!isLimited || count > 0) {
if (count !== 0) {
lotOccupancies = database
.prepare(
`select o.lotOccupancyId,
@ -170,7 +167,7 @@ export function getLotOccupancies(
left join Maps m on l.mapId = m.mapId
${sqlWhereClause}
order by o.occupancyStartDate desc, ifnull(o.occupancyEndDate, 99999999) desc, l.lotName, o.lotId, o.lotOccupancyId desc` +
(isLimited ? " limit " + options.limit + " offset " + options.offset : "")
(isLimited ? ` limit ${options.limit} offset ${options.offset}` : "")
)
.all(sqlParameters);
@ -189,7 +186,7 @@ export function getLotOccupancies(
if (options.includeOccupants) {
lotOccupancy.lotOccupancyOccupants = getLotOccupancyOccupants(
lotOccupancy.lotOccupancyId as number,
lotOccupancy.lotOccupancyId,
database
);
}