upd: api mobile
Deskripsi: - api mobile load, edit, cancel project - api moblie update status task project No Issues
This commit is contained in:
@@ -1,18 +1,20 @@
|
||||
import { prisma } from "@/module/_global";
|
||||
import { funGetUserByCookies } from "@/module/auth";
|
||||
import { createLogUser } from "@/module/user";
|
||||
import { funGetUserById } from "@/module/auth";
|
||||
import { createLogUserMobile } from "@/module/user";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
|
||||
// HAPUS DETAIL PROJECT
|
||||
export async function DELETE(request: Request, context: { params: { id: string } }) {
|
||||
try {
|
||||
const user = await funGetUserByCookies()
|
||||
if (user.id == undefined) {
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
|
||||
}
|
||||
const { id } = context.params;
|
||||
const { idProject } = (await request.json());
|
||||
const { idProject, user } = (await request.json());
|
||||
|
||||
const userMobile = await funGetUserById({ id: String(user) })
|
||||
|
||||
if (userMobile.id == "null" || userMobile.id == undefined || userMobile.id == "") {
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 200 });
|
||||
}
|
||||
|
||||
const data = await prisma.projectTask.count({
|
||||
where: {
|
||||
@@ -26,7 +28,7 @@ export async function DELETE(request: Request, context: { params: { id: string }
|
||||
success: false,
|
||||
message: "Hapus tahapan kegiatan gagal, data tidak ditemukan",
|
||||
},
|
||||
{ status: 404 }
|
||||
{ status: 200 }
|
||||
);
|
||||
}
|
||||
|
||||
@@ -68,14 +70,13 @@ export async function DELETE(request: Request, context: { params: { id: string }
|
||||
})
|
||||
|
||||
// create log user
|
||||
const log = await createLogUser({ act: 'DELETE', desc: 'User menghapus tahapan kegiatan', table: 'projectTask', data: String(id) })
|
||||
const log = await createLogUserMobile({ act: 'DELETE', desc: 'User menghapus tahapan kegiatan', table: 'projectTask', data: String(id), user: userMobile.id })
|
||||
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: true,
|
||||
message: "Tahapan kegiatan berhasil dihapus",
|
||||
data,
|
||||
},
|
||||
{ status: 200 }
|
||||
);
|
||||
@@ -89,13 +90,13 @@ export async function DELETE(request: Request, context: { params: { id: string }
|
||||
// EDIT STATUS DETAIL PROJECT
|
||||
export async function PUT(request: Request, context: { params: { id: string } }) {
|
||||
try {
|
||||
const user = await funGetUserByCookies()
|
||||
if (user.id == undefined) {
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
|
||||
}
|
||||
|
||||
const { id } = context.params;
|
||||
const { status, idProject } = (await request.json());
|
||||
const { status, idProject, user } = (await request.json());
|
||||
const userMobile = await funGetUserById({ id: String(user) })
|
||||
|
||||
if (userMobile.id == "null" || userMobile.id == undefined || userMobile.id == "") {
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 200 });
|
||||
}
|
||||
|
||||
const data = await prisma.projectTask.count({
|
||||
where: {
|
||||
@@ -108,7 +109,7 @@ export async function PUT(request: Request, context: { params: { id: string } })
|
||||
{
|
||||
success: false, message: "Gagal mendapatkan kegiatan, data tidak ditemukan",
|
||||
},
|
||||
{ status: 404 }
|
||||
{ status: 200 }
|
||||
);
|
||||
}
|
||||
|
||||
@@ -152,9 +153,9 @@ export async function PUT(request: Request, context: { params: { id: string } })
|
||||
})
|
||||
|
||||
// create log user
|
||||
const log = await createLogUser({ act: 'UPDATE', desc: 'User mengupdate status tahapan kegiatan', table: 'projectTask', data: String(id) })
|
||||
const log = await createLogUserMobile({ act: 'UPDATE', desc: 'User mengupdate status tahapan kegiatan', table: 'projectTask', data: String(id), user: userMobile.id })
|
||||
|
||||
return NextResponse.json({ success: true, message: "Status tahapan kegiatan berhasil diupdate", data }, { status: 200 });
|
||||
return NextResponse.json({ success: true, message: "Status tahapan kegiatan berhasil diupdate" }, { status: 200 });
|
||||
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
@@ -166,12 +167,14 @@ export async function PUT(request: Request, context: { params: { id: string } })
|
||||
// GET ONE DETAIL PROJECT
|
||||
export async function GET(request: Request, context: { params: { id: string } }) {
|
||||
try {
|
||||
const user = await funGetUserByCookies()
|
||||
if (user.id == undefined) {
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
|
||||
const { id } = context.params;
|
||||
const { user } = (await request.json());
|
||||
const userMobile = await funGetUserById({ id: String(user) })
|
||||
|
||||
if (userMobile.id == "null" || userMobile.id == undefined || userMobile.id == "") {
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 200 });
|
||||
}
|
||||
|
||||
const { id } = context.params;
|
||||
const data = await prisma.projectTask.findUnique({
|
||||
where: {
|
||||
id: String(id),
|
||||
@@ -184,7 +187,7 @@ export async function GET(request: Request, context: { params: { id: string } })
|
||||
{
|
||||
success: false, message: "Gagal mendapatkan kegiatan, data tidak ditemukan",
|
||||
},
|
||||
{ status: 404 }
|
||||
{ status: 200 }
|
||||
);
|
||||
}
|
||||
|
||||
@@ -199,15 +202,13 @@ export async function GET(request: Request, context: { params: { id: string } })
|
||||
// EDIT DETAIL PROJECT
|
||||
export async function POST(request: Request, context: { params: { id: string } }) {
|
||||
try {
|
||||
const user = await funGetUserByCookies()
|
||||
if (user.id == undefined) {
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
|
||||
}
|
||||
|
||||
const { id } = context.params;
|
||||
const { title, dateStart, dateEnd } = (await request.json());
|
||||
|
||||
const { title, dateStart, dateEnd, user } = (await request.json());
|
||||
const userMobile = await funGetUserById({ id: String(user) })
|
||||
|
||||
if (userMobile.id == "null" || userMobile.id == undefined || userMobile.id == "") {
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 200 });
|
||||
}
|
||||
|
||||
const dataTask = await prisma.projectTask.count({
|
||||
where: {
|
||||
@@ -220,7 +221,7 @@ export async function POST(request: Request, context: { params: { id: string } }
|
||||
{
|
||||
success: false, message: "Gagal mendapatkan kegiatan, data tidak ditemukan",
|
||||
},
|
||||
{ status: 404 }
|
||||
{ status: 200 }
|
||||
);
|
||||
}
|
||||
|
||||
@@ -236,9 +237,9 @@ export async function POST(request: Request, context: { params: { id: string } }
|
||||
})
|
||||
|
||||
// create log user
|
||||
const log = await createLogUser({ act: 'UPDATE', desc: 'User mengupdate tahapan kegiatan', table: 'projectTask', data: String(id) })
|
||||
const log = await createLogUserMobile({ act: 'UPDATE', desc: 'User mengupdate tahapan kegiatan', table: 'projectTask', data: String(id), user: userMobile.id })
|
||||
|
||||
return NextResponse.json({ success: true, message: "Detail tahapan kegiatan berhasil diupdate", data }, { status: 200 });
|
||||
return NextResponse.json({ success: true, message: "Detail tahapan kegiatan berhasil diupdate" }, { status: 200 });
|
||||
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
|
||||
Reference in New Issue
Block a user