Skip to content

Commit

Permalink
People API: Convert null result to an empty array (#633)
Browse files Browse the repository at this point in the history
* Handle `null` People results

* Improve logic and documentation

* Update person.ts
  • Loading branch information
jeffdaley authored Mar 5, 2024
1 parent b09f182 commit 1d7658d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion web/app/serializers/person.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,21 @@ export default class PersonSerializer extends JSONSerializer {
normalizeResponse(
_store: DS.Store,
_primaryModelClass: any,
payload: GoogleUser[] | { results: GoogleUser[] },
payload: GoogleUser[] | { results: GoogleUser[] | null },
_id: string | number,
requestType: string,
) {
const type = "person";

if (requestType === "query") {
assert("results are expected for query requests", "results" in payload);

/**
* If the results are `null`, return an empty array to show
* the "No results found" message in the PeopleSelect.
*/
if (!payload.results) return { data: [] };

const people = payload.results.map((p: any) => {
return {
id: p.emailAddresses[0].value,
Expand Down

0 comments on commit 1d7658d

Please sign in to comment.