-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor adapter functions from useApiPostSubsidiary into a standalon…
…e adapter
- Loading branch information
Šimon Macek
committed
Dec 11, 2024
1 parent
9785501
commit 34ab991
Showing
3 changed files
with
74 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// types | ||
import type { FormCompanyAddressFields } from '../components/types/Form'; | ||
import type { | ||
SubsidiaryPostApiPayload, | ||
SubsidiaryPostApiResponse, | ||
} from '../components/types/ApiSubsidiary'; | ||
|
||
/** | ||
* Adapter for converting between API and form subsidiary data formats | ||
*/ | ||
export const subsidiaryAdapter = { | ||
/** | ||
* Convert form data to API payload format | ||
*/ | ||
toApiPayload(formData: FormCompanyAddressFields): SubsidiaryPostApiPayload { | ||
return { | ||
address: { | ||
street: formData.street, | ||
street_number: formData.houseNumber, | ||
recipient: formData.department, | ||
city: formData.city, | ||
psc: formData.zip, | ||
}, | ||
city_id: formData.cityChallenge, | ||
}; | ||
}, | ||
|
||
/** | ||
* Convert API response to form data format | ||
*/ | ||
toFormData(apiData: SubsidiaryPostApiResponse): FormCompanyAddressFields { | ||
return { | ||
street: apiData.address.street, | ||
houseNumber: apiData.address.street_number, | ||
city: apiData.address.city, | ||
zip: String(apiData.address.psc), | ||
cityChallenge: apiData.city_id, | ||
department: apiData.address.recipient, | ||
}; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* API types for subsidiary-related operations | ||
*/ | ||
|
||
export interface SubsidiaryPostApiAddress { | ||
street: string; | ||
street_number: string; | ||
recipient: string; | ||
city: string; | ||
psc: string | number; | ||
} | ||
|
||
export interface SubsidiaryPostApiPayload { | ||
address: SubsidiaryPostApiAddress; | ||
city_id: number | null; | ||
} | ||
|
||
export interface SubsidiaryPostApiResponse { | ||
id: number; | ||
city_id: number | null; | ||
active: boolean; | ||
address: SubsidiaryPostApiAddress; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters