Merge pull request #445 from bipproduction/amalia/14-mei-25
Amalia/14 mei 25
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { DIR, funUploadFile, funViewDir, prisma } from "@/module/_global";
|
import { DIR, funUploadFile, funViewDir, prisma } from "@/module/_global";
|
||||||
import { funGetUserByCookies, funGetUserById } from "@/module/auth";
|
import { funGetUserById } from "@/module/auth";
|
||||||
import { createLogUser } from "@/module/user";
|
import { createLogUser } from "@/module/user";
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
|
|
||||||
@@ -38,12 +38,16 @@ export async function GET(request: Request) {
|
|||||||
// CREATE BANNER
|
// CREATE BANNER
|
||||||
export async function POST(request: Request) {
|
export async function POST(request: Request) {
|
||||||
try {
|
try {
|
||||||
console.log('masuk')
|
console.log('masuklas')
|
||||||
|
console.log(request)
|
||||||
const body = await request.formData()
|
const body = await request.formData()
|
||||||
const file = body.get("file") as File;
|
const fileAwal = body.get("file");
|
||||||
|
const file = JSON.parse(fileAwal as string)
|
||||||
|
const fileFix = file as File
|
||||||
|
const fileCoba = new File([fileFix], fileFix.name, { type: fileFix.type});
|
||||||
const data = body.get("data");
|
const data = body.get("data");
|
||||||
|
|
||||||
console.log(data)
|
console.log(body, fileCoba)
|
||||||
|
|
||||||
const { title, user } = JSON.parse(data as string)
|
const { title, user } = JSON.parse(data as string)
|
||||||
|
|
||||||
@@ -54,12 +58,12 @@ export async function POST(request: Request) {
|
|||||||
const userLogin = await funGetUserById({ id: user })
|
const userLogin = await funGetUserById({ id: user })
|
||||||
|
|
||||||
|
|
||||||
const fExt = file.name.split(".").pop()
|
const fExt = fileCoba.name.split(".").pop()
|
||||||
const fName = file.name.replace("." + fExt, "")
|
const fName = fileCoba.name.replace("." + fExt, "")
|
||||||
const newFile = new File([file], file.name, { type: file.type });
|
const newFile = new File([fileCoba], fileCoba.name, { type: fileCoba.type });
|
||||||
|
|
||||||
const ini = funViewDir({ dirId: DIR.user })
|
const ini = funViewDir({ dirId: DIR.user })
|
||||||
const upload = await funUploadFile({ file: newFile, dirId: DIR.banner })
|
const upload = await funUploadFile({ file: fileCoba, dirId: DIR.banner })
|
||||||
if (upload.success) {
|
if (upload.success) {
|
||||||
const create = await prisma.bannerImage.create({
|
const create = await prisma.bannerImage.create({
|
||||||
data: {
|
data: {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { prisma } from "@/module/_global";
|
import { prisma } from "@/module/_global";
|
||||||
import { funGetUserByCookies } from "@/module/auth";
|
import { funGetUserById } from "@/module/auth";
|
||||||
import { createLogUser } from "@/module/user";
|
import { createLogUserMobile } from "@/module/user";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
|
|
||||||
@@ -8,13 +8,13 @@ import { NextResponse } from "next/server";
|
|||||||
// ADD MEMBER PROJECT
|
// ADD MEMBER PROJECT
|
||||||
export async function POST(request: Request, context: { params: { id: string } }) {
|
export async function POST(request: Request, context: { params: { id: string } }) {
|
||||||
try {
|
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 { 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({
|
const data = await prisma.project.count({
|
||||||
where: {
|
where: {
|
||||||
@@ -27,7 +27,7 @@ export async function POST(request: Request, context: { params: { id: string } }
|
|||||||
{
|
{
|
||||||
success: false, message: "Gagal mendapatkan kegiatan, data tidak ditemukan",
|
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
|
// 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 });
|
return NextResponse.json({ success: true, message: "Berhasil menambahkan anggota kegiatan" }, { status: 200 });
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -56,13 +56,14 @@ export async function POST(request: Request, context: { params: { id: string } }
|
|||||||
// MENGELUARKAN ANGGOTA
|
// MENGELUARKAN ANGGOTA
|
||||||
export async function DELETE(request: Request, context: { params: { id: string } }) {
|
export async function DELETE(request: Request, context: { params: { id: string } }) {
|
||||||
try {
|
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 { 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({
|
const data = await prisma.project.count({
|
||||||
where: {
|
where: {
|
||||||
@@ -77,7 +78,7 @@ export async function DELETE(request: Request, context: { params: { id: string }
|
|||||||
success: false,
|
success: false,
|
||||||
message: "Gagal, data tugas tidak ditemukan",
|
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
|
// 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 });
|
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
|
//GET MEMBER ALL USER ID GROUP
|
||||||
export async function GET(request: Request, context: { params: { id: string } }) {
|
export async function GET(request: Request, context: { params: { id: string } }) {
|
||||||
try {
|
try {
|
||||||
const user = await funGetUserByCookies()
|
const { searchParams } = new URL(request.url);
|
||||||
if (user.id == undefined) {
|
const name = searchParams.get('search');
|
||||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
|
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 { id } = context.params
|
||||||
const groupId = user.idGroup
|
const groupId = userMobile.idGroup
|
||||||
const userId = user.id
|
const userId = userMobile.id
|
||||||
const { searchParams } = new URL(request.url);
|
|
||||||
const name = searchParams.get('search');
|
|
||||||
|
|
||||||
const data = await prisma.project.findUnique({
|
const data = await prisma.project.findUnique({
|
||||||
where: {
|
where: {
|
||||||
@@ -126,7 +129,7 @@ export async function GET(request: Request, context: { params: { id: string } })
|
|||||||
success: false,
|
success: false,
|
||||||
message: "Gagal, data tugas tidak ditemukan",
|
message: "Gagal, data tugas tidak ditemukan",
|
||||||
},
|
},
|
||||||
{ status: 404 }
|
{ status: 200 }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { prisma } from "@/module/_global";
|
import { prisma } from "@/module/_global";
|
||||||
import { funGetUserById } from "@/module/auth";
|
import { funGetUserById } from "@/module/auth";
|
||||||
import { createLogUserMobile } from "@/module/user";
|
import { createLogUserMobile } from "@/module/user";
|
||||||
|
import moment from "moment";
|
||||||
import { NextResponse } from "next/server";
|
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 } }) {
|
export async function GET(request: Request, context: { params: { id: string } }) {
|
||||||
try {
|
try {
|
||||||
const { id } = context.params;
|
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) })
|
const userMobile = await funGetUserById({ id: String(user) })
|
||||||
|
|
||||||
if (userMobile.id == "null" || userMobile.id == undefined || userMobile.id == "") {
|
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) {
|
if (!data) {
|
||||||
return NextResponse.json(
|
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) {
|
} catch (error) {
|
||||||
console.error(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 });
|
return NextResponse.json({ success: false, message: "Gagal mendapatkan kegiatan, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 });
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { title } from 'process';
|
||||||
import { DIR, funSendWebPush, funUploadFile, prisma } from "@/module/_global";
|
import { DIR, funSendWebPush, funUploadFile, prisma } from "@/module/_global";
|
||||||
import { funGetUserById } from "@/module/auth";
|
import { funGetUserById } from "@/module/auth";
|
||||||
import { createLogUserMobile } from "@/module/user";
|
import { createLogUserMobile } from "@/module/user";
|
||||||
@@ -179,13 +180,14 @@ export async function POST(request: Request) {
|
|||||||
|
|
||||||
if (task.length > 0) {
|
if (task.length > 0) {
|
||||||
const dataProject = task.map((v: any) => ({
|
const dataProject = task.map((v: any) => ({
|
||||||
..._.omit(v, ["dateStart", "dateEnd", "name"]),
|
..._.omit(v, ["dateStart", "dateEnd", "name", "dateEndFix", "dateStartFix"]),
|
||||||
idProject: data.id,
|
idProject: data.id,
|
||||||
title: v.title,
|
title: v.title,
|
||||||
dateStart: new Date(v.dateStart),
|
dateStart: new Date(v.dateStartFix),
|
||||||
dateEnd: new Date(v.dateEnd),
|
dateEnd: new Date(v.dateEndFix),
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
|
||||||
const insertTask = await prisma.projectTask.createMany({
|
const insertTask = await prisma.projectTask.createMany({
|
||||||
data: dataProject
|
data: dataProject
|
||||||
})
|
})
|
||||||
@@ -337,7 +339,7 @@ export async function POST(request: Request) {
|
|||||||
|
|
||||||
const pushNotif = dataPush.filter((item) => item.subscription != undefined)
|
const pushNotif = dataPush.filter((item) => item.subscription != undefined)
|
||||||
|
|
||||||
const sendWebPush = await funSendWebPush({ sub: pushNotif, message: { title: 'Kegiatan Baru', body: 'Terdapat kegiatan baru. Silahkan periksa detailnya.' } })
|
// const sendWebPush = await funSendWebPush({ sub: pushNotif, message: { title: 'Kegiatan Baru', body: 'Terdapat kegiatan baru. Silahkan periksa detailnya.' } })
|
||||||
const insertNotif = await prisma.notifications.createMany({
|
const insertNotif = await prisma.notifications.createMany({
|
||||||
data: dataNotif
|
data: dataNotif
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user