Skip to content

Commit

Permalink
add check
Browse files Browse the repository at this point in the history
  • Loading branch information
suzalflueck committed Apr 29, 2024
1 parent 2fa81f5 commit f4517a9
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 89 deletions.
5 changes: 5 additions & 0 deletions frontend/src/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@ export function useSanitizeURL(input: string | String): String {
input = input.toLowerCase().replace(/^a-zA-Z0-9 ]/g, '')
return input
}

/** VALIDATION FUNCTIONS */
export function isValidDistrictNumber(input: string | String | number): boolean {
return !!input && input.toString().length === 3 && /^\d+$/.test(input.toString());
}
182 changes: 93 additions & 89 deletions frontend/src/views/DistrictView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ref, reactive, onMounted, computed, toValue } from 'vue'
import { useAppStore } from '@/stores/app'
import { useRoute } from 'vue-router'
import router from '@/router'
import { formatPhoneNumber } from '@/utils/common'
import { formatPhoneNumber, isValidDistrictNumber } from '@/utils/common'
import type { District, School, Grade, Address, Contact } from '@/types/types.d.ts'
import jsonexport from 'jsonexport/dist'
import { useSanitizeURL } from '@/composables/string'
Expand Down Expand Up @@ -78,97 +78,101 @@ function downloadDistrictSchools() {
onMounted(async () => {
const route = useRoute()
// Set the districtId inside the onMounted hook; null if districtId not found
districtId.value =
appStore.getDistrictByDistrictNumber(String(route.params.districtNumber))?.districtId ?? null
if (isValidDistrictNumber(String(route.params.districtNumber))) {
districtId.value =
appStore.getDistrictByDistrictNumber(String(route.params.districtNumber))?.districtId ?? null
}
// get district data
try {
const response = await InstituteService.getDistrictView(districtId.value as string)
if (response.data?.districtData?.contacts) {
district.value = response.data
contacts.value = response.data?.districtData?.contacts
schools.value = district.value?.districtSchools
if (!!districtId.value) {
try {
const response = await InstituteService.getDistrictView(districtId.value as string)
if (response.data?.districtData?.contacts) {
district.value = response.data
contacts.value = response.data?.districtData?.contacts
schools.value = district.value?.districtSchools
//Change School date for DL
const transformedSchoolData = schools.value.map((school: School) => {
const { contacts, addresses, ...rest } = school
const transformedContacts = contacts.map(({ schoolContactTypeCode, ...contactRest }) => ({
schoolContactTypeCode,
...contactRest
}))
const physicalAddress = addresses.find(
(address: Address) => address?.addressTypeCode === 'PHYSICAL'
)
const mailingAddress = addresses.find(
(address: Address) => address?.addressTypeCode === 'MAILING'
)
return {
...rest,
contacts: transformedContacts.reduce((acc, contact) => ({ ...acc, ...contact }), {}),
physicalAddress: physicalAddress,
mailingAddress: mailingAddress,
grades: [],
neighborhoodLearning: [],
schoolMove: []
}
})
//Change School data for DL
filteredSchools.value = transformedSchoolData.map((item: any) => {
return {
'District Number': response.data.districtData.districtNumber,
Mincode: item.mincode,
'Display Name': item.displayName,
'Mailing Address': item.mailingAddress?.addressLine1,
'Mailing Address Line2': item.mailingAddress?.addressLine2,
'Mailing Address City': item.mailingAddress?.city,
'Mailing Address Province': item.mailingAddress?.provinceCode,
'Mailing Address PostalCode': item.mailingAddress?.postal,
'Physical Address': item.physicalAddress?.addressLine1,
'Physical Address Line2': item.physicalAddress?.addressLine2,
'Physical Address City': item.physicalAddress?.city,
'Physical Address Province': item.physicalAddress?.provinceCode,
'Physical Address Postal Code': item.physicalAddress?.postal,
Role: item.contacts?.jobTitle,
'Contact First Name': item.contacts?.firstName,
'Contact Last Name': item.contacts?.lastName,
'Contact Phone Extension': item.contacts?.phoneExtension,
'Contact Phone Number': item.contacts?.phoneNumber,
'Facility Type Code': appStore.getFacilityCodeLabel(item.facilityTypeCode),
'School Category Code': appStore.getCategoryCodeLabel(item.schoolCategoryCode),
'Phone Number': item.phoneNumber,
Fax: item.faxNumber,
Email: item.email,
Website: item.website,
'Group Classification Primary K-3': item.primaryK3,
'Group Classification Elementary 4-7 EU': item.elementary47,
'Group Classification Junior Secondary 8-10 SU': item.juniorSecondary810,
'Group Classification Senior Secondary 11-12': item.seniorSecondary1112
}
})
filteredContacts.value = contacts.value.map((item: any) => {
return {
'District Number': response.data.districtData?.districtNumber,
'District Name': response.data.districtData?.displayName,
'Contact Type': item.label,
'Job Title': item.jobTitle,
'First Name': item.firstName,
'Last Name': item.lastName,
'Phone Number': item.phoneNumber,
'Phone Extension': item.phoneExtension,
'Alternate Phone Number': item.alternatePhoneNumber,
'Alternate Phone Extension': item.alternatePhoneExtension,
Email: item.email,
'Mailing Address': response.data.districtData?.addresses[0].addressLine1,
'Mailing City': response.data.districtData?.addresses[0].city,
'Mailing Province': response.data.districtData?.addresses[0].provinceCode,
'Mailing Postal Code': response.data.districtData?.addresses[0].postal,
'District Phone': response.data.districtData?.phoneNumber,
'District Fax': response.data.districtData?.faxNumber,
Website: response.data.districtData?.website
}
})
//Change School date for DL
const transformedSchoolData = schools.value.map((school: School) => {
const { contacts, addresses, ...rest } = school
const transformedContacts = contacts.map(({ schoolContactTypeCode, ...contactRest }) => ({
schoolContactTypeCode,
...contactRest
}))
const physicalAddress = addresses.find(
(address: Address) => address?.addressTypeCode === 'PHYSICAL'
)
const mailingAddress = addresses.find(
(address: Address) => address?.addressTypeCode === 'MAILING'
)
return {
...rest,
contacts: transformedContacts.reduce((acc, contact) => ({ ...acc, ...contact }), {}),
physicalAddress: physicalAddress,
mailingAddress: mailingAddress,
grades: [],
neighborhoodLearning: [],
schoolMove: []
}
})
//Change School data for DL
filteredSchools.value = transformedSchoolData.map((item: any) => {
return {
'District Number': response.data.districtData.districtNumber,
Mincode: item.mincode,
'Display Name': item.displayName,
'Mailing Address': item.mailingAddress?.addressLine1,
'Mailing Address Line2': item.mailingAddress?.addressLine2,
'Mailing Address City': item.mailingAddress?.city,
'Mailing Address Province': item.mailingAddress?.provinceCode,
'Mailing Address PostalCode': item.mailingAddress?.postal,
'Physical Address': item.physicalAddress?.addressLine1,
'Physical Address Line2': item.physicalAddress?.addressLine2,
'Physical Address City': item.physicalAddress?.city,
'Physical Address Province': item.physicalAddress?.provinceCode,
'Physical Address Postal Code': item.physicalAddress?.postal,
Role: item.contacts?.jobTitle,
'Contact First Name': item.contacts?.firstName,
'Contact Last Name': item.contacts?.lastName,
'Contact Phone Extension': item.contacts?.phoneExtension,
'Contact Phone Number': item.contacts?.phoneNumber,
'Facility Type Code': appStore.getFacilityCodeLabel(item.facilityTypeCode),
'School Category Code': appStore.getCategoryCodeLabel(item.schoolCategoryCode),
'Phone Number': item.phoneNumber,
Fax: item.faxNumber,
Email: item.email,
Website: item.website,
'Group Classification Primary K-3': item.primaryK3,
'Group Classification Elementary 4-7 EU': item.elementary47,
'Group Classification Junior Secondary 8-10 SU': item.juniorSecondary810,
'Group Classification Senior Secondary 11-12': item.seniorSecondary1112
}
})
filteredContacts.value = contacts.value.map((item: any) => {
return {
'District Number': response.data.districtData?.districtNumber,
'District Name': response.data.districtData?.displayName,
'Contact Type': item.label,
'Job Title': item.jobTitle,
'First Name': item.firstName,
'Last Name': item.lastName,
'Phone Number': item.phoneNumber,
'Phone Extension': item.phoneExtension,
'Alternate Phone Number': item.alternatePhoneNumber,
'Alternate Phone Extension': item.alternatePhoneExtension,
Email: item.email,
'Mailing Address': response.data.districtData?.addresses[0].addressLine1,
'Mailing City': response.data.districtData?.addresses[0].city,
'Mailing Province': response.data.districtData?.addresses[0].provinceCode,
'Mailing Postal Code': response.data.districtData?.addresses[0].postal,
'District Phone': response.data.districtData?.phoneNumber,
'District Fax': response.data.districtData?.faxNumber,
Website: response.data.districtData?.website
}
})
}
} catch (error) {
console.error(error)
}
} catch (error) {
console.error(error)
}
// get district contact type codes
// try {
Expand Down

0 comments on commit f4517a9

Please sign in to comment.