Skip to content

Commit

Permalink
docs: Remove any for contact objects
Browse files Browse the repository at this point in the history
  • Loading branch information
zatteo committed Apr 22, 2024
1 parent 36d25e3 commit 7b9b44f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 14 deletions.
20 changes: 12 additions & 8 deletions libs/cozy/contact.helper.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { models } from "cozy-client";
import { IOCozyContact } from "cozy-client/types/types";

import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
import { SymmetricCryptoKey } from "@bitwarden/common/models/domain/symmetric-crypto-key";
Expand All @@ -12,20 +13,23 @@ const { getInitials } = models.contact;

import { buildFieldsFromContact } from "./fields.helper";

const getPrimaryEmail = (contact: any): string | undefined => {
return contact.email?.find((email: any) => email.primary)?.address;
const getPrimaryEmail = (contact: IOCozyContact): string | undefined => {
return contact.email?.find((email) => email.primary)?.address;
};

const getPrimaryPhone = (contact: any): string | undefined => {
return contact.phone?.find((phone: any) => phone.primary)?.number;
const getPrimaryPhone = (contact: IOCozyContact): string | undefined => {
return contact.phone?.find((phone) => phone.primary)?.number;
};

export const convertContactToCipherData = async (
cipherService: CipherService,
i18nService: I18nService,
contact: any,
contact: IOCozyContact,
key?: SymmetricCryptoKey
): Promise<CipherData> => {
// Temporary type fix becayse contact.cozyMetadata is not properly typed
const cozyMetadata = contact.cozyMetadata as any;

const cipherView = new CipherView();
cipherView.id = contact.id ?? contact._id;
cipherView.name = contact.displayName;
Expand All @@ -35,11 +39,11 @@ export const convertContactToCipherData = async (
cipherView.contact.initials = getInitials(contact);
cipherView.contact.primaryEmail = getPrimaryEmail(contact);
cipherView.contact.primaryPhone = getPrimaryPhone(contact);
cipherView.favorite = !!contact.cozyMetadata?.favorite;
cipherView.favorite = !!cozyMetadata?.favorite;
cipherView.fields = buildFieldsFromContact(i18nService, contact);
cipherView.contact.me = contact.me;
cipherView.creationDate = new Date(contact.cozyMetadata?.createdAt);
cipherView.revisionDate = new Date(contact.cozyMetadata?.updatedAt);
cipherView.creationDate = new Date(cozyMetadata?.createdAt);
cipherView.revisionDate = new Date(cozyMetadata?.updatedAt);

const cipherEncrypted = await cipherService.encrypt(cipherView, key);

Expand Down
4 changes: 3 additions & 1 deletion libs/cozy/contactCipher.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* eslint-disable no-console */
// Cozy customization
import { IOCozyContact } from "cozy-client/types/types";

import { CryptoService } from "@bitwarden/common/abstractions/crypto.service";
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
Expand All @@ -18,7 +20,7 @@ const convertContactsAsCiphers = async (
cipherService: CipherService,
cryptoService: CryptoService,
i18nService: I18nService,
contacts: any
contacts: IOCozyContact[]
): Promise<CipherData[]> => {
const contactsCiphers = [];

Expand Down
6 changes: 5 additions & 1 deletion libs/cozy/fields.helper.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { models } from "cozy-client";
import { IOCozyContact } from "cozy-client/types/types";

import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
import { FieldSubType } from "@bitwarden/common/enums/fieldSubType";
Expand Down Expand Up @@ -214,7 +215,10 @@ const buildFieldsFromContactByBrowsingModels = ({
});
};

export const buildFieldsFromContact = (i18nService: I18nService, contact: any): FieldView[] => {
export const buildFieldsFromContact = (
i18nService: I18nService,
contact: IOCozyContact
): FieldView[] => {
const builtFields: FieldView[] = [];

const lang = i18nService.translationLocale;
Expand Down
12 changes: 8 additions & 4 deletions libs/cozy/queries.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Q } from "cozy-client";
import CozyClient from "cozy-client/types/CozyClient";
import { IOCozyContact } from "cozy-client/types/types";

const buildFilesQueryWithQualificationLabel = () => {
const select = [
Expand Down Expand Up @@ -106,16 +107,19 @@ export const buildContactsQuery = () => ({
},
});

export const fetchContacts = async (client: CozyClient) => {
export const fetchContacts = async (client: CozyClient): Promise<IOCozyContact[]> => {
const contactsQuery = buildContactsQuery();

const data = await client.queryAll(contactsQuery.definition, contactsQuery.options);
const data: IOCozyContact[] = await client.queryAll(
contactsQuery.definition,
contactsQuery.options
);

return data;
};

export const fetchContact = async (client: CozyClient, _id: string) => {
const { data } = await client.query(Q("io.cozy.contacts").getById(_id));
export const fetchContact = async (client: CozyClient, _id: string): Promise<IOCozyContact> => {
const { data }: { data: IOCozyContact } = await client.query(Q("io.cozy.contacts").getById(_id));

return data;
};

0 comments on commit 7b9b44f

Please sign in to comment.