@xuda.io/account_module 1.2.1076 → 1.2.1078

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.
Files changed (2) hide show
  1. package/index.mjs +66 -1
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -2472,8 +2472,73 @@ 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
- const { data: acc_obj } = await db_module.get_couch_doc('xuda_accounts', uid);
2477
+ let { data: acc_obj } = await db_module.get_couch_doc('xuda_accounts', uid);
2478
+ let changes_arr = [];
2479
+ for (const key of account_profile_properties) {
2480
+ let val = data[key];
2481
+ if (typeof val === 'undefined') continue;
2482
+ if (acc_obj[key] !== val) {
2483
+ account_info_changes_arr.push(key);
2484
+
2485
+ if (key === 'profile_picture') {
2486
+ if (account_obj.account_info['profile_picture'].includes('googleusercontent')) {
2487
+ account_obj.account_info['profile_picture_google'] = val;
2488
+ } else {
2489
+ //delete old profile picture
2490
+ // const profile_picture = path.basename(account_obj?.account_info?.['profile_picture'] || '');
2491
+ // if (profile_picture) {
2492
+ // drive_module.delete_drive_files({ uid, drive_type: 'user', files_arr: [profile_picture] });
2493
+ // }
2494
+ }
2495
+
2496
+ const profile_avatar_obj = account_obj?.account_info?.profile_avatar_obj || '';
2497
+ if (profile_avatar_obj) {
2498
+ 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) }] });
2499
+ }
2500
+ }
2501
+
2502
+ account_obj.account_info[key] = val;
2503
+
2504
+ if (account_obj.account_info.account_type === 'business') {
2505
+ if (key === 'business_name' && validate_input(val, 150, true, false) < 0) {
2506
+ error[key] = 'Invalid business name';
2507
+ }
2508
+ }
2509
+ if (key === 'first_name' && !validate_input(val, 35, true, false)) {
2510
+ // print_r(validate_input($val, 35, true, false)<0);
2511
+ // exit;
2512
+ error[key] = 'Invalid first name';
2513
+ }
2514
+ if (key === 'last_name' && !validate_input(val, 35, true, false)) {
2515
+ error[key] = 'Invalid last name';
2516
+ }
2517
+ if (key === 'email' && (!validator.isEmail(val) || !val || val.length < 2)) {
2518
+ error[key] = 'Invalid email';
2519
+ }
2520
+ // if (key === 'phone_number' && (!/^[0-9]{3}-[0-9]{4}-[0-9]{4}$/.test(val) || !val || val.length < 2)) {
2521
+ // // if (key === "phone_number" && (!preg_match("/^[0-9]{3}-[0-9]{4}-[0-9]{4}$/", $val) || !$val || count($val) < 2)) {
2522
+ // error[key] = 'Invalid phone number';
2523
+ // }
2524
+ if (key === 'address' && !/^[a-z0-9- ]+$/i.test(val)) {
2525
+ // if (key === "address" && !preg_match('/^[a-z0-9- ]+$/i', $val)) {
2526
+ error[key] = 'Invalid address';
2527
+ }
2528
+ if (key === 'city' && !validate_input(val, 255, false, false)) {
2529
+ error[key] = 'Invalid city';
2530
+ }
2531
+ if (key === 'state' && !validate_input(val, 50, false, false)) {
2532
+ error[key] = 'Invalid state';
2533
+ }
2534
+ if (key === 'zip' && validate_input(val, 9, false, false) < 0) {
2535
+ error[key] = 'Invalid zip';
2536
+ }
2537
+ if (key === 'country' && !validate_input(val, 55, false, false)) {
2538
+ error[key] = 'Invalid country';
2539
+ }
2540
+ }
2541
+ }
2477
2542
 
2478
2543
  const d = Date.now();
2479
2544
  const doc = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/account_module",
3
- "version": "1.2.1076",
3
+ "version": "1.2.1078",
4
4
  "description": "Xuda Account Server Module",
5
5
  "main": "index.mjs",
6
6
  "dependencies": {