in src/AddSecondaryOwner.ts [71:96]
export async function isSecondaryOwnerForVehicle(
txn: TransactionExecutor,
vin: string,
secondaryOwnerId: string
): Promise<boolean> {
log(`Finding secondary owners for vehicle with VIN: ${vin}`);
const query: string = "SELECT Owners.SecondaryOwners FROM VehicleRegistration AS v WHERE v.VIN = ?";
let doesExist: boolean = false;
await txn.execute(query, vin).then((result: Result) => {
const resultList: dom.Value[] = result.getResultList();
resultList.forEach((value: dom.Value) => {
const secondaryOwnersList: dom.Value[] = value.get("SecondaryOwners").elements();
secondaryOwnersList.forEach((secondaryOwner) => {
const personId: dom.Value = secondaryOwner.get("PersonId");
if (personId !== null && personId.stringValue() === secondaryOwnerId) {
doesExist = true;
}
});
});
});
return doesExist;
}