Merge pull request 'API Profile' (#5) from mobile/27-aug-25 into staging
Reviewed-on: bip/hipmi#5
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
|
||||
|
||||
## [1.4.31](https://wibugit.wibudev.com/bip/hipmi/compare/v1.4.30...v1.4.31) (2025-08-27)
|
||||
|
||||
## [1.4.30](https://wibugit.wibudev.com/bip/hipmi/compare/v1.4.29...v1.4.30) (2025-08-26)
|
||||
|
||||
## [1.4.29](https://wibugit.wibudev.com/bip/hipmi/compare/v1.4.28...v1.4.29) (2025-08-25)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hipmi",
|
||||
"version": "1.4.30",
|
||||
"version": "1.4.31",
|
||||
"private": true,
|
||||
"prisma": {
|
||||
"seed": "bun prisma/seed.ts"
|
||||
|
||||
@@ -47,45 +47,82 @@ async function PUT(request: Request, { params }: { params: { id: string } }) {
|
||||
}
|
||||
|
||||
try {
|
||||
let message;
|
||||
const { id } = params;
|
||||
const body = await request.json();
|
||||
const { data } = body;
|
||||
const { searchParams } = new URL(request.url);
|
||||
const category = searchParams.get("category");
|
||||
|
||||
const cekEmail = await prisma.profile.findUnique({
|
||||
where: {
|
||||
email: data.email,
|
||||
},
|
||||
});
|
||||
|
||||
if (category === "profile") {
|
||||
const cekEmail = await prisma.profile.findUnique({
|
||||
where: {
|
||||
email: data.email,
|
||||
},
|
||||
});
|
||||
if (cekEmail && cekEmail.id != id)
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: "Email sudah digunakan",
|
||||
});
|
||||
const updateData = await prisma.profile.update({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
data: {
|
||||
name: data.name,
|
||||
email: data.email,
|
||||
alamat: data.alamat,
|
||||
jenisKelamin: data.jenisKelamin,
|
||||
},
|
||||
});
|
||||
if (!updateData) {
|
||||
return NextResponse.json({ success: false, message: "Gagal update" });
|
||||
}
|
||||
|
||||
if (cekEmail && cekEmail.id != id)
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: "Email sudah digunakan",
|
||||
message = "Berhasil edit profile";
|
||||
} else if (category === "photo") {
|
||||
const updateData = await prisma.profile.update({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
data: {
|
||||
imageId: data.fileId,
|
||||
},
|
||||
});
|
||||
|
||||
const updateData = await prisma.profile.update({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
data: {
|
||||
name: data.name,
|
||||
email: data.email,
|
||||
alamat: data.alamat,
|
||||
jenisKelamin: data.jenisKelamin,
|
||||
},
|
||||
});
|
||||
if (!updateData) {
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: "Gagal update foto",
|
||||
});
|
||||
}
|
||||
|
||||
if (!updateData) {
|
||||
return NextResponse.json({ success: false, message: "Gagal update" });
|
||||
message = "Berhasil edit foto profile";
|
||||
} else if (category === "background") {
|
||||
const updateData = await prisma.profile.update({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
data: {
|
||||
imageBackgroundId: data.fileId,
|
||||
},
|
||||
});
|
||||
if (!updateData) {
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: "Gagal update background",
|
||||
});
|
||||
}
|
||||
|
||||
message = "Berhasil edit background profile";
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: "Berhasil edit profile",
|
||||
message: message,
|
||||
});
|
||||
} catch (error) {
|
||||
backendLogger.error("Error edit profile", error);
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
|
||||
@@ -7,27 +7,15 @@ async function POST(request: Request) {
|
||||
try {
|
||||
const { data } = await request.json();
|
||||
|
||||
const existingEmail = await prisma.profile.findUnique({
|
||||
where: {
|
||||
email: data.email,
|
||||
},
|
||||
});
|
||||
|
||||
if (existingEmail) {
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: "Email telah digunakan",
|
||||
status: 400,
|
||||
});
|
||||
}
|
||||
|
||||
const create = await prisma.profile.create({
|
||||
await prisma.profile.create({
|
||||
data: {
|
||||
userId: data.id,
|
||||
name: data.name,
|
||||
email: data.email,
|
||||
alamat: data.alamat,
|
||||
jenisKelamin: data.jenisKelamin,
|
||||
imageId: data.imageId || "",
|
||||
imageBackgroundId: data.imageBackgroundId || "",
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
38
src/app/api/mobile/validate/email/route.ts
Normal file
38
src/app/api/mobile/validate/email/route.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { prisma } from "@/lib";
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const { data } = await request.json();
|
||||
const email = data;
|
||||
|
||||
try {
|
||||
const existingEmail = await prisma.profile.findUnique({
|
||||
where: {
|
||||
email: email,
|
||||
},
|
||||
});
|
||||
|
||||
if (existingEmail) {
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: "Email telah digunakan",
|
||||
status: 400,
|
||||
});
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: "Email tidak digunakan",
|
||||
status: 200,
|
||||
});
|
||||
} catch (error) {
|
||||
console.log("error", error);
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Gagal validasi email",
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user