get work order
parent
c2ae19f4a6
commit
f76f41ef63
|
|
@ -9,6 +9,7 @@ interface GetLotOccupanciesFilters {
|
|||
mapId?: number | string;
|
||||
lotName?: string;
|
||||
lotTypeId?: number | string;
|
||||
workOrderId?: number | string;
|
||||
}
|
||||
interface GetLotOccupanciesOptions {
|
||||
limit: -1 | number;
|
||||
|
|
|
|||
|
|
@ -60,6 +60,10 @@ export const getLotOccupancies = (filters, options, connectedDatabase) => {
|
|||
sqlWhereClause += " and l.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" +
|
||||
" from LotOccupancies o" +
|
||||
" left join Lots l on o.lotId = l.lotId" +
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ interface GetLotOccupanciesFilters {
|
|||
mapId ? : number | string;
|
||||
lotName ? : string;
|
||||
lotTypeId ? : number | string;
|
||||
workOrderId?: number | string;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -117,6 +118,11 @@ export const getLotOccupancies = (filters: GetLotOccupanciesFilters,
|
|||
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" +
|
||||
" from LotOccupancies o" +
|
||||
" left join Lots l on o.lotId = l.lotId" +
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ interface GetLotsFilters {
|
|||
lotTypeId?: number | string;
|
||||
lotStatusId?: number | string;
|
||||
occupancyStatus?: "" | "occupied" | "unoccupied";
|
||||
workOrderId?: number | string;
|
||||
}
|
||||
interface GetLotsOptions {
|
||||
limit: number;
|
||||
|
|
|
|||
|
|
@ -35,6 +35,10 @@ export const getLots = (filters, options, connectedDatabase) => {
|
|||
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 count = database.prepare("select count(*) as recordCount" +
|
||||
" from Lots l" +
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ interface GetLotsFilters {
|
|||
lotTypeId ? : number | string;
|
||||
lotStatusId ? : number | string;
|
||||
occupancyStatus ? : "" | "occupied" | "unoccupied";
|
||||
workOrderId ? : number | string;
|
||||
}
|
||||
|
||||
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 count: number = database.prepare("select count(*) as recordCount" +
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
import type * as recordTypes from "../../types/recordTypes";
|
||||
export declare const getWorkOrder: (workOrderId: number | string) => recordTypes.WorkOrder;
|
||||
export default getWorkOrder;
|
||||
|
|
@ -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;
|
||||
|
|
@ -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;
|
||||
Loading…
Reference in New Issue