Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
corps-directory
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
fhurtado14
corps-directory
Merge requests
!8
Feature/activity logger
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Feature/activity logger
feature/activity-logger
into
main
Overview
0
Commits
9
Pipelines
0
Changes
4
Merged
fhurtado14
requested to merge
feature/activity-logger
into
main
5 months ago
Overview
0
Commits
9
Pipelines
0
Changes
4
Expand
0
0
Merge request reports
Viewing commit
c4860d1f
Prev
Next
Show latest version
4 files
+
486
−
9
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
4
Search (e.g. *.vue) (Ctrl+P)
c4860d1f
Working repository classes with most functionality complete.
· c4860d1f
Federico Hurtado
authored
5 months ago
backend/repository/addressRepository.js
+
64
−
1
Options
@@ -62,6 +62,69 @@ async function addAddress(address, peopleId) {
}
}
async
function
updateAddress
()
{
console
.
log
(
"
Update address not implemented!
"
);
}
/*
Function to find all address information associated with a person.
Returns an array of address objects or an empty array if no addresses exist.
*/
async
function
getAddressesForPerson
(
peopleId
)
{
console
.
log
(
"
Finding addresses for person with ID:
"
,
peopleId
);
try
{
const
query
=
`
SELECT
a.addressId,
a.address1,
a.address2,
a.city,
sl.name AS state,
cl.name AS country,
a.zipCode,
pa.preferredAddress
FROM
peopleXAddress pa
LEFT JOIN
address a ON pa.addressId = a.addressId
LEFT JOIN
stateLookup sl ON a.stateId = sl.stateId
LEFT JOIN
countryLookup cl ON a.countryId = cl.countryId
WHERE
pa.peopleId = ?;
`
;
// Execute the query
const
[
results
]
=
await
pool
.
query
(
query
,
[
peopleId
]);
if
(
results
.
length
===
0
)
{
console
.
log
(
"
No addresses found for person with ID:
"
,
peopleId
);
return
[];
}
// Map the results to structured address objects
const
addresses
=
results
.
map
((
row
)
=>
({
addressId
:
row
.
addressId
,
address1
:
row
.
address1
,
address2
:
row
.
address2
,
city
:
row
.
city
,
state
:
row
.
state
,
country
:
row
.
country
,
zipCode
:
row
.
zipCode
,
preferredAddress
:
row
.
preferredAddress
,
}));
console
.
log
(
"
Found addresses:
"
,
addresses
);
return
addresses
;
}
catch
(
error
)
{
console
.
error
(
"
Error fetching addresses for person:
"
,
error
);
return
[];
}
}
// Private helper function to look up the stateId
async
function
_lookupStateId
(
state
)
{
// for now return 1 while tables are not populated
@@ -106,4 +169,4 @@ async function _lookupCountryId(country) {
// }
}
module
.
exports
=
{
addAddress
};
module
.
exports
=
{
addAddress
,
getAddressesForPerson
};
Loading