Skip to content

Commit 8ca8399

Browse files
committed
Bugfix: Adoptions and Fosters now show only relevant events
1 parent d239c16 commit 8ca8399

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

src/client/src/pages/DataView360/View/View.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class View360 extends Component {
6767
let fosterEvents = {};
6868

6969
for (let id of animalIds) {
70-
this.getAnimalEvents(id).then((events) => {
70+
this.getAnimalEvents(id, this.state.matchId).then((events) => {
7171
adoptionEvents[id] = _.filter(events[id], function(e) {
7272
return e["Type"] && e["Type"].toLowerCase().includes("adopt");
7373
});
@@ -86,8 +86,8 @@ class View360 extends Component {
8686
});
8787
}
8888

89-
async getAnimalEvents(animalId) {
90-
let response = await fetch(`/api/animal/${animalId}/events`);
89+
async getAnimalEvents(animalId, matchId) {
90+
let response = await fetch(`/api/person/${matchId}/animal/${animalId}/events`);
9191
return await response.json()
9292
}
9393

src/client/src/pages/DataView360/View/components/AnimalInfo.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,17 @@ const PET_COUNT = 5;
3737
class AnimalInfo extends Component {
3838

3939
getLatestPets(petObject, events) {
40+
4041
function customizer(objValue, srcValue) {
4142
if (_.isObject(objValue) && _.isObject(srcValue)) {
4243
// sort according to date of most recent event
4344
return _.set(objValue, 'Events', _.orderBy(srcValue, ['Time'], ['desc']));
4445
}
4546
}
46-
// force null values to back of list because
47-
// _.orderBy descending places null values first
48-
// see: https://github.com/lodash/lodash/issues/4169
47+
4948
let result = _.mergeWith(petObject, events, customizer);
50-
let emptyEvents = _.filter(result, function(pet) { return pet["Events"] && pet["Events"].length === 0 });
5149
let nonEmptyEvents = _.filter(result, function(pet) { return pet["Events"] && pet["Events"].length > 0 });
52-
result = [..._.orderBy(nonEmptyEvents, ['Events[0].Time'], ['desc']), ...emptyEvents]
50+
result = [..._.orderBy(nonEmptyEvents, ['Events[0].Time'], ['desc'])]
5351
return result.slice(0, PET_COUNT);
5452
}
5553

src/server/api/common_api.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,26 @@ def get_animal_events(animal_id):
109109
animal_url = f"http://shelterluv.com/api/v1/animals/{animal_id}/events"
110110
event_details = requests.get(animal_url, headers={"x-api-key": SHELTERLUV_SECRET_TOKEN}).json()
111111
result[animal_id] = event_details["events"]
112+
return result
113+
114+
115+
@common_api.route('/api/person/<matching_id>/animal/<animal_id>/events', methods=['GET'])
116+
def get_person_animal_events(matching_id, animal_id):
117+
result = {}
118+
events = []
119+
with engine.connect() as connection:
120+
query = text("select * from pdp_contacts where matching_id = :matching_id and source_type = 'shelterluvpeople' and archived_date is null")
121+
query_result = connection.execute(query, matching_id=matching_id)
122+
rows = [dict(row) for row in query_result]
123+
if len(rows) > 0:
124+
row = rows[0]
125+
shelterluv_id = row["source_id"]
126+
animal_url = f"http://shelterluv.com/api/v1/animals/{animal_id}/events"
127+
event_details = requests.get(animal_url, headers={"x-api-key": SHELTERLUV_SECRET_TOKEN}).json()
128+
for event in event_details["events"]:
129+
for record in event["AssociatedRecords"]:
130+
if record["Type"] == "Person" and record["Id"] == shelterluv_id:
131+
events.append(event)
132+
result[animal_id] = events
133+
112134
return result

0 commit comments

Comments
 (0)