-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from ateliware/feat/vehicle-service
Feature :: Formulário para cadastro de veículos
- Loading branch information
Showing
6 changed files
with
196 additions
and
36 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 @@ | ||
export type Vehicle = { | ||
uuid: string; | ||
model: string; | ||
color: string; | ||
plate: string; | ||
platePicture: string; | ||
vehiclePicture: string; | ||
isVerified: boolean; | ||
}; | ||
|
||
export type RemoteVehicle = { | ||
uuid: string; | ||
model: string; | ||
color: string; | ||
plate: string; | ||
plate_picture: string; | ||
vehicle_picture: string; | ||
is_verified: boolean; | ||
}; | ||
|
||
export type VehicleFormParams = { | ||
cnh: string; | ||
model: string; | ||
color: string; | ||
plate: string; | ||
platePicture: File; | ||
vehiclePicture: File; | ||
cnhPicture: File; | ||
isVerified: boolean; | ||
}; | ||
|
||
export type RemoteVehicleFormParams = { | ||
cnh_number: string; | ||
model: string; | ||
color: string; | ||
plate: string; | ||
plate_picture: string; | ||
vehicle_picture: string; | ||
cnh_picture: string; | ||
is_verified: boolean; | ||
}; |
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
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
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
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,13 @@ | ||
import { api } from '..'; | ||
|
||
export const list = async <T>() => { | ||
return api.get<T>('/vehicles/'); | ||
}; | ||
|
||
export const retrieve = async <T>(id: string) => { | ||
return api.get<T>(`/vehicles/${id}/`); | ||
}; | ||
|
||
export const create = async <T>(data: T) => { | ||
return api.post('/vehicles/', data); | ||
}; |
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,48 @@ | ||
import { | ||
RemoteVehicle, | ||
RemoteVehicleFormParams, | ||
VehicleFormParams, | ||
} from 'interfaces/Vehicles'; | ||
import { create, list, retrieve } from './calls'; | ||
import { convertToBase64 } from '@utils/file/file'; | ||
|
||
export * from './calls'; | ||
|
||
export default class VehiclesAPICaller { | ||
static loadVehicles = async () => { | ||
const vehicles = await list<RemoteVehicle[]>(); | ||
|
||
return vehicles.data.map((vehicle) => ({ | ||
...vehicle, | ||
isVerified: vehicle.is_verified, | ||
platePicture: vehicle.plate_picture, | ||
vehiclePicture: vehicle.vehicle_picture, | ||
})); | ||
}; | ||
|
||
static loadVehicleById = async (id: string) => { | ||
const vehicle = await retrieve<RemoteVehicle>(id); | ||
|
||
return { | ||
...vehicle.data, | ||
isVerified: vehicle.data.is_verified, | ||
platePicture: vehicle.data.plate_picture, | ||
vehiclePicture: vehicle.data.vehicle_picture, | ||
}; | ||
}; | ||
|
||
static registerVehicle = async (data: VehicleFormParams) => { | ||
const platePictureBase64 = await convertToBase64(data.platePicture); | ||
const vehiclePictureBase64 = await convertToBase64(data.vehiclePicture); | ||
const cnhPictureBase64 = await convertToBase64(data.cnhPicture); | ||
|
||
await create<RemoteVehicleFormParams>({ | ||
...data, | ||
cnh_number: data.cnh, | ||
plate_picture: platePictureBase64, | ||
vehicle_picture: vehiclePictureBase64, | ||
cnh_picture: cnhPictureBase64, | ||
is_verified: data.isVerified, | ||
}); | ||
}; | ||
} |