upd: api mobile

Deskripsi:
- tambah member project
- mengeluarkan anggota project
- fix tanggal tambah task project

No Issues
This commit is contained in:
amel
2025-05-13 17:44:59 +08:00
parent e8133166b5
commit bf1f2f0291
2 changed files with 35 additions and 28 deletions

View File

@@ -1,6 +1,6 @@
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 _ from "lodash";
import { NextResponse } from "next/server";
@@ -8,13 +8,13 @@ import { NextResponse } from "next/server";
// ADD MEMBER 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 { member } = (await request.json())
const { member, 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.project.count({
where: {
@@ -27,7 +27,7 @@ export async function POST(request: Request, context: { params: { id: string } }
{
success: false, message: "Gagal mendapatkan kegiatan, data tidak ditemukan",
},
{ status: 404 }
{ status: 200 }
);
}
@@ -44,7 +44,7 @@ export async function POST(request: Request, context: { params: { id: string } }
}
// create log user
const log = await createLogUser({ act: 'CREATE', desc: 'User menambah anggota kegiatan', table: 'project', data: String(id) })
const log = await createLogUserMobile({ act: 'CREATE', desc: 'User menambah anggota kegiatan', table: 'project', data: String(id), user: userMobile.id })
return NextResponse.json({ success: true, message: "Berhasil menambahkan anggota kegiatan" }, { status: 200 });
} catch (error) {
@@ -56,13 +56,14 @@ export async function POST(request: Request, context: { params: { id: string } }
// MENGELUARKAN ANGGOTA
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 { idUser } = (await request.json());
const { idUser, 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.project.count({
where: {
@@ -77,7 +78,7 @@ export async function DELETE(request: Request, context: { params: { id: string }
success: false,
message: "Gagal, data tugas tidak ditemukan",
},
{ status: 404 }
{ status: 200 }
);
}
@@ -89,7 +90,7 @@ export async function DELETE(request: Request, context: { params: { id: string }
})
// create log user
const log = await createLogUser({ act: 'DELETE', desc: 'User mengeluarkan anggota kegiatan', table: 'project', data: String(id) })
const log = await createLogUserMobile({ act: 'DELETE', desc: 'User mengeluarkan anggota kegiatan', table: 'project', data: String(id), user: userMobile.id })
return NextResponse.json({ success: true, message: "Berhasil mengeluarkan anggota kegiatan" }, { status: 200 });
@@ -102,16 +103,18 @@ export async function DELETE(request: Request, context: { params: { id: string }
//GET MEMBER ALL USER ID GROUP
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 { searchParams } = new URL(request.url);
const name = searchParams.get('search');
const user = searchParams.get("user");
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 groupId = user.idGroup
const userId = user.id
const { searchParams } = new URL(request.url);
const name = searchParams.get('search');
const groupId = userMobile.idGroup
const userId = userMobile.id
const data = await prisma.project.findUnique({
where: {
@@ -126,7 +129,7 @@ export async function GET(request: Request, context: { params: { id: string } })
success: false,
message: "Gagal, data tugas tidak ditemukan",
},
{ status: 404 }
{ status: 200 }
);
}

View File

@@ -1,6 +1,7 @@
import { prisma } from "@/module/_global";
import { funGetUserById } from "@/module/auth";
import { createLogUserMobile } from "@/module/user";
import moment from "moment";
import { NextResponse } from "next/server";
@@ -168,7 +169,8 @@ export async function PUT(request: Request, context: { params: { id: string } })
export async function GET(request: Request, context: { params: { id: string } }) {
try {
const { id } = context.params;
const { user } = (await request.json());
const { searchParams } = new URL(request.url);
const user = searchParams.get("user");
const userMobile = await funGetUserById({ id: String(user) })
if (userMobile.id == "null" || userMobile.id == undefined || userMobile.id == "") {
@@ -182,6 +184,8 @@ export async function GET(request: Request, context: { params: { id: string } })
}
})
const fixData = { ...data, dateStart: moment(data?.dateStart).format('YYYY-MM-DD'), dateEnd: moment(data?.dateEnd).format('YYYY-MM-DD') }
if (!data) {
return NextResponse.json(
{
@@ -191,7 +195,7 @@ export async function GET(request: Request, context: { params: { id: string } })
);
}
return NextResponse.json({ success: true, message: "Detail kegiatan berhasil ditemukan", data }, { status: 200 });
return NextResponse.json({ success: true, message: "Detail kegiatan berhasil ditemukan", data: fixData }, { status: 200 });
} catch (error) {
console.error(error);
return NextResponse.json({ success: false, message: "Gagal mendapatkan kegiatan, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 });