frontend: real world movement
This commit is contained in:
@@ -1,8 +1,17 @@
|
||||
import { BASE_API_URI } from "$lib/utils/constants";
|
||||
import { formatError, userDatesFromRFC3339 } from "$lib/utils/helpers";
|
||||
import {
|
||||
formatError,
|
||||
userDatesFromRFC3339,
|
||||
userDatesToRFC3339,
|
||||
} from "$lib/utils/helpers";
|
||||
import { fail, redirect } from "@sveltejs/kit";
|
||||
import { toRFC3339 } from "$lib/utils/helpers";
|
||||
|
||||
/**
|
||||
* @typedef {Object} UpdateData
|
||||
* @property {Partial<App.Locals['user']>} user
|
||||
*/
|
||||
|
||||
/** @type {import('./$types').PageServerLoad} */
|
||||
export async function load({ locals, params }) {
|
||||
// redirect user if not logged in
|
||||
@@ -24,6 +33,7 @@ export const actions = {
|
||||
updateUser: async ({ request, fetch, cookies, locals }) => {
|
||||
let formData = await request.formData();
|
||||
|
||||
/** @type {App.Types['licenceCategory'][]} */
|
||||
const licenceCategories = formData
|
||||
.getAll("licence_categories[]")
|
||||
.filter((value) => typeof value === "string")
|
||||
@@ -34,11 +44,10 @@ export const actions = {
|
||||
console.error("Failed to parse licence category:", value);
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.filter(Boolean);
|
||||
});
|
||||
|
||||
/** @type {Partial<App.Locals['user']>} */
|
||||
const updateData = {
|
||||
const userData = {
|
||||
id: Number(formData.get("id")),
|
||||
first_name: String(formData.get("first_name")),
|
||||
last_name: String(formData.get("last_name")),
|
||||
@@ -48,7 +57,7 @@ export const actions = {
|
||||
address: String(formData.get("address")),
|
||||
zip_code: String(formData.get("zip_code")),
|
||||
city: String(formData.get("city")),
|
||||
date_of_birth: toRFC3339(formData.get("birth_date")),
|
||||
date_of_birth: toRFC3339(formData.get("date_of_birth")),
|
||||
company: String(formData.get("company")),
|
||||
profile_picture: String(formData.get("profile_picture")),
|
||||
membership: {
|
||||
@@ -64,9 +73,7 @@ export const actions = {
|
||||
},
|
||||
bank_account: {
|
||||
id: Number(formData.get("bank_account_id")),
|
||||
mandate_date_signed: toRFC3339(
|
||||
String(formData.get("mandate_date_signed"))
|
||||
),
|
||||
mandate_date_signed: toRFC3339(formData.get("mandate_date_signed")),
|
||||
bank: String(formData.get("bank")),
|
||||
account_holder_name: String(formData.get("account_holder_name")),
|
||||
iban: String(formData.get("iban")),
|
||||
@@ -83,11 +90,17 @@ export const actions = {
|
||||
licence_categories: licenceCategories,
|
||||
},
|
||||
};
|
||||
|
||||
// userDatesToRFC3339(userData);
|
||||
|
||||
/** @type {UpdateData} */
|
||||
const updateData = { user: userData };
|
||||
// Remove undefined or null properties
|
||||
const cleanUpdateData = JSON.parse(
|
||||
JSON.stringify(updateData),
|
||||
(key, value) => (value !== null && value !== "" ? value : undefined)
|
||||
);
|
||||
|
||||
console.dir(formData);
|
||||
console.dir(cleanUpdateData);
|
||||
const apiURL = `${BASE_API_URI}/backend/users/update/`;
|
||||
|
||||
Reference in New Issue
Block a user