UNPKG

@fontoxml/fontoxml-development-tools

Version:

Development tools for Fonto.

56 lines (47 loc) 1.14 kB
import ProfileResultStatus from './ProfileResultStatus.js'; /** * Maps the values present in the status field of a ProfileResult to a HTTP status code. * * @param {string} status * * @return {number} */ function mapProfileResultStatusToHttpStatusCode(status) { switch (status) { case ProfileResultStatus.OK: return 200; case ProfileResultStatus.FORBIDDEN: return 403; case ProfileResultStatus.NOT_FOUND: return 404; default: return 500; } } /** * Maps the profile result objects to objects that can be parsed by the client. * * @param {Result} result * * @return {object} */ export default function mapProfileResult(result) { const profileToReturn = { profileId: result.profileId, status: mapProfileResultStatusToHttpStatusCode(result.status), }; if (result.profile) { const { displayName, headline, avatars } = result.profile; const profileBody = { displayName, }; if (headline) { profileBody['headline'] = headline; } if (avatars) { profileBody['avatarVariants'] = Object.keys(avatars); } profileToReturn['body'] = profileBody; } return profileToReturn; }