-
Notifications
You must be signed in to change notification settings - Fork 564
/
index.ts
109 lines (90 loc) · 2.77 KB
/
index.ts
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import { NativeModules } from "react-native";
import NativeContacts from "./src/NativeContacts";
import { Contact, PermissionType } from "./type";
const isTurboModuleEnabled = global.__turboModuleProxy != null;
const Contacts = isTurboModuleEnabled ? NativeContacts : NativeModules.Contacts;
async function getAll(): Promise<Contact[]> {
return Contacts.getAll();
}
async function getAllWithoutPhotos(): Promise<Contact[]> {
return Contacts.getAllWithoutPhotos();
}
async function getContactById(contactId: string): Promise<Contact | null> {
return Contacts.getContactById(contactId);
}
async function getCount(): Promise<number> {
return Contacts.getCount();
}
async function getPhotoForId(contactId: string): Promise<string> {
return Contacts.getPhotoForId(contactId);
}
async function addContact(contact: Partial<Contact>): Promise<Contact> {
return Contacts.addContact(contact);
}
async function openContactForm(contact: Partial<Contact>): Promise<Contact> {
return Contacts.openContactForm(contact);
}
async function openExistingContact(contact: Contact): Promise<Contact> {
return Contacts.openExistingContact(contact);
}
async function viewExistingContact(contact: {
recordID: string;
}): Promise<Contact | void> {
return Contacts.viewExistingContact(contact);
}
async function editExistingContact(contact: Contact): Promise<Contact> {
return Contacts.editExistingContact(contact);
}
async function updateContact(
contact: Partial<Contact> & { recordID: string }
): Promise<void> {
return Contacts.updateContact(contact);
}
async function deleteContact(contact: Contact): Promise<void> {
return Contacts.deleteContact(contact);
}
async function getContactsMatchingString(str: string): Promise<Contact[]> {
return Contacts.getContactsMatchingString(str);
}
async function getContactsByPhoneNumber(
phoneNumber: string
): Promise<Contact[]> {
return Contacts.getContactsByPhoneNumber(phoneNumber);
}
async function getContactsByEmailAddress(
emailAddress: string
): Promise<Contact[]> {
return Contacts.getContactsByEmailAddress(emailAddress);
}
async function checkPermission(): Promise<PermissionType> {
return Contacts.checkPermission();
}
async function requestPermission(): Promise<PermissionType> {
return Contacts.requestPermission();
}
async function writePhotoToPath(
contactId: string,
file: string
): Promise<boolean> {
return Contacts.writePhotoToPath(contactId, file);
}
export default {
getAll,
getAllWithoutPhotos,
getContactById,
getCount,
getPhotoForId,
addContact,
openContactForm,
openExistingContact,
viewExistingContact,
editExistingContact,
updateContact,
deleteContact,
getContactsMatchingString,
getContactsByPhoneNumber,
getContactsByEmailAddress,
checkPermission,
requestPermission,
writePhotoToPath,
};