Skip to content

Instantly share code, notes, and snippets.

@sidneyroberto
Created October 22, 2024 01:50
Show Gist options
  • Save sidneyroberto/746aaa5e248bdb9d42212b92f0c98ae1 to your computer and use it in GitHub Desktop.
Save sidneyroberto/746aaa5e248bdb9d42212b92f0c98ae1 to your computer and use it in GitHub Desktop.
export const contactConverter: FirestoreDataConverter<Contact, DocumentData> = {
toFirestore: (contact: Contact): DocumentData => {
const cleanContact = Object.entries(work)
// eslint-disable-next-line @typescript-eslint/no-unused-vars
.filter(([_, value]) => value !== undefined)
.reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {});
return cleanContact;
},
fromFirestore: (
snapshot: QueryDocumentSnapshot,
options: SnapshotOptions
) => {
const data = snapshot.data(options);
return new Contact(data);
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment