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.
|
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.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.4.29](https://wibugit.wibudev.com/bip/hipmi/compare/v1.4.28...v1.4.29) (2025-08-25)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hipmi",
|
"name": "hipmi",
|
||||||
"version": "1.4.30",
|
"version": "1.4.31",
|
||||||
"private": true,
|
"private": true,
|
||||||
"prisma": {
|
"prisma": {
|
||||||
"seed": "bun prisma/seed.ts"
|
"seed": "bun prisma/seed.ts"
|
||||||
|
|||||||
@@ -47,45 +47,82 @@ async function PUT(request: Request, { params }: { params: { id: string } }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
let message;
|
||||||
const { id } = params;
|
const { id } = params;
|
||||||
const body = await request.json();
|
const body = await request.json();
|
||||||
const { data } = body;
|
const { data } = body;
|
||||||
|
const { searchParams } = new URL(request.url);
|
||||||
|
const category = searchParams.get("category");
|
||||||
|
|
||||||
const cekEmail = await prisma.profile.findUnique({
|
if (category === "profile") {
|
||||||
where: {
|
const cekEmail = await prisma.profile.findUnique({
|
||||||
email: data.email,
|
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)
|
message = "Berhasil edit profile";
|
||||||
return NextResponse.json({
|
} else if (category === "photo") {
|
||||||
success: false,
|
const updateData = await prisma.profile.update({
|
||||||
message: "Email sudah digunakan",
|
where: {
|
||||||
|
id: id,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
imageId: data.fileId,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const updateData = await prisma.profile.update({
|
if (!updateData) {
|
||||||
where: {
|
return NextResponse.json({
|
||||||
id: id,
|
success: false,
|
||||||
},
|
message: "Gagal update foto",
|
||||||
data: {
|
});
|
||||||
name: data.name,
|
}
|
||||||
email: data.email,
|
|
||||||
alamat: data.alamat,
|
|
||||||
jenisKelamin: data.jenisKelamin,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!updateData) {
|
message = "Berhasil edit foto profile";
|
||||||
return NextResponse.json({ success: false, message: "Gagal update" });
|
} 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({
|
return NextResponse.json({
|
||||||
success: true,
|
success: true,
|
||||||
message: "Berhasil edit profile",
|
message: message,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
backendLogger.error("Error edit profile", error);
|
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{
|
{
|
||||||
success: false,
|
success: false,
|
||||||
|
|||||||
@@ -7,27 +7,15 @@ async function POST(request: Request) {
|
|||||||
try {
|
try {
|
||||||
const { data } = await request.json();
|
const { data } = await request.json();
|
||||||
|
|
||||||
const existingEmail = await prisma.profile.findUnique({
|
await prisma.profile.create({
|
||||||
where: {
|
|
||||||
email: data.email,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (existingEmail) {
|
|
||||||
return NextResponse.json({
|
|
||||||
success: false,
|
|
||||||
message: "Email telah digunakan",
|
|
||||||
status: 400,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const create = await prisma.profile.create({
|
|
||||||
data: {
|
data: {
|
||||||
userId: data.id,
|
userId: data.id,
|
||||||
name: data.name,
|
name: data.name,
|
||||||
email: data.email,
|
email: data.email,
|
||||||
alamat: data.alamat,
|
alamat: data.alamat,
|
||||||
jenisKelamin: data.jenisKelamin,
|
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