Skip to content

Commit

Permalink
fix: encode nested jsonb fields
Browse files Browse the repository at this point in the history
  • Loading branch information
capJavert committed May 31, 2024
1 parent 16e45a7 commit 5d68b1a
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/workers/cdc/common.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { ContentUpdatedMessage } from '@dailydotdev/schema';
import {
ContentMeta,
ContentQuality,
ContentUpdatedMessage,
} from '@dailydotdev/schema';
import { DataSource } from 'typeorm';
import { EntityTarget } from 'typeorm/common/EntityTarget';
import {
Expand All @@ -11,6 +15,7 @@ import { ChangeObject } from '../../types';
import { PostKeyword, Source } from '../../entity';
import { triggerTypedEvent } from '../../common';
import { logger } from '../../logger';
import { JsonValue } from '@bufbuild/protobuf';

export const isChanged = <T>(before: T, after: T, property: keyof T): boolean =>
before[property] != after[property];
Expand Down Expand Up @@ -83,15 +88,21 @@ export const notifyPostContentUpdated = async ({
summary: articlePost.summary,
content: freeformPost.content,
language: post.language,
contentMeta: post.contentMeta,
contentMeta: post.contentMeta
? ContentMeta.fromJson(post.contentMeta as JsonValue, {
ignoreUnknownFields: true,
})
: undefined,
relatedPosts: relatedPosts.map((item) => ({
...item,
createdAt: +item.createdAt,
})),
contentCuration: post.contentCuration,
contentQuality: {
isAiProbability: post.contentQuality?.is_ai_probability,
},
contentQuality: post.contentQuality
? ContentQuality.fromJson(post.contentQuality, {
ignoreUnknownFields: true,
})
: undefined,
});

await triggerTypedEvent(
Expand Down

0 comments on commit 5d68b1a

Please sign in to comment.