deepsource-autofix-76c6eb20
Dan Gowans 2023-01-17 13:26:38 -05:00
parent e5cc63fe87
commit 3eb4958f65
24 changed files with 166 additions and 168 deletions

View File

@ -13,7 +13,8 @@ export function addRecord(recordTable, recordName, orderNumber, requestSession)
const rightNowMillis = Date.now();
const result = database
.prepare(`insert into ${recordTable} (
${recordNameColumns.get(recordTable)}, orderNumber,
${recordNameColumns.get(recordTable)},
orderNumber,
recordCreate_userName, recordCreate_timeMillis,
recordUpdate_userName, recordUpdate_timeMillis)
values (?, ?, ?, ?, ?, ?)`)

View File

@ -34,7 +34,8 @@ export function addRecord(
const result = database
.prepare(
`insert into ${recordTable} (
${recordNameColumns.get(recordTable)!}, orderNumber,
${recordNameColumns.get(recordTable)!},
orderNumber,
recordCreate_userName, recordCreate_timeMillis,
recordUpdate_userName, recordUpdate_timeMillis)
values (?, ?, ?, ?, ?, ?)`

View File

@ -9,19 +9,19 @@ function buildWhereClause(filters) {
const lotNameFilters = getLotNameWhereClause(filters.lotName, filters.lotNameSearchType ?? '', 'l');
sqlWhereClause += lotNameFilters.sqlWhereClause;
sqlParameters.push(...lotNameFilters.sqlParameters);
if (filters.mapId) {
if ((filters.mapId ?? '') !== '') {
sqlWhereClause += ' and l.mapId = ?';
sqlParameters.push(filters.mapId);
}
if (filters.lotTypeId) {
if ((filters.lotTypeId ?? '') !== '') {
sqlWhereClause += ' and l.lotTypeId = ?';
sqlParameters.push(filters.lotTypeId);
}
if (filters.lotStatusId) {
if ((filters.lotStatusId ?? '') !== '') {
sqlWhereClause += ' and l.lotStatusId = ?';
sqlParameters.push(filters.lotStatusId);
}
if (filters.occupancyStatus) {
if ((filters.occupancyStatus ?? '') !== '') {
if (filters.occupancyStatus === 'occupied') {
sqlWhereClause += ' and lotOccupancyCount > 0';
}
@ -30,7 +30,7 @@ function buildWhereClause(filters) {
' and (lotOccupancyCount is null or lotOccupancyCount = 0)';
}
}
if (filters.workOrderId) {
if ((filters.workOrderId ?? '') !== '') {
sqlWhereClause +=
' and l.lotId in (select lotId from WorkOrderLots where recordDelete_timeMillis is null and workOrderId = ?)';
sqlParameters.push(filters.workOrderId);
@ -50,20 +50,16 @@ export function getLots(filters, options, connectedDatabase) {
let count = 0;
if (options.limit !== -1) {
count = database
.prepare('select count(*) as recordCount' +
' from Lots l' +
(' left join (' +
'select lotId, count(lotOccupancyId) as lotOccupancyCount' +
' from LotOccupancies' +
' where recordDelete_timeMillis is null' +
' and occupancyStartDate <= ' +
currentDate +
' and (occupancyEndDate is null or occupancyEndDate >= ' +
currentDate +
')' +
' group by lotId' +
') o on l.lotId = o.lotId') +
sqlWhereClause)
.prepare(`select count(*) as recordCount
from Lots l
left join (
select lotId, count(lotOccupancyId) as lotOccupancyCount from LotOccupancies
where recordDelete_timeMillis is null
and occupancyStartDate <= ${currentDate}
and (occupancyEndDate is null or occupancyEndDate >= ${currentDate})
group by lotId
) o on l.lotId = o.lotId
${sqlWhereClause}`)
.get(sqlParameters).recordCount;
}
let lots = [];

View File

@ -41,22 +41,22 @@ function buildWhereClause(filters: GetLotsFilters): {
sqlWhereClause += lotNameFilters.sqlWhereClause
sqlParameters.push(...lotNameFilters.sqlParameters)
if (filters.mapId) {
if ((filters.mapId ?? '') !== '') {
sqlWhereClause += ' and l.mapId = ?'
sqlParameters.push(filters.mapId)
}
if (filters.lotTypeId) {
if ((filters.lotTypeId ?? '') !== '') {
sqlWhereClause += ' and l.lotTypeId = ?'
sqlParameters.push(filters.lotTypeId)
}
if (filters.lotStatusId) {
if ((filters.lotStatusId ?? '') !== '') {
sqlWhereClause += ' and l.lotStatusId = ?'
sqlParameters.push(filters.lotStatusId)
}
if (filters.occupancyStatus) {
if ((filters.occupancyStatus ?? '') !== '') {
if (filters.occupancyStatus === 'occupied') {
sqlWhereClause += ' and lotOccupancyCount > 0'
} else if (filters.occupancyStatus === 'unoccupied') {
@ -65,7 +65,7 @@ function buildWhereClause(filters: GetLotsFilters): {
}
}
if (filters.workOrderId) {
if ((filters.workOrderId ?? '') !== '') {
sqlWhereClause +=
' and l.lotId in (select lotId from WorkOrderLots where recordDelete_timeMillis is null and workOrderId = ?)'
sqlParameters.push(filters.workOrderId)
@ -100,20 +100,16 @@ export function getLots(
if (options.limit !== -1) {
count = database
.prepare(
'select count(*) as recordCount' +
' from Lots l' +
(' left join (' +
'select lotId, count(lotOccupancyId) as lotOccupancyCount' +
' from LotOccupancies' +
' where recordDelete_timeMillis is null' +
' and occupancyStartDate <= ' +
currentDate +
' and (occupancyEndDate is null or occupancyEndDate >= ' +
currentDate +
')' +
' group by lotId' +
') o on l.lotId = o.lotId') +
sqlWhereClause
`select count(*) as recordCount
from Lots l
left join (
select lotId, count(lotOccupancyId) as lotOccupancyCount from LotOccupancies
where recordDelete_timeMillis is null
and occupancyStartDate <= ${currentDate}
and (occupancyEndDate is null or occupancyEndDate >= ${currentDate})
group by lotId
) o on l.lotId = o.lotId
${sqlWhereClause}`
)
.get(sqlParameters).recordCount
}

View File

@ -940,9 +940,11 @@ function importFromWorkOrderCSV() {
}
console.timeEnd('importFromWorkOrderCSV');
}
console.log('Started ' + (new Date().toLocaleString()));
console.time('importFromCsv');
purgeTables();
importFromMasterCSV();
importFromPrepaidCSV();
importFromWorkOrderCSV();
console.timeEnd('importFromCsv');
console.log('Finished ' + (new Date().toLocaleString()));

View File

@ -1639,6 +1639,7 @@ function importFromWorkOrderCSV(): void {
console.timeEnd('importFromWorkOrderCSV')
}
console.log('Started ' + (new Date().toLocaleString()))
console.time('importFromCsv')
purgeTables()
@ -1648,3 +1649,4 @@ importFromPrepaidCSV()
importFromWorkOrderCSV()
console.timeEnd('importFromCsv')
console.log('Finished ' + (new Date().toLocaleString()))