Skip to content

Commit

Permalink
refactor: Refactor type handling for company data keys
Browse files Browse the repository at this point in the history
Updated `canUseCompanyData` method to use `keyof QuestionnaireData` instead of `CompanyDataStorageKey`. This ensures type consistency and better type checking. Adjusted calls and type casts accordingly.
  • Loading branch information
dolemoine committed Nov 15, 2024
1 parent ac4c04c commit 8ea4d4b
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions apps/web/src/utils/storage/companyDataStorageHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { CompanyDataType } from '@/types/companyDataType'

export class CompanyDataStorageHandler {
static populateCompletedQuestionnaire(data: FlatArray<((QuestionnaireData | undefined)[] | undefined)[], 1>[]) {
if (this.canUseCompanyData(data, CompanyDataStorageKey.Company)) {
if (this.canUseCompanyData(data, CompanyDataStorageKey.Company as keyof QuestionnaireData)) {
data.push(CompanyDataStorage.getCompanyData() as QuestionnaireData)
}

Expand Down Expand Up @@ -59,12 +59,12 @@ export class CompanyDataStorageHandler {
}
}

static canUseCompanyData(data: (QuestionnaireData | undefined)[], key: CompanyDataStorageKey): boolean {
if (CompanyDataStorage.hasItem(key)) {
const storageItem = CompanyDataStorage.getItem(key)
static canUseCompanyData(data: (QuestionnaireData | undefined)[], key: keyof QuestionnaireData): boolean {
if (CompanyDataStorage.hasItem(key as CompanyDataStorageKey)) {
const storageItem = CompanyDataStorage.getItem(key as CompanyDataStorageKey)

return (
CompanyDataStorage.hasItem(key) &&
CompanyDataStorage.hasItem(key as CompanyDataStorageKey) &&
!data.some((item) => item?.[key] === (typeof storageItem === 'string' ? storageItem : (storageItem as QuestionnaireData)?.[key]))
)
}
Expand Down

0 comments on commit 8ea4d4b

Please sign in to comment.