Update syncedAt after syncing

This commit is contained in:
Hongbo Wu
2022-08-09 09:51:31 +08:00
parent 134482a261
commit 427cecf6b9
3 changed files with 14 additions and 3 deletions

View File

@ -127,10 +127,9 @@ export function integrationsServiceRouter() {
return
}
}
// update integration syncedAt if successful
// delete task name if completed
await getRepository(Integration).update(integration.id, {
taskName: null,
syncedAt: new Date(),
})
} else {
logger.info('unknown action', { action })

View File

@ -5,6 +5,7 @@ import { wait } from '../utils/helpers'
import { Page } from '../elastic/types'
import { getHighlightLocation, getHighlightUrl } from './highlights'
import { Integration } from '../entity/integration'
import { getRepository } from '../entity/utils'
interface ReadwiseHighlight {
// The highlight text, (technically the only field required in a highlight object)
@ -98,6 +99,13 @@ export const syncWithIntegration = async (
default:
return false
}
// update integration syncedAt if successful
if (result) {
console.log('updating integration syncedAt')
await getRepository(Integration).update(integration.id, {
syncedAt: new Date(),
})
}
return result
}

View File

@ -285,7 +285,7 @@ describe('Integrations routers', () => {
})
context('when action is sync_all', () => {
before(() => {
before(async () => {
action = 'sync_all'
data = {
message: {
@ -306,6 +306,10 @@ describe('Integrations routers', () => {
})
.post('/highlights', highlightsData)
.reply(200)
await getRepository(Integration).update(integration.id, {
syncedAt: null,
taskName: 'some task name',
})
})
it('returns 200 with OK', async () => {