in src/TransferVehicleOwnership.ts [54:71]
export async function findPrimaryOwnerForVehicle(txn: TransactionExecutor, vin: string): Promise<dom.Value> {
log(`Finding primary owner for vehicle with VIN: ${vin}`);
const query: string = "SELECT Owners.PrimaryOwner.PersonId FROM VehicleRegistration AS v WHERE v.VIN = ?";
let documentId: string = undefined;
await txn.execute(query, vin).then((result: Result) => {
const resultList: dom.Value[] = result.getResultList();
if (resultList.length === 0) {
throw new Error(`Unable to retrieve document ID using ${vin}.`);
}
const PersonIdValue: dom.Value = resultList[0].get("PersonId");
if (PersonIdValue === null) {
throw new Error(`Expected field name PersonId not found.`);
}
documentId = PersonIdValue.stringValue();
});
return findPersonFromDocumentId(txn, documentId);
}