@xuda.io/account_module 1.2.1076 → 1.2.1077
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.mjs +67 -1
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -2472,8 +2472,74 @@ export const create_account_profile = async function (req, job_id, headers) {
|
|
|
2472
2472
|
|
|
2473
2473
|
export const update_account_profile = async function (req, job_id, headers) {
|
|
2474
2474
|
const { uid, profile_name, profile_signature, profile_email, profile_picture, profile_avatar, profile_picture_obj, profile_avatar_obj } = req;
|
|
2475
|
+
const account_profile_properties = ['profile_name', 'profile_signature', 'profile_email', 'profile_picture', 'profile_avatar', 'profile_picture_obj', 'profile_avatar_obj'];
|
|
2475
2476
|
try {
|
|
2476
|
-
|
|
2477
|
+
let { data: acc_obj } = await db_module.get_couch_doc('xuda_accounts', uid);
|
|
2478
|
+
|
|
2479
|
+
for (const key of account_profile_properties) {
|
|
2480
|
+
let val = data[key];
|
|
2481
|
+
if (typeof val === 'undefined') continue;
|
|
2482
|
+
if (account_obj.account_info[key] !== val) {
|
|
2483
|
+
change += ' from ' + account_obj.account_info[key] + ' to ' + val;
|
|
2484
|
+
account_info_changes_arr.push(key);
|
|
2485
|
+
|
|
2486
|
+
if (key === 'profile_picture') {
|
|
2487
|
+
if (account_obj.account_info['profile_picture'].includes('googleusercontent')) {
|
|
2488
|
+
account_obj.account_info['profile_picture_google'] = val;
|
|
2489
|
+
} else {
|
|
2490
|
+
//delete old profile picture
|
|
2491
|
+
// const profile_picture = path.basename(account_obj?.account_info?.['profile_picture'] || '');
|
|
2492
|
+
// if (profile_picture) {
|
|
2493
|
+
// drive_module.delete_drive_files({ uid, drive_type: 'user', files_arr: [profile_picture] });
|
|
2494
|
+
// }
|
|
2495
|
+
}
|
|
2496
|
+
|
|
2497
|
+
const profile_avatar_obj = account_obj?.account_info?.profile_avatar_obj || '';
|
|
2498
|
+
if (profile_avatar_obj) {
|
|
2499
|
+
drive_module.delete_drive_files({ uid, drive_type: 'user', files_arr: [{ type: 'file', file_path: path.join(profile_avatar_obj.file_path, profile_avatar_obj.filename) }] });
|
|
2500
|
+
}
|
|
2501
|
+
}
|
|
2502
|
+
|
|
2503
|
+
account_obj.account_info[key] = val;
|
|
2504
|
+
|
|
2505
|
+
if (account_obj.account_info.account_type === 'business') {
|
|
2506
|
+
if (key === 'business_name' && validate_input(val, 150, true, false) < 0) {
|
|
2507
|
+
error[key] = 'Invalid business name';
|
|
2508
|
+
}
|
|
2509
|
+
}
|
|
2510
|
+
if (key === 'first_name' && !validate_input(val, 35, true, false)) {
|
|
2511
|
+
// print_r(validate_input($val, 35, true, false)<0);
|
|
2512
|
+
// exit;
|
|
2513
|
+
error[key] = 'Invalid first name';
|
|
2514
|
+
}
|
|
2515
|
+
if (key === 'last_name' && !validate_input(val, 35, true, false)) {
|
|
2516
|
+
error[key] = 'Invalid last name';
|
|
2517
|
+
}
|
|
2518
|
+
if (key === 'email' && (!validator.isEmail(val) || !val || val.length < 2)) {
|
|
2519
|
+
error[key] = 'Invalid email';
|
|
2520
|
+
}
|
|
2521
|
+
// if (key === 'phone_number' && (!/^[0-9]{3}-[0-9]{4}-[0-9]{4}$/.test(val) || !val || val.length < 2)) {
|
|
2522
|
+
// // if (key === "phone_number" && (!preg_match("/^[0-9]{3}-[0-9]{4}-[0-9]{4}$/", $val) || !$val || count($val) < 2)) {
|
|
2523
|
+
// error[key] = 'Invalid phone number';
|
|
2524
|
+
// }
|
|
2525
|
+
if (key === 'address' && !/^[a-z0-9- ]+$/i.test(val)) {
|
|
2526
|
+
// if (key === "address" && !preg_match('/^[a-z0-9- ]+$/i', $val)) {
|
|
2527
|
+
error[key] = 'Invalid address';
|
|
2528
|
+
}
|
|
2529
|
+
if (key === 'city' && !validate_input(val, 255, false, false)) {
|
|
2530
|
+
error[key] = 'Invalid city';
|
|
2531
|
+
}
|
|
2532
|
+
if (key === 'state' && !validate_input(val, 50, false, false)) {
|
|
2533
|
+
error[key] = 'Invalid state';
|
|
2534
|
+
}
|
|
2535
|
+
if (key === 'zip' && validate_input(val, 9, false, false) < 0) {
|
|
2536
|
+
error[key] = 'Invalid zip';
|
|
2537
|
+
}
|
|
2538
|
+
if (key === 'country' && !validate_input(val, 55, false, false)) {
|
|
2539
|
+
error[key] = 'Invalid country';
|
|
2540
|
+
}
|
|
2541
|
+
}
|
|
2542
|
+
}
|
|
2477
2543
|
|
|
2478
2544
|
const d = Date.now();
|
|
2479
2545
|
const doc = {
|