get work order

deepsource-autofix-76c6eb20
Dan Gowans 2022-08-31 10:20:40 -04:00
parent c2ae19f4a6
commit f76f41ef63
9 changed files with 132 additions and 0 deletions

View File

@ -9,6 +9,7 @@ interface GetLotOccupanciesFilters {
mapId?: number | string; mapId?: number | string;
lotName?: string; lotName?: string;
lotTypeId?: number | string; lotTypeId?: number | string;
workOrderId?: number | string;
} }
interface GetLotOccupanciesOptions { interface GetLotOccupanciesOptions {
limit: -1 | number; limit: -1 | number;

View File

@ -60,6 +60,10 @@ export const getLotOccupancies = (filters, options, connectedDatabase) => {
sqlWhereClause += " and l.lotTypeId = ?"; sqlWhereClause += " and l.lotTypeId = ?";
sqlParameters.push(filters.lotTypeId); sqlParameters.push(filters.lotTypeId);
} }
if (filters.workOrderId) {
sqlWhereClause += " and o.lotOccupancyId in (select lotOccupancyId from WorkOrderLotOccupancies where recordDelete_timeMillis is null and workOrderId = ?)";
sqlParameters.push(filters.workOrderId);
}
const count = database.prepare("select count(*) as recordCount" + const count = database.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" +

View File

@ -26,6 +26,7 @@ interface GetLotOccupanciesFilters {
mapId ? : number | string; mapId ? : number | string;
lotName ? : string; lotName ? : string;
lotTypeId ? : number | string; lotTypeId ? : number | string;
workOrderId?: number | string;
} }
@ -117,6 +118,11 @@ export const getLotOccupancies = (filters: GetLotOccupanciesFilters,
sqlParameters.push(filters.lotTypeId); sqlParameters.push(filters.lotTypeId);
} }
if (filters.workOrderId) {
sqlWhereClause += " and o.lotOccupancyId in (select lotOccupancyId from WorkOrderLotOccupancies where recordDelete_timeMillis is null and workOrderId = ?)";
sqlParameters.push(filters.workOrderId);
}
const count: number = database.prepare("select count(*) as recordCount" + const count: number = database.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" +

View File

@ -6,6 +6,7 @@ interface GetLotsFilters {
lotTypeId?: number | string; lotTypeId?: number | string;
lotStatusId?: number | string; lotStatusId?: number | string;
occupancyStatus?: "" | "occupied" | "unoccupied"; occupancyStatus?: "" | "occupied" | "unoccupied";
workOrderId?: number | string;
} }
interface GetLotsOptions { interface GetLotsOptions {
limit: number; limit: number;

View File

@ -35,6 +35,10 @@ export const getLots = (filters, options, connectedDatabase) => {
sqlWhereClause += " and (lotOccupancyCount is null or lotOccupancyCount = 0)"; sqlWhereClause += " and (lotOccupancyCount is null or lotOccupancyCount = 0)";
} }
} }
if (filters.workOrderId) {
sqlWhereClause += " and l.lotId in (select lotId from WorkOrderLots where recordDelete_timeMillis is null and workOrderId = ?)";
sqlParameters.push(filters.workOrderId);
}
const currentDate = dateToInteger(new Date()); const currentDate = dateToInteger(new Date());
const count = database.prepare("select count(*) as recordCount" + const count = database.prepare("select count(*) as recordCount" +
" from Lots l" + " from Lots l" +

View File

@ -19,6 +19,7 @@ interface GetLotsFilters {
lotTypeId ? : number | string; lotTypeId ? : number | string;
lotStatusId ? : number | string; lotStatusId ? : number | string;
occupancyStatus ? : "" | "occupied" | "unoccupied"; occupancyStatus ? : "" | "occupied" | "unoccupied";
workOrderId ? : number | string;
} }
interface GetLotsOptions { interface GetLotsOptions {
@ -72,6 +73,11 @@ export const getLots = (filters: GetLotsFilters,
} }
} }
if (filters.workOrderId) {
sqlWhereClause += " and l.lotId in (select lotId from WorkOrderLots where recordDelete_timeMillis is null and workOrderId = ?)";
sqlParameters.push(filters.workOrderId);
}
const currentDate = dateToInteger(new Date()); const currentDate = dateToInteger(new Date());
const count: number = database.prepare("select count(*) as recordCount" + const count: number = database.prepare("select count(*) as recordCount" +

View File

@ -0,0 +1,3 @@
import type * as recordTypes from "../../types/recordTypes";
export declare const getWorkOrder: (workOrderId: number | string) => recordTypes.WorkOrder;
export default getWorkOrder;

View File

@ -0,0 +1,40 @@
import sqlite from "better-sqlite3";
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
import { dateIntegerToString } from "@cityssm/expressjs-server-js/dateTimeFns.js";
import { getLots } from "./getLots.js";
import { getLotOccupancies } from "./getLotOccupancies.js";
export const getWorkOrder = (workOrderId) => {
const database = sqlite(databasePath, {
readonly: true
});
database.function("userFn_dateIntegerToString", dateIntegerToString);
const workOrder = database
.prepare("select w.workOrderId," +
" w.workOrderTypeId, t.workOrderType," +
" w.workOrderNumber, w.workOrderDescription," +
" w.workOrderOpenDate, userFn_dateIntegerToString(w.workOrderOpenDate) as workOrderOpenDateString," +
" w.workOrderCloseDate, userFn_dateIntegerToString(w.workOrderCloseDate) as workOrderCloseDateString" +
" from WorkOrders w" +
" left join WorkOrderTypes t on w.workOrderTypeId = t.workOrderTypeId" +
" where w.recordDelete_timeMillis is null" +
" and w.workOrderId = ?")
.get(workOrderId);
if (workOrder) {
workOrder.workOrderLots = getLots({
workOrderId: workOrder.workOrderId
}, {
limit: -1,
offset: 0
}, database).lots;
workOrder.workOrderLotOccupancies = getLotOccupancies({
workOrderId: workOrder.workOrderId
}, {
limit: -1,
offset: 0,
includeOccupants: true
}, database).lotOccupancies;
}
database.close();
return workOrder;
};
export default getWorkOrder;

View File

@ -0,0 +1,67 @@
import sqlite from "better-sqlite3";
import {
lotOccupancyDB as databasePath
} from "../../data/databasePaths.js";
import {
dateIntegerToString
} from "@cityssm/expressjs-server-js/dateTimeFns.js";
import {
getLots
} from "./getLots.js";
import {
getLotOccupancies
} from "./getLotOccupancies.js";
import type * as recordTypes from "../../types/recordTypes";
export const getWorkOrder = (workOrderId: number | string): recordTypes.WorkOrder => {
const database = sqlite(databasePath, {
readonly: true
});
database.function("userFn_dateIntegerToString", dateIntegerToString);
const workOrder: recordTypes.WorkOrder = database
.prepare("select w.workOrderId," +
" w.workOrderTypeId, t.workOrderType," +
" w.workOrderNumber, w.workOrderDescription," +
" w.workOrderOpenDate, userFn_dateIntegerToString(w.workOrderOpenDate) as workOrderOpenDateString," +
" w.workOrderCloseDate, userFn_dateIntegerToString(w.workOrderCloseDate) as workOrderCloseDateString" +
" from WorkOrders w" +
" left join WorkOrderTypes t on w.workOrderTypeId = t.workOrderTypeId" +
" where w.recordDelete_timeMillis is null" +
" and w.workOrderId = ?")
.get(workOrderId);
if (workOrder) {
workOrder.workOrderLots = getLots({
workOrderId: workOrder.workOrderId
}, {
limit: -1,
offset: 0
}, database).lots;
workOrder.workOrderLotOccupancies = getLotOccupancies({
workOrderId: workOrder.workOrderId
}, {
limit: -1,
offset: 0,
includeOccupants: true
}, database).lotOccupancies;
}
database.close();
return workOrder;
};
export default getWorkOrder;