attempt to reduce complexity
parent
95ac39b054
commit
677a0f33bd
|
|
@ -69,7 +69,7 @@ export function getLotOccupancies(filters, options, connectedDatabase) {
|
||||||
});
|
});
|
||||||
database.function("userFn_dateIntegerToString", dateIntegerToString);
|
database.function("userFn_dateIntegerToString", dateIntegerToString);
|
||||||
const { sqlWhereClause, sqlParameters } = buildWhereClause(filters);
|
const { sqlWhereClause, sqlParameters } = buildWhereClause(filters);
|
||||||
let count = 0;
|
let count = options.limit;
|
||||||
const isLimited = options.limit !== -1;
|
const isLimited = options.limit !== -1;
|
||||||
if (isLimited) {
|
if (isLimited) {
|
||||||
count = database
|
count = database
|
||||||
|
|
@ -80,7 +80,7 @@ export function getLotOccupancies(filters, options, connectedDatabase) {
|
||||||
.get(sqlParameters).recordCount;
|
.get(sqlParameters).recordCount;
|
||||||
}
|
}
|
||||||
let lotOccupancies = [];
|
let lotOccupancies = [];
|
||||||
if (!isLimited || count > 0) {
|
if (count !== 0) {
|
||||||
lotOccupancies = database
|
lotOccupancies = database
|
||||||
.prepare(`select o.lotOccupancyId,
|
.prepare(`select o.lotOccupancyId,
|
||||||
o.occupancyTypeId, t.occupancyType,
|
o.occupancyTypeId, t.occupancyType,
|
||||||
|
|
@ -95,7 +95,7 @@ export function getLotOccupancies(filters, options, connectedDatabase) {
|
||||||
left join Maps m on l.mapId = m.mapId
|
left join Maps m on l.mapId = m.mapId
|
||||||
${sqlWhereClause}
|
${sqlWhereClause}
|
||||||
order by o.occupancyStartDate desc, ifnull(o.occupancyEndDate, 99999999) desc, l.lotName, o.lotId, o.lotOccupancyId desc` +
|
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);
|
.all(sqlParameters);
|
||||||
if (!isLimited) {
|
if (!isLimited) {
|
||||||
count = lotOccupancies.length;
|
count = lotOccupancies.length;
|
||||||
|
|
|
||||||
|
|
@ -134,11 +134,8 @@ export function getLotOccupancies(
|
||||||
|
|
||||||
const { sqlWhereClause, sqlParameters } = buildWhereClause(filters);
|
const { sqlWhereClause, sqlParameters } = buildWhereClause(filters);
|
||||||
|
|
||||||
let count = 0;
|
let count = options.limit;
|
||||||
|
|
||||||
/**
|
|
||||||
* options.limit !== -1
|
|
||||||
*/
|
|
||||||
const isLimited = options.limit !== -1;
|
const isLimited = options.limit !== -1;
|
||||||
|
|
||||||
if (isLimited) {
|
if (isLimited) {
|
||||||
|
|
@ -154,7 +151,7 @@ export function getLotOccupancies(
|
||||||
|
|
||||||
let lotOccupancies: recordTypes.LotOccupancy[] = [];
|
let lotOccupancies: recordTypes.LotOccupancy[] = [];
|
||||||
|
|
||||||
if (!isLimited || count > 0) {
|
if (count !== 0) {
|
||||||
lotOccupancies = database
|
lotOccupancies = database
|
||||||
.prepare(
|
.prepare(
|
||||||
`select o.lotOccupancyId,
|
`select o.lotOccupancyId,
|
||||||
|
|
@ -170,7 +167,7 @@ export function getLotOccupancies(
|
||||||
left join Maps m on l.mapId = m.mapId
|
left join Maps m on l.mapId = m.mapId
|
||||||
${sqlWhereClause}
|
${sqlWhereClause}
|
||||||
order by o.occupancyStartDate desc, ifnull(o.occupancyEndDate, 99999999) desc, l.lotName, o.lotId, o.lotOccupancyId desc` +
|
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);
|
.all(sqlParameters);
|
||||||
|
|
||||||
|
|
@ -189,7 +186,7 @@ export function getLotOccupancies(
|
||||||
|
|
||||||
if (options.includeOccupants) {
|
if (options.includeOccupants) {
|
||||||
lotOccupancy.lotOccupancyOccupants = getLotOccupancyOccupants(
|
lotOccupancy.lotOccupancyOccupants = getLotOccupancyOccupants(
|
||||||
lotOccupancy.lotOccupancyId as number,
|
lotOccupancy.lotOccupancyId,
|
||||||
database
|
database
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue