generated from microverseinc/readme-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'profile' into profileFront
- Loading branch information
Showing
15 changed files
with
431 additions
and
72 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,2 @@ | ||
import Payments from '../components/profile/Payment'; | ||
export default Payments; |
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,2 @@ | ||
import UserProfileCard from '../components/profile/PersonalInfo'; | ||
export default UserProfileCard; |
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,2 @@ | ||
import Preferences from '../components/profile/Preferences'; | ||
export default Preferences; |
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,2 @@ | ||
import Security from '../components/profile/security'; | ||
export default Security; |
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,43 @@ | ||
import { NextResponse } from 'next/server'; | ||
import prisma from "@/app/libs/prismadb"; | ||
import getCurrentUser from "@/app/actions/getCurrentUser"; | ||
|
||
// Handler for GET request to retrieve preferences | ||
export async function GET() { | ||
const currentUser = await getCurrentUser(); | ||
|
||
if (!currentUser) { | ||
return NextResponse.error(); | ||
} | ||
|
||
// Retrieve user preferences from the database | ||
const user = await prisma.user.findUnique({ | ||
where: { id: currentUser.id }, | ||
select: { | ||
currency: true, | ||
language: true, | ||
}, | ||
}); | ||
|
||
return NextResponse.json(user); | ||
} | ||
|
||
// Handler for POST request to save preferences | ||
export async function POST(request: Request) { | ||
const currentUser = await getCurrentUser(); | ||
|
||
if (!currentUser) { | ||
return NextResponse.error(); | ||
} | ||
|
||
const body = await request.json(); | ||
const { currency, language } = body; | ||
|
||
// Save preferences to the database | ||
await prisma.user.update({ | ||
where: { id: currentUser.id }, | ||
data: { currency, language }, | ||
}); | ||
|
||
return NextResponse.json({ message: 'Preferences saved successfully' }); | ||
} |
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,65 @@ | ||
import { NextResponse } from "next/server"; | ||
import prisma from "@/app/libs/prismadb"; | ||
import getCurrentUser from "@/app/actions/getCurrentUser"; | ||
|
||
// Handler for the PUT | ||
export async function PUT(request: Request) { | ||
// Get the current user | ||
const currentUser = await getCurrentUser(); | ||
|
||
// If there is no current user, return an error response | ||
if (!currentUser) { | ||
return NextResponse.error(); | ||
} | ||
|
||
// Parse the request body as JSON | ||
const body = await request.json(); | ||
|
||
// Destructure the required properties from the request body | ||
const { | ||
name, | ||
surname, | ||
username, | ||
dateOfBirth, | ||
email, | ||
telephone, | ||
gender, | ||
image | ||
} = body; | ||
|
||
// Update the user's favoriteIds in the database | ||
const user = await prisma.user.update({ | ||
where:{id: currentUser.id}, | ||
data: { | ||
name, | ||
surname, | ||
username, | ||
dateOfBirth, | ||
email, | ||
telephone, | ||
gender, | ||
image | ||
} | ||
}); | ||
|
||
// Return the created listing as a JSON response | ||
return NextResponse.json(user); | ||
} | ||
// Handler for the GET request | ||
export async function GET(request: Request) { | ||
try { | ||
// Get the current user | ||
const currentUser = await getCurrentUser(); | ||
|
||
// If there is no current user, return an error response | ||
if (!currentUser) { | ||
return NextResponse.error(); | ||
} | ||
|
||
// Return the user data as a JSON response | ||
return NextResponse.json(currentUser); | ||
} catch (error) { | ||
console.error(error); | ||
return NextResponse.error(); | ||
} | ||
} |
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,59 @@ | ||
import { NextResponse } from "next/server"; | ||
import prisma from "@/app/libs/prismadb"; | ||
import bcrypt from "bcrypt"; | ||
import getCurrentUser from "@/app/actions/getCurrentUser"; | ||
|
||
|
||
export async function PUT(request: Request) { | ||
try { | ||
const body = await request.json(); | ||
|
||
const { password , recoveryEmail } = body; | ||
|
||
// Get the current user | ||
const currentUser = await getCurrentUser(); | ||
|
||
// If no user is found, return an error response | ||
if (!currentUser) { | ||
return NextResponse.error(); | ||
} | ||
const hashedPassword = await bcrypt.hash(password, 12); | ||
|
||
const user = await prisma.user.update({ | ||
where: { | ||
id: currentUser.id | ||
}, | ||
data: { hashedPassword, recoveryEmail }, | ||
}); | ||
|
||
return NextResponse.json(user); | ||
} catch (error) { | ||
console.error(error); | ||
return NextResponse.json({ error: "Internal Server Error" }, { status: 500 }); | ||
} | ||
} | ||
//Delete user account endpoint | ||
export async function DELETE(request: Request) { | ||
try { | ||
// Get the current user | ||
const currentUser = await getCurrentUser(); | ||
|
||
// If no user is found, return an error response | ||
if (!currentUser) { | ||
return NextResponse.error(); | ||
} | ||
|
||
// Delete the user from the database | ||
await prisma.user.delete({ | ||
where: { | ||
id: currentUser.id | ||
} | ||
}); | ||
|
||
// Return a success response | ||
return NextResponse.json({ message: "User account deleted successfully" }); | ||
} catch (error) { | ||
console.error(error); | ||
return NextResponse.json({ error: "Internal Server Error" }, { status: 500 }); | ||
} | ||
} |
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
Oops, something went wrong.