Skip to content

Commit 34ea138

Browse files
committed
feat(users): add conditional UTM parameter inclusion in user data and update validation return type
1 parent 271e380 commit 34ea138

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/models/usersFactory.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,12 @@ export default class UsersFactory extends AbstractModelFactory<UserDBScheme, Use
7676
email,
7777
password: hashedPassword,
7878
notifications: UserModel.generateDefaultNotificationsSettings(email),
79-
utm: utm,
8079
};
8180

81+
if (utm && Object.keys(utm).length > 0) {
82+
userData.utm = utm;
83+
}
84+
8285
const userId = (await this.collection.insertOne(userData)).insertedId;
8386

8487
const user = new UserModel({

src/utils/utm/utm.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ const MAX_UTM_VALUE_LENGTH = 50;
1919
* @param {Object} utm - UTM parameters to validate
2020
* @returns {Object} - filtered valid UTM parameters
2121
*/
22-
export function validateUtmParams(utm: any): Record<string, string> {
22+
export function validateUtmParams(utm: any): Record<string, string> | undefined {
2323
if (!utm || typeof utm !== 'object' || Array.isArray(utm)) {
24-
return {};
24+
return undefined;
2525
}
2626

2727
const result: Record<string, string> = {};

0 commit comments

Comments
 (0)