53 lines
2.3 KiB
JavaScript
53 lines
2.3 KiB
JavaScript
import { dateIntegerToString } from '@cityssm/utils-datetime';
|
|
import getContractComments from './getContractComments.js';
|
|
import getContractFees from './getContractFees.js';
|
|
import getContractFields from './getContractFields.js';
|
|
// import getContractOccupants from './getContractOccupants.js'
|
|
import getContractTransactions from './getContractTransactions.js';
|
|
import { getWorkOrders } from './getWorkOrders.js';
|
|
import { acquireConnection } from './pool.js';
|
|
export default async function getContract(contractId, connectedDatabase) {
|
|
const database = connectedDatabase ?? (await acquireConnection());
|
|
database.function('userFn_dateIntegerToString', dateIntegerToString);
|
|
const contract = database
|
|
.prepare(`select o.contractId,
|
|
o.contractTypeId, t.contractType,
|
|
o.burialSiteId,
|
|
l.burialSiteName,
|
|
l.burialSiteTypeId,
|
|
l.cemeteryId, m.cemeteryName,
|
|
o.contractStartDate, userFn_dateIntegerToString(o.contractStartDate) as contractStartDateString,
|
|
o.contractEndDate, userFn_dateIntegerToString(o.contractEndDate) as contractEndDateString,
|
|
o.recordUpdate_timeMillis
|
|
from Contracts o
|
|
left join ContractTypes t on o.contractTypeId = t.contractTypeId
|
|
left join BurialSites l on o.burialSiteId = l.burialSiteId
|
|
left join Maps m on l.cemeteryId = m.cemeteryId
|
|
where o.recordDelete_timeMillis is null
|
|
and o.contractId = ?`)
|
|
.get(contractId);
|
|
if (contract !== undefined) {
|
|
contract.contractFields = await getContractFields(contractId, database);
|
|
/*
|
|
contract.contractInterments = await getContractOccupants(
|
|
contractId,
|
|
database
|
|
)
|
|
*/
|
|
contract.contractComments = await getContractComments(contractId, database);
|
|
contract.contractFees = await getContractFees(contractId, database);
|
|
contract.contractTransactions = await getContractTransactions(contractId, { includeIntegrations: true }, database);
|
|
const workOrdersResults = await getWorkOrders({
|
|
contractId
|
|
}, {
|
|
limit: -1,
|
|
offset: 0
|
|
}, database);
|
|
contract.workOrders = workOrdersResults.workOrders;
|
|
}
|
|
if (connectedDatabase === undefined) {
|
|
database.release();
|
|
}
|
|
return contract;
|
|
}
|