Skip to content

Instantly share code, notes, and snippets.

@fernandocamargo
Last active January 5, 2018 10:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fernandocamargo/26144729f16bfa7312f830e002befbbf to your computer and use it in GitHub Desktop.
Save fernandocamargo/26144729f16bfa7312f830e002befbbf to your computer and use it in GitHub Desktop.
import { pick } from 'ramda';
import {
ALREADY_EXISTS,
COMMUNICATION_ID_NOT_FOUND,
GENERAL_SIGNUP_ERROR,
} from 'constants/signUp';
import {
ATTRACTION_ALREADY_ASSIGNED_TO_COMMUNICATION_ID as ALREADY_EXISTS_ERROR_CODE,
COMMUNICATION_ID_NOT_FOUND as COMMUNICATION_ID_NOT_FOUND_ERROR_CODE,
} from 'common/enum/ErrorCode';
import * as API from 'api';
export const translate = code =>
({
[ALREADY_EXISTS_ERROR_CODE]: ALREADY_EXISTS,
[COMMUNICATION_ID_NOT_FOUND_ERROR_CODE]: COMMUNICATION_ID_NOT_FOUND,
}[code] || GENERAL_SIGNUP_ERROR);
export const using = pick(['communicationId', 'name', 'email', 'password']);
export const getErrorFrom = ({ error: { errorCode } }) => translate(errorCode);
export const deny = response => Promise.reject(getErrorFrom(response));
export const allow = response => Promise.resolve(response);
export const check = response => (response.error ? deny : allow)(response);
export const signUp = data => API.signUp(using(data)).then(check);
export default {
signUp,
};
import { pick } from 'ramda';
import {
ALREADY_EXISTS,
COMMUNICATION_ID_NOT_FOUND,
GENERAL_SIGNUP_ERROR,
} from 'constants/signUp';
import {
ATTRACTION_ALREADY_ASSIGNED_TO_COMMUNICATION_ID as ALREADY_EXISTS_ERROR_CODE,
COMMUNICATION_ID_NOT_FOUND as COMMUNICATION_ID_NOT_FOUND_ERROR_CODE,
} from 'common/enum/ErrorCode';
import * as api from 'api';
const errorCodesToConstants = {
[ALREADY_EXISTS_ERROR_CODE]: ALREADY_EXISTS,
[COMMUNICATION_ID_NOT_FOUND_ERROR_CODE]: COMMUNICATION_ID_NOT_FOUND,
};
const pickSignUpData = pick(['communicationId', 'name', 'email', 'password']);
export default {
// load: ({ params: { activationCode } }) =>
// activationCode && api.userActivate(activationCode),
signUp: data =>
api
.signUp(pickSignUpData(data))
.then(
response =>
response.error
? Promise.reject(
errorCodesToConstants[response.error.errorCode] ||
GENERAL_SIGNUP_ERROR,
)
: Promise.resolve(response),
),
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment