mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Merge pull request #1355 from omnivore-app/fix/sync-integration
Use the correct data format in the pub/sub queue
This commit is contained in:
commit
bad6904909
2 changed files with 14 additions and 5 deletions
|
|
@ -13,8 +13,10 @@ import { DateFilter } from '../../utils/search'
|
|||
|
||||
export interface Message {
|
||||
type?: EntityType
|
||||
data?: any
|
||||
id?: string
|
||||
userId: string
|
||||
pageId?: string
|
||||
articleId?: string
|
||||
}
|
||||
|
||||
const logger = buildLogger('app.dispatch')
|
||||
|
|
@ -41,7 +43,9 @@ export function integrationsServiceRouter() {
|
|||
}
|
||||
|
||||
try {
|
||||
const { userId, type, data }: Message = JSON.parse(msgStr)
|
||||
const data: Message = JSON.parse(msgStr)
|
||||
const userId = data.userId
|
||||
const type = data.type
|
||||
if (!userId) {
|
||||
logger.info('No userId found in message')
|
||||
res.status(400).send('Bad Request')
|
||||
|
|
@ -62,7 +66,7 @@ export function integrationsServiceRouter() {
|
|||
const action = req.params.action.toUpperCase()
|
||||
if (action === 'SYNC_UPDATED') {
|
||||
// get updated page by id
|
||||
let id = ''
|
||||
let id: string | undefined
|
||||
switch (type) {
|
||||
case EntityType.PAGE:
|
||||
id = data.id
|
||||
|
|
@ -74,6 +78,11 @@ export function integrationsServiceRouter() {
|
|||
id = data.pageId
|
||||
break
|
||||
}
|
||||
if (!id) {
|
||||
logger.info('No id found in message')
|
||||
res.status(400).send('Bad Request')
|
||||
return
|
||||
}
|
||||
const page = await getPageById(id)
|
||||
if (!page) {
|
||||
logger.info('No page found for id', { id })
|
||||
|
|
|
|||
|
|
@ -190,7 +190,7 @@ describe('Integrations routers', () => {
|
|||
JSON.stringify({
|
||||
userId: user.id,
|
||||
type: 'page',
|
||||
data: { id: page.id },
|
||||
id: page.id,
|
||||
})
|
||||
).toString('base64'),
|
||||
publishTime: new Date().toISOString(),
|
||||
|
|
@ -257,7 +257,7 @@ describe('Integrations routers', () => {
|
|||
JSON.stringify({
|
||||
userId: user.id,
|
||||
type: 'highlight',
|
||||
data: { articleId: page.id },
|
||||
articleId: page.id,
|
||||
})
|
||||
).toString('base64'),
|
||||
publishTime: new Date().toISOString(),
|
||||
|
|
|
|||
Loading…
Reference in a new issue