Files
standardnotes-server/packages/syncing-server/src/Domain/Handler/UserCredentialsChangedEventHandler.ts
T
2023-05-19 12:59:28 -05:00

18 lines
849 B
TypeScript

import { DomainEventHandlerInterface, UserCredentialsChangedEvent } from '@standardnotes/domain-events'
import { TimerInterface } from '@standardnotes/time'
import { ContactsRepositoryInterface } from '../Contact/Repository/ContactRepositoryInterface'
export class UserCredentialsChangedEventHandler implements DomainEventHandlerInterface {
constructor(private contactRepository: ContactsRepositoryInterface, private timer: TimerInterface) {}
async handle(event: UserCredentialsChangedEvent): Promise<void> {
const contacts = await this.contactRepository.findAll({ contactUuid: event.payload.userUuid })
for (const contact of contacts) {
contact.contactPublicKey = event.payload.newPublicKey
contact.updatedAtTimestamp = this.timer.getTimestampInMicroseconds()
await this.contactRepository.save(contact)
}
}
}