Skip to content

Commit 7818635

Browse files
feat: support more fields in updateContact/addNewContact (#27)
* refactor args validation * updateContact/addNewContact: support jobTitle/departmentName/organizationName/middleName
1 parent 79e6a41 commit 7818635

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ console.log(contacts)
163163
* `firstName` String (required) - The first name of the contact.
164164
* `lastName` String (optional) - The last name of the contact.
165165
* `nickname` String (optional) - The nickname for the contact.
166+
* `jobTitle` String (optional) - The contact's job title.
167+
* `departmentName` String (optional) - The name of the department associated with the contact.
168+
* `organizationName` String (optional) - The name of the organization associated with the contact.
169+
* `middleName` String (optional) - The contact's middle name.
166170
* `birthday` String (optional) - The birthday for the contact in `YYYY-MM-DD` format.
167171
* `phoneNumbers` Array\<String\> (optional) - The phone numbers for the contact, as strings in [E.164 format](https://en.wikipedia.org/wiki/E.164): `+14155552671` or `+442071838750`.
168172
* `emailAddresses` Array\<String\> (optional) - The email addresses for the contact, as strings.
@@ -217,6 +221,10 @@ console.log(`Contact ${name} was ${deleted ? 'deleted' : 'not deleted'}.`)
217221
* `firstName` String (required) - The first name of the contact.
218222
* `lastName` String (optional) - The last name of the contact.
219223
* `nickname` String (optional) - The nickname for the contact.
224+
* `jobTitle` String (optional) - The contact's job title.
225+
* `departmentName` String (optional) - The name of the department associated with the contact.
226+
* `organizationName` String (optional) - The name of the organization associated with the contact.
227+
* `middleName` String (optional) - The contact's middle name.
220228
* `birthday` String (optional) - The birthday for the contact in `YYYY-MM-DD` format.
221229
* `phoneNumbers` Array\<String\> (optional) - The phone numbers for the contact, as strings in [E.164 format](https://en.wikipedia.org/wiki/E.164): `+14155552671` or `+442071838750`.
222230
* `emailAddresses` Array\<String\> (optional) - The email addresses for the contact, as strings.

contacts.mm

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,12 @@ CNAuthorizationStatus AuthStatus() {
369369
[contact setGivenName:[NSString stringWithUTF8String:first_name.c_str()]];
370370
}
371371

372+
if (contact_data.Has("middleName")) {
373+
std::string middle_name =
374+
contact_data.Get("middleName").As<Napi::String>().Utf8Value();
375+
[contact setMiddleName:[NSString stringWithUTF8String:middle_name.c_str()]];
376+
}
377+
372378
if (contact_data.Has("lastName")) {
373379
std::string last_name =
374380
contact_data.Get("lastName").As<Napi::String>().Utf8Value();
@@ -381,6 +387,24 @@ CNAuthorizationStatus AuthStatus() {
381387
[contact setNickname:[NSString stringWithUTF8String:nick_name.c_str()]];
382388
}
383389

390+
if (contact_data.Has("jobTitle")) {
391+
std::string job_title =
392+
contact_data.Get("jobTitle").As<Napi::String>().Utf8Value();
393+
[contact setJobTitle:[NSString stringWithUTF8String:job_title.c_str()]];
394+
}
395+
396+
if (contact_data.Has("departmentName")) {
397+
std::string department_name =
398+
contact_data.Get("departmentName").As<Napi::String>().Utf8Value();
399+
[contact setDepartmentName:[NSString stringWithUTF8String:department_name.c_str()]];
400+
}
401+
402+
if (contact_data.Has("organizationName")) {
403+
std::string organization_name =
404+
contact_data.Get("organizationName").As<Napi::String>().Utf8Value();
405+
[contact setOrganizationName:[NSString stringWithUTF8String:organization_name.c_str()]];
406+
}
407+
384408
if (contact_data.Has("birthday")) {
385409
std::string birth_day =
386410
contact_data.Get("birthday").As<Napi::String>().Utf8Value();

index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,15 @@ function validateContactArg(contact) {
6767
throw new TypeError('contact must be a non-empty object')
6868
}
6969

70-
for (const prop of ['firstName', 'lastName', 'nickname']) {
70+
for (const prop of [
71+
'firstName',
72+
'middleName',
73+
'lastName',
74+
'nickname',
75+
'jobTitle',
76+
'departmentName',
77+
'organizationName',
78+
]) {
7179
const hasProp = contact.hasOwnProperty(prop)
7280
if (hasProp && typeof contact[prop] !== 'string') {
7381
throw new TypeError(`${prop} must be a string`)

0 commit comments

Comments
 (0)