Skip to content

Commit

Permalink
feat: Add isContact method on contacts models
Browse files Browse the repository at this point in the history
  • Loading branch information
JF-Cozy committed Mar 16, 2023
1 parent 66475ed commit 0281ad3
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 14 deletions.
60 changes: 46 additions & 14 deletions docs/api/cozy-client/modules/models.contact.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@

[models](models.md).contact

## Variables

### CONTACTS_DOCTYPE

`Const` **CONTACTS_DOCTYPE**: `"io.cozy.contacts"`

*Defined in*

[packages/cozy-client/src/models/contact.js:6](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/models/contact.js#L6)

## Functions

### getDefaultSortIndexValue
Expand All @@ -26,7 +36,7 @@ Returns 'byFamilyNameGivenNameEmailCozyUrl' index of a contact

*Defined in*

[packages/cozy-client/src/models/contact.js:198](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/models/contact.js#L198)
[packages/cozy-client/src/models/contact.js:201](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/models/contact.js#L201)

***

Expand All @@ -50,7 +60,7 @@ Returns a display name for the contact

*Defined in*

[packages/cozy-client/src/models/contact.js:160](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/models/contact.js#L160)
[packages/cozy-client/src/models/contact.js:163](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/models/contact.js#L163)

***

Expand All @@ -74,7 +84,7 @@ Returns the contact's fullname

*Defined in*

[packages/cozy-client/src/models/contact.js:122](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/models/contact.js#L122)
[packages/cozy-client/src/models/contact.js:125](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/models/contact.js#L125)

***

Expand All @@ -100,7 +110,7 @@ Returns 'byFamilyNameGivenNameEmailCozyUrl' index of a contact

*Defined in*

[packages/cozy-client/src/models/contact.js:219](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/models/contact.js#L219)
[packages/cozy-client/src/models/contact.js:222](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/models/contact.js#L222)

***

Expand All @@ -124,7 +134,7 @@ Returns the initials of the contact.

*Defined in*

[packages/cozy-client/src/models/contact.js:16](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/models/contact.js#L16)
[packages/cozy-client/src/models/contact.js:19](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/models/contact.js#L19)

***

Expand All @@ -148,7 +158,7 @@ Returns the contact's main address

*Defined in*

[packages/cozy-client/src/models/contact.js:89](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/models/contact.js#L89)
[packages/cozy-client/src/models/contact.js:92](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/models/contact.js#L92)

***

Expand All @@ -172,7 +182,7 @@ Returns the contact's main cozy

*Defined in*

[packages/cozy-client/src/models/contact.js:54](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/models/contact.js#L54)
[packages/cozy-client/src/models/contact.js:57](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/models/contact.js#L57)

***

Expand All @@ -196,7 +206,7 @@ Returns the contact's main cozy url without protocol

*Defined in*

[packages/cozy-client/src/models/contact.js:65](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/models/contact.js#L65)
[packages/cozy-client/src/models/contact.js:68](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/models/contact.js#L68)

***

Expand All @@ -220,7 +230,7 @@ Returns the contact's main email

*Defined in*

[packages/cozy-client/src/models/contact.js:43](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/models/contact.js#L43)
[packages/cozy-client/src/models/contact.js:46](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/models/contact.js#L46)

***

Expand Down Expand Up @@ -252,7 +262,7 @@ Returns the contact's main email

*Defined in*

[packages/cozy-client/src/models/contact.js:5](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/models/contact.js#L5)
[packages/cozy-client/src/models/contact.js:8](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/models/contact.js#L8)

***

Expand All @@ -276,7 +286,29 @@ Returns the contact's main phone number

*Defined in*

[packages/cozy-client/src/models/contact.js:80](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/models/contact.js#L80)
[packages/cozy-client/src/models/contact.js:83](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/models/contact.js#L83)

***

### isContact

**isContact**(`doc`): `boolean`

Whether the document is a contact

*Parameters*

| Name | Type | Description |
| :------ | :------ | :------ |
| `doc` | `any` | A document (from io.cozy.something, or com.bitwarden or anything else) |

*Returns*

`boolean`

*Defined in*

[packages/cozy-client/src/models/contact.js:236](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/models/contact.js#L236)

***

Expand All @@ -300,7 +332,7 @@ Makes 'byFamilyNameGivenNameEmailCozyUrl' index of a contact

*Defined in*

[packages/cozy-client/src/models/contact.js:174](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/models/contact.js#L174)
[packages/cozy-client/src/models/contact.js:177](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/models/contact.js#L177)

***

Expand All @@ -324,7 +356,7 @@ Makes displayName from contact data

*Defined in*

[packages/cozy-client/src/models/contact.js:136](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/models/contact.js#L136)
[packages/cozy-client/src/models/contact.js:139](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/models/contact.js#L139)

***

Expand All @@ -348,4 +380,4 @@ Makes fullname from contact name

*Defined in*

[packages/cozy-client/src/models/contact.js:98](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/models/contact.js#L98)
[packages/cozy-client/src/models/contact.js:101](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/models/contact.js#L101)
11 changes: 11 additions & 0 deletions packages/cozy-client/src/models/contact.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import get from 'lodash/get'
import isEmpty from 'lodash/isEmpty'

import logger from '../logger'

export const CONTACTS_DOCTYPE = 'io.cozy.contacts'

export const getPrimaryOrFirst = property => obj =>
!obj[property] || obj[property].length === 0
? ''
Expand Down Expand Up @@ -223,3 +226,11 @@ export const getIndexByFamilyNameGivenNameEmailCozyUrl = contact => {

return getDefaultSortIndexValue(contact)
}

/**
* Whether the document is a contact
*
* @param {object} doc - A document (from io.cozy.something, or com.bitwarden or anything else)
* @returns {boolean}
*/
export const isContact = doc => doc._type === CONTACTS_DOCTYPE
2 changes: 2 additions & 0 deletions packages/cozy-client/types/models/contact.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const CONTACTS_DOCTYPE: "io.cozy.contacts";
export function getPrimaryOrFirst(property: any): (obj: any) => any;
export function getInitials(contact: object): string;
export function getPrimaryEmail(contact: object): string;
Expand All @@ -12,3 +13,4 @@ export function getDisplayName(contact: object): string;
export function makeDefaultSortIndexValue(contact: object): string;
export function getDefaultSortIndexValue(contact: object): string;
export function getIndexByFamilyNameGivenNameEmailCozyUrl(contact: object): string;
export function isContact(doc: object): boolean;

0 comments on commit 0281ad3

Please sign in to comment.