-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetContacts.ts
More file actions
31 lines (29 loc) · 1.17 KB
/
getContacts.ts
File metadata and controls
31 lines (29 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
})