Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mirage cleanup (People route) #639

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 25 additions & 44 deletions web/mirage/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ export default function (mirageConfig) {
* Jira requests
*
*************************************************************************/

// Get issue
this.get("/jira/issues/:issue_id", (schema, request) => {
const issue = schema.jiraIssues.findBy({
Expand Down Expand Up @@ -789,32 +790,12 @@ export default function (mirageConfig) {

/*************************************************************************
*
* HEAD requests
* People
*
*************************************************************************/

this.head("/me", (schema, _request) => {
let isLoggedIn = schema.db.me[0].isLoggedIn;

if (isLoggedIn) {
return new Response(200, {});
} else {
return new Response(401, {});
}
});

/*************************************************************************
*
* POST requests
*
*************************************************************************/

/**
* Used by the `PeopleSelect` component to query for people
* without exposing personal information like a GET request might.
*/
// Query via the PeopleSelect
this.post("/people", (schema, request) => {
// Grab the query from the request body
let query: string = JSON.parse(request.requestBody).query;

// Search everyone's first emailAddress for matches
Expand All @@ -831,6 +812,28 @@ export default function (mirageConfig) {
return new Response(200, {}, matches.models);
});

/*************************************************************************
*
* HEAD requests
*
*************************************************************************/

this.head("/me", (schema, _request) => {
let isLoggedIn = schema.db.me[0].isLoggedIn;

if (isLoggedIn) {
return new Response(200, {});
} else {
return new Response(401, {});
}
});

/*************************************************************************
*
* POST requests
*
*************************************************************************/

/**
* Used when publishing a draft for review.
* Updates the document's status and isDraft properties.
Expand Down Expand Up @@ -951,28 +954,6 @@ export default function (mirageConfig) {
}
});

/**
* Used by the PeopleSelect component to get a list of people.
* Used to confirm that an approver has access to a document.
*/
this.get("/people", (schema, request) => {
if (request.queryParams.emails !== "") {
const emails = request.queryParams.emails.split(",");

if (emails.length === 0) {
return new Response(200, {}, []);
}

const hermesUsers = emails.map((email: string) => {
return { emailAddresses: [{ value: email }], photos: [] };
});

return new Response(200, {}, hermesUsers);
}

return schema.people.all();
});

/**
* Used by the Document route to get a document.
*/
Expand Down
Loading