Repository URL to install this package:
|
Version:
1.1.13 ▾
|
import { autofixSafe, isTrue, toBoolean, isSafe } from 'uxui-modules/exotic';
import { getTyped } from 'uxui-modules/composition';
// const transformAddressInfo = data => {
// const { string } = getTyped(data)
// return {
// addressid: string('addressid'),
// }
// }
const transformGenericInfo = addressinfoDetails => {
const { array, string, boolean, obj } = getTyped(addressinfoDetails);
const transformed = {
additionaldetails: array('additionaldetails'),
addressid: string('addressid'),
addressline1: string('addressline1'),
addressline2: string('addressline2'),
addresstype: string('addresstype'),
city: string('city'),
country: string('country'),
email: string('email'),
// @todo fullname
firstname: string('firstname'),
lastname: string('lastname'),
// @todo - this also doesn't work on card.....
// isDefaultItem: boolean('isdefaultaddress') || boolean('isdefault'),
isdefaultaddress: boolean('isdefaultaddress') || boolean('isdefault'),
phonedetails: array('phonedetails'),
// isn't state an obj? (note in this place, it's string for address state!)
state: string('state'),
// @note this is a string!
zipcode: string('zipcode'),
};
return autofixSafe(transformed);
};
const toDefaultAddress = address => {
if (isTrue(toBoolean(address.isdefaultaddress))) {
return address;
} else {
return '';
}
};
const toCard = card => {
return card;
};
const toDefaultCard = card => {
if (isTrue(toBoolean(card.isdefault))) {
return card;
} else {
return '';
}
};
// const transformCard = cards => {
// const { array, string, obj } = getTyped(cards)
// return {
// cards: array(cards).map(toCard),
// defaultCard: array(cards).filter(toDefaultCard).map(toCard),
// }
// }
const toSecurityQuestion = userinfo => {
const { array, string, obj } = getTyped(userinfo);
if (isSafe(userinfo.securityquestion)) {
return {
securityquestion: userinfo.securityquestion,
securityanswer: userinfo.securityanswer,
};
}
return {};
};
const toAddressinfo = addressinfo => {
const generic = transformGenericInfo(addressinfo);
return generic;
};
const transformUser = response => {
const { any, array, obj, float, string } = getTyped(response);
// const userSerialized = oneStorage.get('user-serial-info')
// const preferencesSerialized = oneStorage.set('preferences-serial-info')
// const profile-info = { 'userSerialized': userSerialized, 'preferencesSerialized': preferencesSerialized }
const user = {
type: any('type'),
// lol -.-
responseMessage: string('Get Profile Success'),
// cardList
cards: array('properties.creditcardinfo.cards').map(toCard),
// probably we want like .address.shippingList & .payment.cardList
// this one can be computed
// addressList
// addressinfo: array('properties.userinfo.0.addressinfo').map(toAddressinfo),
// don't think we need this?
// this is a confusing conflict for user because bad naming of "province"
state: obj('properties.state'),
// what else is in userinfo o.o ?
userinfo: obj('properties.userinfo.0'),
// number
responseCode: string('0'),
// @todo should be computed
// defaultCard: array('properties.creditcardinfo.cards').filter(toDefaultCard),
security: array('properties.userinfo').map(toSecurityQuestion),
cookies: array('cookies'),
};
const autofixed = autofixSafe(user);
return autofixed;
};
const transformPaymentStatus = response => {
if(!(response.properties.state.status)) {
// response status is not received when call fails
// hence adding static status responseMessage for failure
response.properties.state.status = 'failure - something went wrong in payment'
}
return response
}
export { toDefaultAddress, toDefaultCard, toSecurityQuestion, toAddressinfo };
export { transformUser, transformPaymentStatus };
export default transformUser;