attempt to reduce complexity
parent
095eb2e5f8
commit
889ad4ab10
|
|
@ -36,8 +36,7 @@ function buildWhereClause(filters) {
|
||||||
sqlParameters.push(dateStringToInteger(filters.occupancyStartDateString));
|
sqlParameters.push(dateStringToInteger(filters.occupancyStartDateString));
|
||||||
}
|
}
|
||||||
if ((filters.occupancyEffectiveDateString ?? '') !== '') {
|
if ((filters.occupancyEffectiveDateString ?? '') !== '') {
|
||||||
sqlWhereClause +=
|
sqlWhereClause += ` and (
|
||||||
` and (
|
|
||||||
o.occupancyEndDate is null
|
o.occupancyEndDate is null
|
||||||
or (o.occupancyStartDate <= ? and o.occupancyEndDate >= ?)
|
or (o.occupancyStartDate <= ? and o.occupancyEndDate >= ?)
|
||||||
)`;
|
)`;
|
||||||
|
|
@ -66,6 +65,18 @@ function buildWhereClause(filters) {
|
||||||
sqlParameters
|
sqlParameters
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
async function addInclusions(lotOccupancy, options, database) {
|
||||||
|
if (options.includeFees) {
|
||||||
|
lotOccupancy.lotOccupancyFees = await getLotOccupancyFees(lotOccupancy.lotOccupancyId, database);
|
||||||
|
}
|
||||||
|
if (options.includeTransactions) {
|
||||||
|
lotOccupancy.lotOccupancyTransactions = await getLotOccupancyTransactions(lotOccupancy.lotOccupancyId, database);
|
||||||
|
}
|
||||||
|
if (options.includeOccupants) {
|
||||||
|
lotOccupancy.lotOccupancyOccupants = await getLotOccupancyOccupants(lotOccupancy.lotOccupancyId, database);
|
||||||
|
}
|
||||||
|
return lotOccupancy;
|
||||||
|
}
|
||||||
export async function getLotOccupancies(filters, options, connectedDatabase) {
|
export async function getLotOccupancies(filters, options, connectedDatabase) {
|
||||||
const database = connectedDatabase ?? (await acquireConnection());
|
const database = connectedDatabase ?? (await acquireConnection());
|
||||||
database.function('userFn_dateIntegerToString', dateIntegerToString);
|
database.function('userFn_dateIntegerToString', dateIntegerToString);
|
||||||
|
|
@ -74,10 +85,10 @@ export async function getLotOccupancies(filters, options, connectedDatabase) {
|
||||||
const isLimited = options.limit !== -1;
|
const isLimited = options.limit !== -1;
|
||||||
if (isLimited) {
|
if (isLimited) {
|
||||||
count = database
|
count = database
|
||||||
.prepare('select count(*) as recordCount' +
|
.prepare(`select count(*) as recordCount
|
||||||
' from LotOccupancies o' +
|
from LotOccupancies o
|
||||||
' left join Lots l on o.lotId = l.lotId' +
|
left join Lots l on o.lotId = l.lotId
|
||||||
sqlWhereClause)
|
${sqlWhereClause}`)
|
||||||
.get(sqlParameters).recordCount;
|
.get(sqlParameters).recordCount;
|
||||||
}
|
}
|
||||||
let lotOccupancies = [];
|
let lotOccupancies = [];
|
||||||
|
|
@ -108,16 +119,7 @@ export async function getLotOccupancies(filters, options, connectedDatabase) {
|
||||||
? configFunctions.getProperty('settings.lotOccupancy.prints')[0]
|
? configFunctions.getProperty('settings.lotOccupancy.prints')[0]
|
||||||
: occupancyType.occupancyTypePrints[0];
|
: occupancyType.occupancyTypePrints[0];
|
||||||
}
|
}
|
||||||
if (options.includeFees) {
|
await addInclusions(lotOccupancy, options, database);
|
||||||
lotOccupancy.lotOccupancyFees = await getLotOccupancyFees(lotOccupancy.lotOccupancyId, database);
|
|
||||||
}
|
|
||||||
if (options.includeTransactions) {
|
|
||||||
lotOccupancy.lotOccupancyTransactions =
|
|
||||||
await getLotOccupancyTransactions(lotOccupancy.lotOccupancyId, database);
|
|
||||||
}
|
|
||||||
if (options.includeOccupants) {
|
|
||||||
lotOccupancy.lotOccupancyOccupants = await getLotOccupancyOccupants(lotOccupancy.lotOccupancyId, database);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (connectedDatabase === undefined) {
|
if (connectedDatabase === undefined) {
|
||||||
|
|
|
||||||
|
|
@ -97,8 +97,7 @@ function buildWhereClause(filters: GetLotOccupanciesFilters): {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((filters.occupancyEffectiveDateString ?? '') !== '') {
|
if ((filters.occupancyEffectiveDateString ?? '') !== '') {
|
||||||
sqlWhereClause +=
|
sqlWhereClause += ` and (
|
||||||
` and (
|
|
||||||
o.occupancyEndDate is null
|
o.occupancyEndDate is null
|
||||||
or (o.occupancyStartDate <= ? and o.occupancyEndDate >= ?)
|
or (o.occupancyStartDate <= ? and o.occupancyEndDate >= ?)
|
||||||
)`
|
)`
|
||||||
|
|
@ -136,6 +135,35 @@ function buildWhereClause(filters: GetLotOccupanciesFilters): {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function addInclusions(
|
||||||
|
lotOccupancy: recordTypes.LotOccupancy,
|
||||||
|
options: GetLotOccupanciesOptions,
|
||||||
|
database: PoolConnection
|
||||||
|
): Promise<recordTypes.LotOccupancy> {
|
||||||
|
if (options.includeFees) {
|
||||||
|
lotOccupancy.lotOccupancyFees = await getLotOccupancyFees(
|
||||||
|
lotOccupancy.lotOccupancyId!,
|
||||||
|
database
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.includeTransactions) {
|
||||||
|
lotOccupancy.lotOccupancyTransactions = await getLotOccupancyTransactions(
|
||||||
|
lotOccupancy.lotOccupancyId!,
|
||||||
|
database
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.includeOccupants) {
|
||||||
|
lotOccupancy.lotOccupancyOccupants = await getLotOccupancyOccupants(
|
||||||
|
lotOccupancy.lotOccupancyId!,
|
||||||
|
database
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return lotOccupancy
|
||||||
|
}
|
||||||
|
|
||||||
export async function getLotOccupancies(
|
export async function getLotOccupancies(
|
||||||
filters: GetLotOccupanciesFilters,
|
filters: GetLotOccupanciesFilters,
|
||||||
options: GetLotOccupanciesOptions,
|
options: GetLotOccupanciesOptions,
|
||||||
|
|
@ -154,10 +182,10 @@ export async function getLotOccupancies(
|
||||||
if (isLimited) {
|
if (isLimited) {
|
||||||
count = database
|
count = database
|
||||||
.prepare(
|
.prepare(
|
||||||
'select count(*) as recordCount' +
|
`select count(*) as recordCount
|
||||||
' from LotOccupancies o' +
|
from LotOccupancies o
|
||||||
' left join Lots l on o.lotId = l.lotId' +
|
left join Lots l on o.lotId = l.lotId
|
||||||
sqlWhereClause
|
${sqlWhereClause}`
|
||||||
)
|
)
|
||||||
.get(sqlParameters).recordCount
|
.get(sqlParameters).recordCount
|
||||||
}
|
}
|
||||||
|
|
@ -201,27 +229,7 @@ export async function getLotOccupancies(
|
||||||
: occupancyType.occupancyTypePrints![0]
|
: occupancyType.occupancyTypePrints![0]
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.includeFees) {
|
await addInclusions(lotOccupancy, options, database)
|
||||||
lotOccupancy.lotOccupancyFees = await getLotOccupancyFees(
|
|
||||||
lotOccupancy.lotOccupancyId!,
|
|
||||||
database
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options.includeTransactions) {
|
|
||||||
lotOccupancy.lotOccupancyTransactions =
|
|
||||||
await getLotOccupancyTransactions(
|
|
||||||
lotOccupancy.lotOccupancyId!,
|
|
||||||
database
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options.includeOccupants) {
|
|
||||||
lotOccupancy.lotOccupancyOccupants = await getLotOccupancyOccupants(
|
|
||||||
lotOccupancy.lotOccupancyId!,
|
|
||||||
database
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue