Skip to content

Commit

Permalink
Merge pull request #794 from wazo-platform/WDA-2264-lastfirstname
Browse files Browse the repository at this point in the history
[WDA-2264] Add first and last name to contacts
  • Loading branch information
bogue authored Dec 10, 2024
2 parents a7a6b1d + b0b63cd commit ec7b0c0
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 43 deletions.
112 changes: 69 additions & 43 deletions src/domain/Contact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ export interface NewContact {
firstName: string;
lastName: string;
phoneNumber: string;
email: string | null | undefined;
address: string | null | undefined;
entreprise: string | null | undefined;
birthday: string | null | undefined;
note: string | null | undefined;
email?: string;
address?: string;
entreprise?: string;
birthday?: string;
note?: string;
sessions: Array<{
uuid: string;
mobile: boolean;
}> | null | undefined;
connected: boolean | null | undefined;
connected?: boolean;
}
export type ContactResponse = {
source: string;
Expand All @@ -33,7 +33,7 @@ export type ContactResponse = {
relations: {
user_id: number;
xivo_id: string;
agent_id: number | null | undefined;
agent_id?: number | null;
endpoint_id: number;
user_uuid: string;
source_entry_id: string;
Expand All @@ -47,22 +47,22 @@ export type ContactsResponse = {
};
export type ContactPersonalResponse = {
id: string;
firstName: string | null | undefined;
lastName: string | null | undefined;
number: string | null | undefined;
firstName?: string;
lastName?: string;
number?: string;
numbers: Array<{
label?: string;
number: string;
}> | null | undefined;
email: string | null | undefined;
entreprise: string | null | undefined;
birthday: string | null | undefined;
address: string | null | undefined;
note: string | null | undefined;
email?: string;
entreprise?: string;
birthday?: string;
address?: string;
note?: string;
// @TODO: legacy ?
firstname: string | null | undefined;
lastname: string | null | undefined;
backend: string | null | undefined;
firstname?: string;
lastname?: string;
backend?: string;
favorited: boolean;
};
export type ContactsGraphQlResponse = {
Expand Down Expand Up @@ -127,6 +127,8 @@ type ContactArguments = {
id?: string;
uuid?: string;
name?: string;
firstName?: string;
lastName?: string;
number?: string;
numbers?: Array<{
label?: string;
Expand All @@ -146,7 +148,7 @@ type ContactArguments = {
personal?: boolean;
state?: string;
source?: string;
sourceId?: string | null | undefined;
sourceId?: string;
lineState?: string;
previousPresential?: string;
lastActivity?: string;
Expand Down Expand Up @@ -233,6 +235,8 @@ type GoogleResponse = {
emails: string[];
id: string;
name: string;
firstname: string;
lastname: string;
numbers: string[];
numbers_by_label: any;
};
Expand All @@ -243,57 +247,61 @@ export default class Contact {

type: string;

id: string | null | undefined;
id?: string;

uuid?: string;

uuid: string | null | undefined;
name?: string;

name: string | null | undefined;
firstName?: string;

number: string | null | undefined;
lastName?: string;

number?: string;

numbers: Array<{
label?: string;
number: string;
}> | null | undefined;

favorited: boolean | null | undefined;
favorited?: boolean;

email: string | null | undefined;
email?: string;

emails: Array<{
label?: string;
email: string;
}> | null | undefined;

entreprise: string | null | undefined;
entreprise?: string;

birthday: string | null | undefined;
birthday?: string;

address: string | null | undefined;
address?: string;

note: string | null | undefined;
note?: string;

endpointId: number | null | undefined;
endpointId?: number;

personal: boolean | null | undefined;
personal?: boolean;

state: string | null | undefined;
state?: string;

lineState: string | null | undefined;
lineState?: string;

previousPresential: string | null | undefined;
previousPresential?: string;

lastActivity: string | null | undefined;
lastActivity?: string;

mobile: boolean | null | undefined;
mobile?: boolean;

source: string | null | undefined;
source?: string;

sourceId: string | null | undefined;
sourceId?: string;

status: string | null | undefined;
status?: string;

backend: string | null | undefined;
backend?: string;

personalStatus: string;

Expand All @@ -302,11 +310,11 @@ export default class Contact {
mobile: boolean;
}> | null | undefined;

connected: boolean | null | undefined;
connected?: boolean;

doNotDisturb: boolean | null | undefined;
doNotDisturb?: boolean;

ringing: boolean | null | undefined;
ringing?: boolean;

lines: Record<string, any>[];

Expand Down Expand Up @@ -357,6 +365,8 @@ export default class Contact {
const name = edge.node.firstname && edge.node.lastname ? `${edge.node.firstname || ''} ${edge.node.lastname || ''}` : edge.node.wazoReverse;
return new Contact({
name,
firstName: edge.node.firstname,
lastName: edge.node.lastname,
number: numbers[i],
numbers: [{
label: 'primary',
Expand Down Expand Up @@ -389,6 +399,8 @@ export default class Contact {
const email = plain.column_values[columns.indexOf('email')];
return new Contact({
name: plain.column_values[columns.indexOf('name')],
firstName: plain.column_values[columns.indexOf('firstname')],
lastName: plain.column_values[columns.indexOf('lastname')],
number: numbers.length ? numbers[0] : '',
numbers: numbers.map((number, i) => ({
label: i === 0 ? 'primary' : 'secondary',
Expand Down Expand Up @@ -420,6 +432,8 @@ export default class Contact {
static parsePersonal(plain: ContactPersonalResponse): Contact {
return new Contact({
name: `${plain.firstName || plain.firstname || ''} ${plain.lastName || plain.lastname || ''}`,
firstName: plain.firstName || plain.firstname,
lastName: plain.lastName || plain.lastname,
number: plain.number || '',
numbers: plain.number ? [{
label: 'primary',
Expand Down Expand Up @@ -458,6 +472,8 @@ export default class Contact {

return new Contact({
name,
firstName,
lastName,
number: plain.phoneNumbers.length ? plain.phoneNumbers[0].number : '',
// Make numbers unique
numbers: [...new Map(plain.phoneNumbers.map(item => [item.number, item])).values()].map((item, idx) => ({
Expand Down Expand Up @@ -523,6 +539,8 @@ export default class Contact {
return new Contact({
sourceId: single.id || '',
name: single.displayName || '',
firstName: single.givenName,
lastName: single.surname,
number: numbers.length ? numbers[0].number : '',
numbers,
emails,
Expand Down Expand Up @@ -568,6 +586,8 @@ export default class Contact {
return new Contact({
sourceId: single.id || '',
name: single.name || '',
firstName: single.lastname || '',
lastName: single.firstname || '',
number: numbers.length ? numbers[0].number : '',
numbers,
emails,
Expand Down Expand Up @@ -609,6 +629,8 @@ export default class Contact {
uuid: single.uuid,
sourceId: String(single.id) || '',
name: `${single.firstname}${single.lastname ? ` ${single.lastname}` : ''}`,
firstName: single.firstname,
lastName: single.lastname,
number: numbers.length ? numbers[0].number : '',
numbers,
emails,
Expand Down Expand Up @@ -651,6 +673,8 @@ export default class Contact {
id,
uuid,
name,
firstName,
lastName,
number,
numbers,
email,
Expand Down Expand Up @@ -681,6 +705,8 @@ export default class Contact {
this.id = id;
this.uuid = uuid;
this.name = name || '';
this.firstName = firstName || '';
this.lastName = lastName || '';
this.number = number;
this.numbers = numbers;
this.email = email;
Expand Down
12 changes: 12 additions & 0 deletions src/domain/__tests__/Contact.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import Contact from '../Contact';
const genericContactResponse = {
column_types: [
'name',
'firstname',
'lastname',
'number',
'callable',
'voicemail',
Expand All @@ -13,6 +15,8 @@ const genericContactResponse = {
term: 'a',
column_headers: [
'Nom',
'Pr\u00e9nom',
'Nom de famille',
'Num\u00e9ro',
'Mobile',
'Bo\u00eete vocale',
Expand All @@ -27,6 +31,8 @@ const contact1 = {
source: 'internal',
column_values: [
'Jonathan Lessard',
'Jonathan',
'Lessard',
'8020',
'06800880',
null,
Expand All @@ -49,6 +55,8 @@ const contact2 = {
source: 'internal',
column_values: [
'John Doe',
'John',
'Doe',
'8021',
'06800881',
null,
Expand All @@ -69,6 +77,8 @@ const contact2 = {

const parsedContact1 = new Contact({
name: 'Jonathan Lessard',
firstName: 'Jonathan',
lastName: 'Lessard',
number: '8020',
numbers: [
{
Expand Down Expand Up @@ -102,6 +112,8 @@ const parsedContact1 = new Contact({

const parsedContact2 = new Contact({
name: 'John Doe',
firstName: 'John',
lastName: 'Doe',
number: '8021',
numbers: [
{
Expand Down

0 comments on commit ec7b0c0

Please sign in to comment.