import { firebase, firestore } from '../../firebase' import { AlreadyReadMessage } from '../../domain/account/alreadyReadMessage' import { getAlreadyReadMessagePath } from '../../firebase/collectionSchema' type Input = Omit, 'updatedAt'>, 'readAccountId'> & { accountId: AlreadyReadMessage['readAccountId'] } type DTO = Omit, 'updatedAt'> & { updatedAt: firebase.firestore.FieldValue } function mapEntityToDTO(entity: Input): DTO { return { roomId: entity.roomId, readAccountId: entity.accountId, updatedAt: firebase.firestore.FieldValue.serverTimestamp(), } } export function saveAlreadyReadMessage(input: Input) { return firestore .collection(getAlreadyReadMessagePath(input.accountId, input.roomId)) .doc(input.accountId) .set(mapEntityToDTO(input)) }