Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/classes/Standardizer/plugins/Google/getters/getContacts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import Google from '../Google'
import { Contact } from '../../../../../types/schemas'
import { MediaType } from '../../../../../types/schemas/Media'
import withAutoParser from '../../../../../modules/Standardizer/withAutoParser'

const CONTACT_FILE_CSV = 'Takeout/Contacts/Tous les contacts/Tous les contacts.csv'
const CONTACT_FILE_VCF = 'Takeout/Contacts/Tous les contacts/Tous les contacts.vcf'

Google.prototype.getContacts = withAutoParser(async parser => {
if (!(await parser.filesExist([CONTACT_FILE_VCF]))) {
const rawContacts = await parser.parseAsCSV(CONTACT_FILE_CSV)
const contacts: Contact[] = rawContacts.data.map((contact): Contact => ({
displayName: contact?.Name,
firstName: contact?.['Given Name'],
lastName: contact?.['Family Name'],
nickname: contact?.Nickname,
gender: contact?.Gender,
birthday: contact?.Birthday ? new Date(contact.Birthday) : undefined,
phoneNumbers: contact?.['Phone 1 - Value'],
mails: contact?.['E-mail 1 - Value'],
profilePicture: {
current: {
url: contact?.Photo,
type: MediaType.IMAGE,
},
},
}))
return contacts
}
return null
})