Skip to content

Commit 4551ae8

Browse files
authored
fix: convert primitive attributes to platform-specific format [CM-772] (#3568)
1 parent cf6e073 commit 4551ae8

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

services/apps/data_sink_worker/src/service/member.service.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ export default class MemberService extends LoggerBase {
9292
let attributes: Record<string, unknown> = {}
9393
if (data.attributes) {
9494
attributes = await logExecutionTimeV2(
95-
() => memberAttributeService.validateAttributes(data.attributes),
95+
() =>
96+
memberAttributeService.validateAttributes(data.attributes, source as PlatformType),
9697
this.log,
9798
'memberService -> create -> validateAttributes',
9899
)
@@ -285,7 +286,8 @@ export default class MemberService extends LoggerBase {
285286
if (data.attributes) {
286287
this.log.trace({ memberId: id }, 'Validating member attributes!')
287288
data.attributes = await logExecutionTimeV2(
288-
() => memberAttributeService.validateAttributes(data.attributes),
289+
() =>
290+
memberAttributeService.validateAttributes(data.attributes, source as PlatformType),
289291
this.log,
290292
'memberService -> update -> validateAttributes',
291293
)

services/apps/data_sink_worker/src/service/memberAttribute.service.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
import { dbStoreQx } from '@crowd/data-access-layer/src/queryExecutor'
88
import { Logger, LoggerBase } from '@crowd/logging'
99
import { RedisClient } from '@crowd/redis'
10-
import { MemberAttributeType } from '@crowd/types'
10+
import { MemberAttributeType, PlatformType } from '@crowd/types'
1111

1212
export default class MemberAttributeService extends LoggerBase {
1313
constructor(
@@ -27,6 +27,7 @@ export default class MemberAttributeService extends LoggerBase {
2727

2828
public async validateAttributes(
2929
attributes: Record<string, unknown>,
30+
platform: PlatformType,
3031
): Promise<Record<string, unknown>> {
3132
const settings = await getMemberAttributeSettings(dbStoreQx(this.store), this.redis)
3233
const memberAttributeSettings = settings.reduce((acc, attribute) => {
@@ -43,32 +44,35 @@ export default class MemberAttributeService extends LoggerBase {
4344
delete attributes[attributeName]
4445
continue
4546
}
47+
// Convert primitive to platform-specific format: { [platform]: value }
4648
if (typeof attributes[attributeName] !== 'object') {
49+
const value = attributes[attributeName]
50+
4751
attributes[attributeName] = {
48-
custom: attributes[attributeName],
52+
[platform]: value,
4953
}
5054
}
5155

52-
for (const platform of Object.keys(attributes[attributeName])) {
56+
for (const platformKey of Object.keys(attributes[attributeName])) {
5357
if (
54-
attributes[attributeName][platform] !== undefined &&
55-
attributes[attributeName][platform] !== null
58+
attributes[attributeName][platformKey] !== undefined &&
59+
attributes[attributeName][platformKey] !== null
5660
) {
5761
if (
5862
!MemberAttributeService.isCorrectType(
59-
attributes[attributeName][platform],
63+
attributes[attributeName][platformKey],
6064
memberAttributeSettings[attributeName].type,
6165
{ options: memberAttributeSettings[attributeName].options },
6266
)
6367
) {
6468
this.log.error('Failed to validate attributee', {
6569
attributeName,
66-
platform,
67-
attributeValue: attributes[attributeName][platform],
70+
platform: platformKey,
71+
attributeValue: attributes[attributeName][platformKey],
6872
attributeType: memberAttributeSettings[attributeName].type,
6973
})
7074
throw new Error(
71-
`Failed to validate attribute '${attributeName}' with value '${attributes[attributeName][platform]}'!`,
75+
`Failed to validate attribute '${attributeName}' with value '${attributes[attributeName][platformKey]}'!`,
7276
)
7377
}
7478
}

0 commit comments

Comments
 (0)