ggez-banking-sdk
Version:
A Node.js package to handle GGEZ Banking API endpoints, Simplify the process of managing CRUD operations with this efficient and easy-to-use package.
120 lines (119 loc) • 4.11 kB
JavaScript
import { DeviceType, EntityStatus, EntityVerificationStatus, DocumentType, SecurityAuthenticationTypes, SecurityLoginType, } from "../../../constant";
import { ClientHelper, DateTimeHelper, UserHelper } from "../../../helper";
import { getBase64 } from "../../../utils";
import { createDefaultUserData } from "./userDefaults";
export { createDefaultUserData, fillCreateUserData, fillCreateUserWithGoogleData };
const fillCreateUserData = (data) => {
const clientHelper = new ClientHelper();
const personalInfo = {
title: data.title,
first_name: data.firstName,
last_name: data.lastName,
date_of_birth: data.dateOfBirth,
gender: String(data.gender),
verification_status: EntityVerificationStatus.Verified,
};
const address = {
country_code: data.country,
state_region: data.state,
verification_status: EntityVerificationStatus.Not_Verified,
};
const device = {
type: DeviceType.Browser,
brand: `${clientHelper.getBrowser()}-${clientHelper.getBrowserVersion()}`,
os: clientHelper.getOS(),
status: EntityStatus.Active,
verification_status: data.deviceVerificationStatus,
installation_id: data.installationID,
extended_info: {
cpu: clientHelper.getCPU(),
system_language: clientHelper.getSystemLanguage(),
user_agent: clientHelper.getUserAgent(),
},
};
const userData = createDefaultUserData({
personal_info: personalInfo,
address: address,
email: [
{
id: 0,
address: data.email,
is_primary: 1,
verification_status: EntityVerificationStatus.Verified,
},
],
authentication: [],
security: {
password: data.password,
},
preferences: {
preferred_language_code: data.preferredLanguageCode,
enable_promotion_notification: "1",
enable_email_notification: "1",
enable_sms_notification: "1",
enable_push_notification: "1",
enable_device_authentication: "1",
time_zone: DateTimeHelper.getClientTimeZone(),
},
currency: [
{
id: 0,
code: data.currency,
is_primary: 0,
},
],
terms_conditions: {
id: 0,
acceptance: "1",
},
device: [device],
custom_field: UserHelper.fillPromotionData({
giftData: data.giftData,
referralCode: data.referralCode,
referralCodeType: data.referralCodeType,
}),
});
// if (data.isMobileConfirmed && data.mobileAuthenticationCode) {
// userData.authentication.push({
// type: SecurityAuthenticationTypes.SMS_Code,
// code: data.mobileAuthenticationCode,
// });
// }
if (data.emailAuthenticationCode) {
userData.authentication.push({
type: SecurityAuthenticationTypes.Email_Code,
code: data.emailAuthenticationCode,
});
}
return userData;
};
const fillCreateUserWithGoogleData = async (data) => {
const base64 = await getBase64(data.picture);
const userData = fillCreateUserData(data);
const externalAuth = {
id: 0,
login_id: data.loginId,
token: data.token,
status: EntityStatus.Active,
type: SecurityLoginType.Google,
verification_status: EntityVerificationStatus.Verified,
};
userData.external_auth = [externalAuth];
if (base64) {
const documentData = {
info: {
type: DocumentType.Profile_Picture,
subject: "Profile Picture",
},
attachment: [
{
file_name: data.loginId,
file_extension: ".jpg",
content: base64,
},
],
};
userData.documents = [documentData];
}
return userData;
};