Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions services/apps/data_sink_worker/src/service/member.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,22 @@ export default class MemberService extends LoggerBase {
let attributes: Record<string, unknown> | undefined
if (member.attributes) {
const temp = mergeWith({}, dbMember.attributes, member.attributes)

const manuallyChangedFields: string[] = dbMember.manuallyChangedFields || []
if (manuallyChangedFields.length > 0) {
const attrColumn = 'attributes'
const manuallyChangedAttributes = (dbMember.manuallyChangedFields || [])
.filter((f) => f.startsWith(attrColumn))
.map((f) => f.substring(attrColumn.length))

// Preserve manually changed attributes
for (const key of manuallyChangedAttributes) {
if (dbMember.attributes[key] !== undefined) {
temp[key] = dbMember.attributes[key]
}
}
}

if (!isEqual(temp, dbMember.attributes)) {
attributes = temp
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ export interface IDbMember {
joinedAt: string
attributes: Record<string, unknown>
reach: Partial<Record<PlatformType | 'total', number>>
manuallyChangedFields?: string[]
}

let getMemberColumnSet: DbColumnSet
export function getSelectMemberColumnSet(instance: DbInstance): DbColumnSet {
if (getMemberColumnSet) return getMemberColumnSet

getMemberColumnSet = new instance.helpers.ColumnSet(
['id', 'score', 'joinedAt', 'reach', 'attributes', 'displayName'],
['id', 'score', 'joinedAt', 'reach', 'attributes', 'displayName', 'manuallyChangedFields'],
{
table: {
table: 'members',
Expand Down
Loading