77import { dbStoreQx } from '@crowd/data-access-layer/src/queryExecutor'
88import { Logger , LoggerBase } from '@crowd/logging'
99import { RedisClient } from '@crowd/redis'
10- import { MemberAttributeType } from '@crowd/types'
10+ import { MemberAttributeType , PlatformType } from '@crowd/types'
1111
1212export 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