Skip to content

Commit 246c826

Browse files
committed
bugfix(modeling-commons): error parsing user social links
1 parent f1fa663 commit 246c826

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

apps/modeling-commons-backend/src/modules/user/user.mapper.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,16 @@ export default function userMapper(): Mapper<UserEntity, UserRecord, UserRespons
1010
toDomain(record: UserRecord): UserEntity {
1111
let socialLinks: UserEntity['socialLinks'] = null;
1212
if (record.socialLinks) {
13-
try {
14-
socialLinks = JSON.parse(record.socialLinks as string) as UserEntity['socialLinks'];
15-
} catch (error) {
16-
// If parsing fails, log the error and keep socialLinks as null
17-
console.error('Error parsing socialLinks for user', { userId: record.id, error });
13+
if (typeof record.socialLinks === 'object') {
14+
// If it's already an object (e.g., due to some ORM magic), use it directly
15+
socialLinks = record.socialLinks as UserEntity['socialLinks'];
16+
} else if (typeof record.socialLinks === 'string') {
17+
try {
18+
socialLinks = JSON.parse(record.socialLinks) as UserEntity['socialLinks'];
19+
} catch (error) {
20+
// If parsing fails, log the error and keep socialLinks as null
21+
console.error('Error parsing socialLinks for user', { userId: record.id, error });
22+
}
1823
}
1924
}
2025

0 commit comments

Comments
 (0)