add: car processing
This commit is contained in:
@@ -3,10 +3,10 @@ import { toRFC3339 } from './helpers';
|
||||
/**
|
||||
* Converts FormData to a nested object structure
|
||||
* @param {FormData} formData - The FormData object to convert
|
||||
* @returns {{ object: Partial<App.Locals['user']> | Partial<App.Types['subscription']>, confirm_password: string }} Nested object representation of the form data
|
||||
* @returns {{ object: Partial<App.Locals['user']> | Partial<App.Types['subscription']> | Partial<App.Types['car']>, confirm_password: string }} Nested object representation of the form data
|
||||
*/
|
||||
export function formDataToObject(formData) {
|
||||
/** @type { Partial<App.Locals['user']> | Partial<App.Types['subscription']> } */
|
||||
/** @type { Partial<App.Locals['user']> | Partial<App.Types['subscription']> | Partial<App.Types['car']> } */
|
||||
const object = {};
|
||||
let confirm_password = '';
|
||||
|
||||
@@ -142,8 +142,8 @@ export function processUserFormData(rawData) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the raw form data into the expected user data structure
|
||||
* @param {{ object: Partial<App.Types['subscription']>} } rawData - The raw form data object
|
||||
* Processes the raw form data into the expected subscription data structure
|
||||
* @param {{ object: Partial<App.Types['subscription']>, confirm_password: string }} rawData - The raw form data object
|
||||
* @returns {{ subscription: Partial<App.Types['subscription']> }} Processed user data
|
||||
*/
|
||||
export function processSubscriptionFormData(rawData) {
|
||||
@@ -166,3 +166,39 @@ export function processSubscriptionFormData(rawData) {
|
||||
console.dir(clean);
|
||||
return clean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the raw form data into the expected car data structure
|
||||
* @param {{ object: Partial<App.Types['car']>, confirm_password: string }} rawData - The raw form data object
|
||||
* @returns {{ car: Partial<App.Types['car']> }} Processed user data
|
||||
*/
|
||||
export function processCarFormData(rawData) {
|
||||
/** @type {{ car: Partial<App.Types['car']> }} */
|
||||
let processedData = {
|
||||
car: {
|
||||
id: Number(rawData.object.id) || 0,
|
||||
name: String(rawData.object.name) || '',
|
||||
status: Number(rawData.object.status) || 0,
|
||||
brand: String(rawData.object.brand) || '',
|
||||
model: String(rawData.object.model) || '',
|
||||
price: Number(rawData.object.price) || 0,
|
||||
rate: Number(rawData.object.rate) || 0,
|
||||
licence_plate: String(rawData.object.licence_plate) || '',
|
||||
start_date: toRFC3339(String(rawData.object.start_date)) || '',
|
||||
end_date: toRFC3339(String(rawData.object.end_date)) || '',
|
||||
color: String(rawData.object.color) || '',
|
||||
notes: String(rawData.object.notes) || '',
|
||||
location: {
|
||||
latitude: Number(rawData.object.location?.latitude) || 0,
|
||||
longitude: Number(rawData.object.location?.longitude) || 0
|
||||
},
|
||||
damages: rawData.object.damages || [],
|
||||
insurances: rawData.object.insurances || []
|
||||
}
|
||||
};
|
||||
const clean = JSON.parse(JSON.stringify(processedData), (key, value) =>
|
||||
value !== null && value !== '' ? value : undefined
|
||||
);
|
||||
console.dir(clean);
|
||||
return clean;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user