Skip to content

Commit

Permalink
refcator : added helper methods for updating profile
Browse files Browse the repository at this point in the history
  • Loading branch information
ad956 committed Jul 11, 2024
1 parent 8ad4689 commit c6345c3
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/lib/update-profile/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"use server";

import updateAddress from "./update-address";
import updatePersonal from "./update-personal";
import updateSecurity from "./update-security";

export { updateAddress, updatePersonal, updateSecurity };
25 changes: 25 additions & 0 deletions app/lib/update-profile/update-address.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import getBaseUrl from "@utils/getBaseUrl";
import { getSessionToken } from "../sessions/sessionUtils";

export default async function updateAddress(filteredFields: any) {
const session = getSessionToken();
const serverUrl = getBaseUrl();

const headers = {
Authorization: `Bearer ${session}`,
};

try {
const response = await fetch(`${serverUrl}/api/update-profile/address`, {
method: "PUT",
headers,
body: JSON.stringify(filteredFields),
});

const success = await response.json();

return success;
} catch (error) {
console.error("Error updating address information:", error);
}
}
25 changes: 25 additions & 0 deletions app/lib/update-profile/update-personal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import getBaseUrl from "@utils/getBaseUrl";
import { getSessionToken } from "../sessions/sessionUtils";

export default async function updatePersonal(filteredFields: any) {
const session = getSessionToken();
const serverUrl = getBaseUrl();

const headers = {
Authorization: `Bearer ${session}`,
};

try {
const response = await fetch(`${serverUrl}/api/update-profile/personal`, {
method: "PUT",
headers,
body: JSON.stringify(filteredFields),
});

const success = await response.json();

return success;
} catch (error) {
console.error("Error updating personal information:", error);
}
}
28 changes: 28 additions & 0 deletions app/lib/update-profile/update-security.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import getBaseUrl from "@utils/getBaseUrl";
import { getSessionToken } from "../sessions/sessionUtils";

export default async function updateSecurity(password: string) {
const session = getSessionToken();
const serverUrl = getBaseUrl();

const headers = {
Authorization: `Bearer ${session}`,
};

try {
const response = await fetch(
`${serverUrl}/api/update-profile/reset-password`,
{
method: "PUT",
headers,
body: JSON.stringify({ password }),
}
);

const success = await response.json();

return success;
} catch (error) {
console.error("Error updating password :", error);
}
}

0 comments on commit c6345c3

Please sign in to comment.