UNPKG

@churchapps/helpers

Version:

Library of helper functions not specific to any one ChurchApps project or framework.

84 lines 3.33 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PersonHelper = void 0; const CommonEnvironmentHelper_1 = require("./CommonEnvironmentHelper"); class PersonHelper { static getPhotoPath(churchId, person) { if (!person.photoUpdated) { if (person.id?.startsWith("PER0000")) return "https://app.staging.chums.org/images/demo/avatars/" + person.id + ".svg"; else return ""; } else return "/" + churchId + "/membership/people/" + person.id + ".png?dt=" + person.photoUpdated.getTime().toString(); } static getPhotoUrl(person) { if (!person?.photo) return "/images/sample-profile.png"; else { return (person?.photo?.startsWith("data:image/png;base64,") || person.photo?.indexOf("://") > -1) ? person.photo : CommonEnvironmentHelper_1.CommonEnvironmentHelper.ContentRoot + person.photo; } } static getAge(birthdate) { if (birthdate !== undefined && birthdate !== null) { let ageDifMs = Date.now() - new Date(birthdate).getTime(); let ageDate = new Date(ageDifMs); let years = Math.abs(ageDate.getUTCFullYear() - 1970); return years + " years"; } else return ""; } static getDisplayNameFromPerson(person) { if (person?.name?.nick !== null && person?.name?.nick !== "" && person?.name?.nick !== undefined) return person.name.first + " \"" + person.name.nick + "\" " + person.name.last; else return person.name.first + " " + person.name.last; } static getDisplayName(firstName, lastName, nickName) { if (nickName !== undefined && nickName !== null && nickName.length > 0) return firstName + ' "' + nickName + '" ' + lastName; else return firstName + " " + lastName; } static getBirthMonth(birthdate) { if (birthdate) return new Date(birthdate).getMonth() + 1; else return -1; } static compareAddress(address1, address2) { const displayAddress1 = this.addressToString(address1).trim(); const displayAddress2 = this.addressToString(address2).trim(); if (displayAddress1 !== displayAddress2) { return true; } return false; } static addressToString(address) { return `${address.address1 || ""} ${address.address2 || ""} ${address.city || ""}${(address.city && address.state) ? "," : ""} ${address.state || ""} ${address.zip || ""}`; } static changeOnlyAddress(contactInfo1, contactInfo2) { const updatedAddress = { ...contactInfo1, address1: contactInfo2.address1, address2: contactInfo2.address2, city: contactInfo2.city, state: contactInfo2.state, zip: contactInfo2.zip }; return updatedAddress; } static checkAddressAvailabilty(person) { const addressString = this.addressToString(person.contactInfo).trim(); if (addressString !== "") { return true; } return false; } } exports.PersonHelper = PersonHelper; //# sourceMappingURL=PersonHelper.js.map