diff --git a/CHANGELOG.md b/CHANGELOG.md index 1080cf60..16a05ce3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,136 @@ 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.5.6](https://wibugit.wibudev.com/bip/hipmi/compare/v1.5.5...v1.5.6) (2025-10-21) + +## [1.5.5](https://wibugit.wibudev.com/bip/hipmi/compare/v1.5.4...v1.5.5) (2025-10-20) + +## [1.5.4](https://wibugit.wibudev.com/bip/hipmi/compare/v1.5.3...v1.5.4) (2025-10-17) + +## [1.5.3](https://wibugit.wibudev.com/bip/hipmi/compare/v1.5.2...v1.5.3) (2025-10-16) + +## [1.5.2](https://wibugit.wibudev.com/bip/hipmi/compare/v1.5.1...v1.5.2) (2025-10-15) + +## [1.5.1](https://wibugit.wibudev.com/bip/hipmi/compare/v1.5.0...v1.5.1) (2025-10-14) + +## 1.5.0 (2025-10-09) + + +### Features + +* admin app information ([bc10b80](https://wibugit.wibudev.com/bip/hipmi/commit/bc10b80139833966d3e39b52cabf577930552052)) +* admin sticker ([2a8c79f](https://wibugit.wibudev.com/bip/hipmi/commit/2a8c79fd09c3f7fd7ee58ac6896b17802dfe0147)) +* admin stiker ([e7858a2](https://wibugit.wibudev.com/bip/hipmi/commit/e7858a281223a81037219afec58e5f6b9e04be15)) +* **app / dev / login:** membuat page login ([91333b5](https://wibugit.wibudev.com/bip/hipmi/commit/91333b5c00b87da35a0d965f0678ff971484825b)) +* **app / dev / page:** modified file ([90c32b3](https://wibugit.wibudev.com/bip/hipmi/commit/90c32b345c1099c943a9b8f67b8aa257941484d9)) +* **app / dev / register:** membuat page register ([1e06aeb](https://wibugit.wibudev.com/bip/hipmi/commit/1e06aeb6998f00d77fa74849de11be182a0be676)) +* **dashboard admin:** membuat dashboard admin ([46da772](https://wibugit.wibudev.com/bip/hipmi/commit/46da772f3895bde770942c3d9044e6da0620ef1c)) +* **dashboard super admin:** membuat dashboard super admin ([c363736](https://wibugit.wibudev.com/bip/hipmi/commit/c3637366f9ebf24507c470714952ad2e572a0b0d)) +* **image:** menambahkan gambar logo ([c74bb6e](https://wibugit.wibudev.com/bip/hipmi/commit/c74bb6eceb401c55c3c297889fe43181406f3a22)) +* **landing page:** buat komponen landing page ([38cb10d](https://wibugit.wibudev.com/bip/hipmi/commit/38cb10da4ac8d68f1abd0163a0671036c15e1743)) +* **login:** - Membuat login page - Membuat register page ([b6cc83c](https://wibugit.wibudev.com/bip/hipmi/commit/b6cc83c004cacb2289c51491fce7ebc2b29e126f)) +* **src/app/page:** mengedit page ([ca66fde](https://wibugit.wibudev.com/bip/hipmi/commit/ca66fde1dc6751f3749cb1d582f7bbd299241318)) +* tambah dependensi 'jose' versi 5.9.2 pada package.json ([6ee43ed](https://wibugit.wibudev.com/bip/hipmi/commit/6ee43ed20faa273cbca0be948295e95d36bbd760)) +* tampilan upload stiker di admin ([fbea35e](https://wibugit.wibudev.com/bip/hipmi/commit/fbea35eef96a656e1b474959aa3fb8198c7d2b0e)) + + +### Bug Fixes + +* admin ([604077c](https://wibugit.wibudev.com/bip/hipmi/commit/604077cc8dda568951fa1cd1b8ddfe862e1d321d)) +* Admin ([74108c3](https://wibugit.wibudev.com/bip/hipmi/commit/74108c30969bd2c607b51f302209de91430e7792)) +* admin app info ([117dbe6](https://wibugit.wibudev.com/bip/hipmi/commit/117dbe6157fbb74d359db1c8baffe3c4985fab4a)) +* admin app info ([0cbcee8](https://wibugit.wibudev.com/bip/hipmi/commit/0cbcee87bd52f6a7b596e260841deef9d4615016)) +* admin collaboration ([039ffc5](https://wibugit.wibudev.com/bip/hipmi/commit/039ffc57b18d24968d854d06cd62fff13b769a6f)) +* admin donasi ([6ccdbf9](https://wibugit.wibudev.com/bip/hipmi/commit/6ccdbf9763c1ce8443a6a691b24817d6b80265c6)) +* admin donasi ([d624d61](https://wibugit.wibudev.com/bip/hipmi/commit/d624d61a33069a9c578a1af780bc2229dd3bad96)) +* admin forum ([aba2585](https://wibugit.wibudev.com/bip/hipmi/commit/aba258517db277fd85d043c3aa4df279a5ec232d)) +* admin investasi ([9b4a6fd](https://wibugit.wibudev.com/bip/hipmi/commit/9b4a6fdc1c49ea982bb5e166aa8b3f4f40b3a392)) +* admin job ([3aea046](https://wibugit.wibudev.com/bip/hipmi/commit/3aea0460462e87c30b0e7a939a24aaf5d9ce6978)) +* admin map ([8cedf7d](https://wibugit.wibudev.com/bip/hipmi/commit/8cedf7db61702dc67300fdd11570022d84b1d857)) +* Bug ([7e9dfce](https://wibugit.wibudev.com/bip/hipmi/commit/7e9dfce293bda5a4577ea16a4867e340b9883b3f)) +* button sticker ([3743008](https://wibugit.wibudev.com/bip/hipmi/commit/37430081d8718b4b2b06f5c3c09f13935bf413c4)) +* collaboration ([5030253](https://wibugit.wibudev.com/bip/hipmi/commit/5030253b07c1264229d066d18732d81e2636c5a6)) +* collaboration ([740ae44](https://wibugit.wibudev.com/bip/hipmi/commit/740ae447340ce48d168e0e8e7c14079b3cf61817)) +* collaboration ([bdff760](https://wibugit.wibudev.com/bip/hipmi/commit/bdff760f7021c624f8338da3af2d46c911b1dcff)) +* collaboration ([5007827](https://wibugit.wibudev.com/bip/hipmi/commit/5007827d51117105b879bf18f06da60db8c48ff4)) +* Cookies ([038c40a](https://wibugit.wibudev.com/bip/hipmi/commit/038c40a6fbc4062e1c3f1659ec0d1a4ab92205ae)) +* Cookies ([abaec2c](https://wibugit.wibudev.com/bip/hipmi/commit/abaec2c1c3be2a54975246e89cfe7047c962f2a8)) +* dashboard admin ([ac432d1](https://wibugit.wibudev.com/bip/hipmi/commit/ac432d1eb7b975d621889b0d2e13e366e806cf56)) +* Db Profile ([cf9355e](https://wibugit.wibudev.com/bip/hipmi/commit/cf9355e91f623171e7708d37a9ce8590ff473a44)) +* donasi ([f2c6940](https://wibugit.wibudev.com/bip/hipmi/commit/f2c694022e510ea99726cfffaf06b6cfffb808c1)) +* donasi ([1f1cca3](https://wibugit.wibudev.com/bip/hipmi/commit/1f1cca3520ff22b878e945383a580b32a3054a3d)) +* donasi ([e94090e](https://wibugit.wibudev.com/bip/hipmi/commit/e94090eb30c2f34af08816b3c4ad8ac4cbd360e8)) +* donasi ([bb65042](https://wibugit.wibudev.com/bip/hipmi/commit/bb650429b323670c85adc582eda8ff522bd4dd60)) +* donasi ([886d9f3](https://wibugit.wibudev.com/bip/hipmi/commit/886d9f37f4636576b8a89020537e13708f582431)) +* donasi ([709de95](https://wibugit.wibudev.com/bip/hipmi/commit/709de95b10650ae1472b75d73bdd0bf20306633e)) +* donasi ([9c5f005](https://wibugit.wibudev.com/bip/hipmi/commit/9c5f0053b6b834c67f170767e28dd9e04c5614a4)) +* donasi ([4fdfb6f](https://wibugit.wibudev.com/bip/hipmi/commit/4fdfb6f4b0548d78a712443ac24e37e933665d41)) +* donasi ([1b23c50](https://wibugit.wibudev.com/bip/hipmi/commit/1b23c50ff08f2bbb46ecfeec9d0c02c03f9230c1)) +* donasi ([0e4dda5](https://wibugit.wibudev.com/bip/hipmi/commit/0e4dda5356df96f4dc749c5a7d5613e378eb6096)) +* donasi ([72b6d23](https://wibugit.wibudev.com/bip/hipmi/commit/72b6d239fee3e90e812ab24192154e5e8910fccb)) +* Donasi ([517b2bb](https://wibugit.wibudev.com/bip/hipmi/commit/517b2bb9b0e256d31d7a10332a6e7880c58ad48f)) +* Donasi ([2335807](https://wibugit.wibudev.com/bip/hipmi/commit/2335807b427ee24e7a28ae78a3ca9dae981a79e2)) +* Donasi ([a798f9a](https://wibugit.wibudev.com/bip/hipmi/commit/a798f9a3bc9996811ca55e70ea407297e1f939d8)) +* drawer katalog ([eab293d](https://wibugit.wibudev.com/bip/hipmi/commit/eab293dd35a6f061cfa4675679de1ce68f506c3c)) +* dynamic error ([86bfbcb](https://wibugit.wibudev.com/bip/hipmi/commit/86bfbcb60e225adcba6504869cf8548370fc6750)) +* event ([6f686b6](https://wibugit.wibudev.com/bip/hipmi/commit/6f686b6abf4ba6201df632938e4024004fe749b3)) +* event ([02bbdfd](https://wibugit.wibudev.com/bip/hipmi/commit/02bbdfd5f6a2d299b8d527b9211f7b6ff598602f)) +* event ([fc38813](https://wibugit.wibudev.com/bip/hipmi/commit/fc388133a638d4288314dd3faeddfcce61fe7292)) +* Event ([45279cd](https://wibugit.wibudev.com/bip/hipmi/commit/45279cd37fb4b2a293012c9cb1a8d6e977d0edb3)) +* Event ([1f8bfcb](https://wibugit.wibudev.com/bip/hipmi/commit/1f8bfcbed924ec1b53cdcc42393884f554299c5b)) +* Event ([8f76067](https://wibugit.wibudev.com/bip/hipmi/commit/8f760673804d114c3f04ce65a648fa0ff5962822)) +* Event ([81543d6](https://wibugit.wibudev.com/bip/hipmi/commit/81543d678cb515b36f8393ee257b8a6a6c4a0834)) +* File view ([84b7b38](https://wibugit.wibudev.com/bip/hipmi/commit/84b7b381f62d2f69d8b1e9d7c2411175e5d48e38)) +* forum ([0de70b0](https://wibugit.wibudev.com/bip/hipmi/commit/0de70b038429a63be25b669ef6d8732e2312fd9d)) +* forum ([42cfe65](https://wibugit.wibudev.com/bip/hipmi/commit/42cfe650b565c02eb7ebf639ecef41c188ad4449)) +* forum ([512d170](https://wibugit.wibudev.com/bip/hipmi/commit/512d170c3e047848c9b26144533e50720e04950b)) +* forum admin ([4b8316c](https://wibugit.wibudev.com/bip/hipmi/commit/4b8316cc1311eb88840c029f1dfdb6a43e3a7f4f)) +* Image donasi ([0371ca5](https://wibugit.wibudev.com/bip/hipmi/commit/0371ca5e0137354bb0d7a89300aa112112cf194d)) +* investasi ([69c0abe](https://wibugit.wibudev.com/bip/hipmi/commit/69c0abed75cb7b777c7072969e8826663dd32fdc)) +* investasi ([7a95395](https://wibugit.wibudev.com/bip/hipmi/commit/7a95395fe9861997527d76f08073db8de4ba48aa)) +* Investasi ([5ff74b0](https://wibugit.wibudev.com/bip/hipmi/commit/5ff74b00f55751cc951b959f2d9bccda403158dc)) +* investasi: ([5c3fe55](https://wibugit.wibudev.com/bip/hipmi/commit/5c3fe551aeb57bdd24ad616f9cbe37c2d417efca)) +* Job ([1b58ba7](https://wibugit.wibudev.com/bip/hipmi/commit/1b58ba7d905f490fdba9e1d90e722faf251b2ae3)) +* Job ([aa612d2](https://wibugit.wibudev.com/bip/hipmi/commit/aa612d24bc7cb729db66841bd3a48379cf875f70)) +* Job ([30743b0](https://wibugit.wibudev.com/bip/hipmi/commit/30743b02ae0c2d0a83310af05711ed255000c7ce)) +* loading button tambah portofolio ([8823a01](https://wibugit.wibudev.com/bip/hipmi/commit/8823a01b067928cbeea195402f2bb454df8e8bea)) +* Map ([f23defd](https://wibugit.wibudev.com/bip/hipmi/commit/f23defd972fbd276fee546677dc5e9565651b4f4)) +* Map ([56548b4](https://wibugit.wibudev.com/bip/hipmi/commit/56548b425876a7fa9be49f2a290de6a1916609a1)) +* Middlerawe/1 ([cc690ee](https://wibugit.wibudev.com/bip/hipmi/commit/cc690eec0686e4306a440a8b38fffacb2c2b78c6)) +* Middlerawe/2 ([ac749f3](https://wibugit.wibudev.com/bip/hipmi/commit/ac749f3d9d348162a2b8e8c88091dce97f9cca27)) +* Middlerawe/3 ([10dee19](https://wibugit.wibudev.com/bip/hipmi/commit/10dee19f98b011de19a21e9ef4a5282e37ffdf38)) +* Middlerawe/4 ([0a03b05](https://wibugit.wibudev.com/bip/hipmi/commit/0a03b05d4e0d9c369844859cac8879ba5505efa7)) +* Middlerawe/5 ([6e5a9f7](https://wibugit.wibudev.com/bip/hipmi/commit/6e5a9f785a06f6b31b6010f8b89dfd146112a44a)) +* Middlerawe/6 ([b9e4b97](https://wibugit.wibudev.com/bip/hipmi/commit/b9e4b97b31f1f86cd3ee64c1a51827d3d724b1e7)) +* Middlerawe/7 ([13c855f](https://wibugit.wibudev.com/bip/hipmi/commit/13c855f2f64212857cb6c143f135d2fe160d9ee9)) +* middleware ([31124c5](https://wibugit.wibudev.com/bip/hipmi/commit/31124c5500d10a4d831c45c0da1a46a1dee995db)) +* Navbar admin ([6b8ace7](https://wibugit.wibudev.com/bip/hipmi/commit/6b8ace772c54aa00eebf9228da0d1543ed593d2d)) +* Navbar admin ([5fcb09b](https://wibugit.wibudev.com/bip/hipmi/commit/5fcb09b88906e74c2f2be76f5fd325daa48f5ae5)) +* nested layout ([c202cc8](https://wibugit.wibudev.com/bip/hipmi/commit/c202cc8ea08ce8cdb351136a47c2afe10afb14c9)) +* Notifikasi ([82f5b23](https://wibugit.wibudev.com/bip/hipmi/commit/82f5b237ae52dc087711452f4bd6baa7acce8a1f)) +* pencegahan error ([afe8014](https://wibugit.wibudev.com/bip/hipmi/commit/afe8014cc8b4ab7266f3c52918a6bc82bb62bc58)) +* Profile ([b13110b](https://wibugit.wibudev.com/bip/hipmi/commit/b13110be6f475df7d5b36909cdc8f92f80a62d57)) +* super admin ([5bc70ba](https://wibugit.wibudev.com/bip/hipmi/commit/5bc70baf96e792e1e1492027747f8352f2f80313)) +* test new github ([555b6e7](https://wibugit.wibudev.com/bip/hipmi/commit/555b6e76332d867fc72b51cc1163fd6911a63288)) +* update version ([3d6ec14](https://wibugit.wibudev.com/bip/hipmi/commit/3d6ec1410d0a54bad35dea2740101aaad589fdd7)) +* update version in package.json ([ca99de7](https://wibugit.wibudev.com/bip/hipmi/commit/ca99de7dd5a48dca66f33b3d63b6c278e0367c9d)) +* Upload image ([360ba26](https://wibugit.wibudev.com/bip/hipmi/commit/360ba267ec69404dd45bb7d6510fe6113d9087ab)) +* Upload image ([370e3ec](https://wibugit.wibudev.com/bip/hipmi/commit/370e3ec4e4c6e1f342c966feb7a65b62a09d2945)) +* user ([215accb](https://wibugit.wibudev.com/bip/hipmi/commit/215accbcaa989e43f43dfc5f400d5411013f4ef3)) +* User search & Event ([ca5c304](https://wibugit.wibudev.com/bip/hipmi/commit/ca5c30499a2630e5d8a8c87f569f2b50fa88ad6e)) +* validasi ([a6548f7](https://wibugit.wibudev.com/bip/hipmi/commit/a6548f7b364e403d5265a0015003021b5c11f004)) +* version 1.2.10 ([08eed15](https://wibugit.wibudev.com/bip/hipmi/commit/08eed15b798d549146b035ffd9a44cea5e55b283)) +* version 1.2.11 ([7afcc9c](https://wibugit.wibudev.com/bip/hipmi/commit/7afcc9ced02eafab1df669fd71fdbcd4556bb322)) +* version 1.2.12 ([932735f](https://wibugit.wibudev.com/bip/hipmi/commit/932735f9238db07b331b1b26328624247371c3d6)) +* version 1.2.6 ([13142f2](https://wibugit.wibudev.com/bip/hipmi/commit/13142f283d804fead233cf6bff6a41e4732a3ec0)) +* version 1.2.7 ([1b83de0](https://wibugit.wibudev.com/bip/hipmi/commit/1b83de0189b4581a8511cc58af2de0d5c613646b)) +* version 1.2.8 ([378b2c1](https://wibugit.wibudev.com/bip/hipmi/commit/378b2c19ff7a7fb07647c6a093d803d299c091f7)) +* version 1.2.8 ([23edb2d](https://wibugit.wibudev.com/bip/hipmi/commit/23edb2d6317f2a8344ac3190f492f718c05b65c9)) +* voting ([c057f20](https://wibugit.wibudev.com/bip/hipmi/commit/c057f20963df70f4ce2ac071007541678c6ff854)) +* Voting ([e65a8d3](https://wibugit.wibudev.com/bip/hipmi/commit/e65a8d30a2a70593f3e4268518ae4c0c542a02dd)) +* voting status ([9bb68b2](https://wibugit.wibudev.com/bip/hipmi/commit/9bb68b216fc444e390fccf7131af886bc6d12d60)) +* voting status ([e5e36a3](https://wibugit.wibudev.com/bip/hipmi/commit/e5e36a38893f21037688cd3153a57dc29ce1347e)) + ## [1.4.45](https://wibugit.wibudev.com/bip/hipmi/compare/v1.4.44...v1.4.45) (2025-10-06) ## [1.4.44](https://wibugit.wibudev.com/bip/hipmi/compare/v1.4.43...v1.4.44) (2025-10-02) diff --git a/package.json b/package.json index 4af1a089..99536e2c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hipmi", - "version": "1.4.45", + "version": "1.5.6", "private": true, "prisma": { "seed": "bun prisma/seed.ts" diff --git a/src/app/api/admin/vote/status/[name]/route.ts b/src/app/api/admin/vote/status/[name]/route.ts index e2cd0b6b..d2bb1f84 100644 --- a/src/app/api/admin/vote/status/[name]/route.ts +++ b/src/app/api/admin/vote/status/[name]/route.ts @@ -70,7 +70,7 @@ export async function GET( for (let i of getAllData) { if (moment(i.akhirVote).diff(moment(), "minutes") < 0) { - await prisma.event.update({ + await prisma.voting.update({ where: { id: i.id, }, diff --git a/src/app/api/mobile/admin/collaboration/[id]/route.ts b/src/app/api/mobile/admin/collaboration/[id]/route.ts new file mode 100644 index 00000000..11c30486 --- /dev/null +++ b/src/app/api/mobile/admin/collaboration/[id]/route.ts @@ -0,0 +1,156 @@ +import { NextResponse } from "next/server"; +import prisma from "@/lib/prisma"; + +export { GET, PUT }; + +async function GET(request: Request, { params }: { params: { id: string } }) { + const { id } = params; + const { searchParams } = new URL(request.url); + const category = searchParams.get("category"); + + let fixData; + try { + if (category === "publish" || category === "reject") { + fixData = await prisma.projectCollaboration.findUnique({ + where: { + id: id, + }, + select: { + id: true, + isActive: true, + title: true, + lokasi: true, + purpose: true, + benefit: true, + createdAt: true, + report: true, + Author: { + select: { + id: true, + username: true, + }, + }, + ProjectCollaborationMaster_Industri: true, + ProjectCollaboration_Partisipasi: { + where: { + User: { + active: true, + }, + }, + select: { + id: true, + User: { + select: { + id: true, + Profile: { + select: { + name: true, + }, + }, + }, + }, + }, + }, + }, + }); + } else if (category === "group") { + fixData = await prisma.projectCollaboration_RoomChat.findUnique({ + where: { + id: id, + }, + select: { + id: true, + name: true, + ProjectCollaboration: { + select: { + id: true, + isActive: true, + title: true, + lokasi: true, + purpose: true, + benefit: true, + createdAt: true, + ProjectCollaborationMaster_Industri: true, + Author: true, + }, + }, + ProjectCollaboration_AnggotaRoomChat: { + select: { + User: { + select: { + username: true, + id: true, + Profile: { + select: { + id: true, + name: true, + }, + }, + }, + }, + }, + }, + }, + }); + } + + return NextResponse.json( + { + success: true, + message: "Success get data collaboration", + data: fixData, + }, + { status: 200 } + ); + } catch (error) { + return NextResponse.json( + { + success: false, + message: "Error get data collaboration", + reason: (error as Error).message, + }, + { status: 500 } + ); + } +} + +async function PUT(request: Request, { params }: { params: { id: string } }) { + const { id } = params; + const { data } = await request.json(); + // const {searchParams} = new URL(request.url); + // const status = searchParams.get("status"); + + try { + const projectUpdate = await prisma.projectCollaboration.update({ + where: { + id: id, + }, + data: { + isActive: false, + isReject: true, + report: data, + }, + select: { + userId: true, + }, + }); + + return NextResponse.json( + { + success: true, + message: "Success update data collaboration", + // data: projectUpdate, + }, + { status: 200 } + ); + } catch (error) { + return NextResponse.json( + { + success: false, + message: "Error update data collaboration", + reason: (error as Error).message, + }, + { status: 500 } + ); + } +} diff --git a/src/app/api/mobile/admin/collaboration/route.ts b/src/app/api/mobile/admin/collaboration/route.ts new file mode 100644 index 00000000..8703665e --- /dev/null +++ b/src/app/api/mobile/admin/collaboration/route.ts @@ -0,0 +1,200 @@ +import { NextResponse } from "next/server"; +import { prisma } from "@/lib"; + +export { GET }; + +async function GET(request: Request, { params }: { params: { name: string } }) { + const { searchParams } = new URL(request.url); + const category = searchParams.get("category"); + let fixData; + + try { + if (category === "dashboard") { + const publish = await prisma.projectCollaboration.count({ + where: { + isActive: true, + isReject: false, + Author: { + active: true, + }, + }, + }); + + const reject = await prisma.projectCollaboration.count({ + where: { + isActive: false, + isReject: true, + Author: { + active: true, + }, + }, + }); + + const group = await prisma.projectCollaboration_RoomChat.count({ + where: { + isActive: true, + }, + }); + + fixData = { + publish: publish, + reject: reject, + group: group, + }; + } else if (category === "publish") { + fixData = await prisma.projectCollaboration.findMany({ + orderBy: { + createdAt: "desc", + }, + where: { + isActive: true, + isReject: false, + Author: { + active: true, + }, + }, + select: { + id: true, + createdAt: true, + isActive: true, + title: true, + Author: { + select: { + id: true, + username: true, + Profile: true, + }, + }, + projectCollaborationMaster_IndustriId: true, + ProjectCollaborationMaster_Industri: true, + ProjectCollaboration_Partisipasi: { + where: { + User: { + active: true, + }, + }, + // select: { + // User: { + // select: { + // id: true, + // username: true, + // Profile: true, + // }, + // }, + // }, + }, + }, + }); + } else if (category === "reject") { + fixData = await prisma.projectCollaboration.findMany({ + orderBy: { + createdAt: "desc", + }, + where: { + isActive: false, + isReject: true, + Author: { + active: true, + }, + }, + select: { + id: true, + createdAt: true, + isActive: true, + title: true, + Author: { + select: { + id: true, + username: true, + Profile: true, + }, + }, + projectCollaborationMaster_IndustriId: true, + ProjectCollaborationMaster_Industri: true, + ProjectCollaboration_Partisipasi: { + where: { + User: { + active: true, + }, + }, + // select: { + // User: { + // select: { + // id: true, + // username: true, + // Profile: true, + // }, + // }, + // }, + }, + }, + }); + } else if (category === "group") { + fixData = await prisma.projectCollaboration_RoomChat.findMany({ + orderBy: { + createdAt: "desc", + }, + where: { + isActive: true, + }, + select: { + id: true, + createdAt: true, + isActive: true, + name: true, + ProjectCollaboration_AnggotaRoomChat: { + select: { + User: { + select: { + id: true, + Profile: true, + }, + }, + }, + }, + ProjectCollaboration: { + select: { + id: true, + isActive: true, + title: true, + lokasi: true, + purpose: true, + benefit: true, + createdAt: true, + report: true, + Author: { + select: { + id: true, + Profile: { + select: { + name: true, + }, + }, + }, + }, + ProjectCollaborationMaster_Industri: true, + }, + }, + }, + }); + } + + return NextResponse.json( + { + success: true, + message: "Success get data collaboration", + data: fixData, + }, + { status: 200 } + ); + } catch (error) { + return NextResponse.json( + { + success: false, + message: "Error get data collaboration", + reason: (error as Error).message, + }, + { status: 500 } + ); + } +} diff --git a/src/app/api/mobile/admin/donation/route.ts b/src/app/api/mobile/admin/donation/route.ts new file mode 100644 index 00000000..e762d26a --- /dev/null +++ b/src/app/api/mobile/admin/donation/route.ts @@ -0,0 +1,134 @@ +import _ from "lodash"; +import { NextResponse } from "next/server"; + +export { GET }; + +async function GET(request: Request) { + const { searchParams } = new URL(request.url); + const category = searchParams.get("category"); + const page = searchParams.get("page"); + const search = searchParams.get("search"); + const takeData = 10; + const skipData = Number(page) * takeData - takeData; + console.log("[CATEGORY]", category); + let fixData; + + + try { + if (category === "dashboard") { + const publish = await prisma.donasi.count({ + where: { + DonasiMaster_Status: { + name: "Publish", + }, + }, + }); + + const review = await prisma.donasi.count({ + where: { + DonasiMaster_Status: { + name: "Review", + }, + }, + }); + + const reject = await prisma.donasi.count({ + where: { + DonasiMaster_Status: { + name: "Reject", + }, + }, + }); + + const countCategoryDonation = await prisma.donasiMaster_Kategori.findMany( + { + orderBy: { + createdAt: "asc", + }, + where: { + active: true, + }, + } + ); + + const categoryDonation = countCategoryDonation.length; + + fixData = { + publish, + review, + reject, + categoryDonation, + }; + } else { + const fixCategory = _.startCase(category || ""); + + const checkStatus = await prisma.donasiMaster_StatusDonasi.findFirst({ + where: { + name: fixCategory, + }, + }); + + console.log("[STATUS]", checkStatus); + + if (!checkStatus) { + return NextResponse.json( + { + success: false, + message: "Failed to get data donation", + reason: "Status not found", + }, + { status: 500 } + ); + } + + fixData = await prisma.donasi.findMany({ + take: page ? takeData : undefined, + skip: page ? skipData : undefined, + orderBy: { + createdAt: "desc", + }, + where: { + DonasiMaster_Status: { + name: checkStatus.name, + }, + active: true, + title: { + contains: search || "", + mode: "insensitive", + }, + }, + select: { + id: true, + title: true, + Author: { + select: { + id: true, + username: true, + }, + }, + }, + }); + + console.log("[LIST]", fixData); + } + + return NextResponse.json( + { + success: true, + message: `Success get data donation ${category}`, + data: fixData, + }, + { status: 200 } + ); + } catch (error) { + console.error("Error get data donation:", error); + return NextResponse.json( + { + success: false, + message: "Failed to get data donation", + reason: (error as Error).message, + }, + { status: 500 } + ); + } +} diff --git a/src/app/api/mobile/admin/event/[id]/participants/route.ts b/src/app/api/mobile/admin/event/[id]/participants/route.ts new file mode 100644 index 00000000..36d05177 --- /dev/null +++ b/src/app/api/mobile/admin/event/[id]/participants/route.ts @@ -0,0 +1,53 @@ +import { NextResponse } from "next/server"; +import prisma from "@/lib/prisma"; + +export { GET }; + +async function GET(request: Request, { params }: { params: { id: string } }) { + try { + const { id } = params; + + const data = await prisma.event_Peserta.findMany({ + where: { + eventId: id, + }, + select: { + eventId: true, + userId: true, + isPresent: true, + User: { + select: { + id: true, + username: true, + nomor: true, + Profile: { + select: { + id: true, + name: true, + imageId: true, + }, + }, + }, + }, + }, + }); + + return NextResponse.json( + { + success: true, + message: "Success get participants", + data: data, + }, + { status: 200 } + ); + } catch (error) { + return NextResponse.json( + { + success: false, + message: "Error get participants", + reason: (error as Error).message, + }, + { status: 500 } + ); + } +} diff --git a/src/app/api/mobile/admin/event/[id]/route.ts b/src/app/api/mobile/admin/event/[id]/route.ts new file mode 100644 index 00000000..1215c1ea --- /dev/null +++ b/src/app/api/mobile/admin/event/[id]/route.ts @@ -0,0 +1,129 @@ +import { NextResponse } from "next/server"; +import prisma from "@/lib/prisma"; +import _ from "lodash"; + +export { GET, PUT }; + +async function GET(request: Request, { params }: { params: { id: string } }) { + const { id } = params; + + try { + const data = await prisma.event.findUnique({ + where: { + id: id, + }, + include: { + Author: { + select: { + username: true, + nomor: true, + Profile: { + select: { + name: true, + alamat: true, + }, + }, + }, + }, + EventMaster_TipeAcara: { + select: { + name: true, + }, + }, + EventMaster_Status: true, + }, + }); + + return NextResponse.json( + { + success: true, + message: "Success get data event", + data: data, + }, + { status: 200 } + ); + } catch (error) { + return NextResponse.json( + { + success: false, + message: "Failed to get data", + reason: (error as Error).message, + }, + { status: 500 } + ); + } +} + +async function PUT(request: Request, { params }: { params: { id: string } }) { + const { id } = params; + const { data } = await request.json(); + const { searchParams } = new URL(request.url); + const status = searchParams.get("status"); + const fixStatus = _.startCase(status as string); + + console.log("ID", id); + console.log("DATA", data); + console.log("FIX STATUS", fixStatus); + + let fixData; + try { + const checkStatus = await prisma.eventMaster_Status.findFirst({ + where: { + name: fixStatus, + }, + }); + + if (!checkStatus) + return NextResponse.json( + { + success: false, + message: "Error update data event", + reason: "Status not found", + }, + { status: 500 } + ); + + if (fixStatus === "Reject") { + const updateData = await prisma.event.update({ + where: { + id: id, + }, + data: { + catatan: data, + eventMaster_StatusId: checkStatus.id, + }, + }); + + fixData = updateData; + } else if (fixStatus === "Publish") { + const updateData = await prisma.event.update({ + where: { + id: id, + }, + data: { + eventMaster_StatusId: checkStatus.id, + }, + }); + + fixData = updateData; + } + + return NextResponse.json( + { + success: true, + message: "Success update data event", + data: fixData, + }, + { status: 200 } + ); + } catch (error) { + return NextResponse.json( + { + success: false, + message: "Failed to update data", + reason: (error as Error).message, + }, + { status: 500 } + ); + } +} diff --git a/src/app/api/mobile/admin/event/route.ts b/src/app/api/mobile/admin/event/route.ts new file mode 100644 index 00000000..c2f072f9 --- /dev/null +++ b/src/app/api/mobile/admin/event/route.ts @@ -0,0 +1,192 @@ +import _ from "lodash"; +import { prisma } from "@/lib"; +import { NextResponse } from "next/server"; +import moment from "moment"; + +export { GET }; + +async function GET(request: Request) { + const { searchParams } = new URL(request.url); + const category = searchParams.get("category"); + const fixStatus = _.startCase(category || ""); + + const search = searchParams.get("search"); + const page = searchParams.get("page"); + const takeData = 10; + const skipData = Number(page) * takeData - takeData; + let fixData; + + console.log("[CATEGORY]", category); + // console.log("[FIX STATUS]", fixStatus); + + try { + if (category === "dashboard") { + const publish = await prisma.event.count({ + where: { + EventMaster_Status: { + name: "Publish", + }, + isArsip: false, + }, + }); + + const review = await prisma.event.count({ + where: { + EventMaster_Status: { + name: "Review", + }, + isArsip: false, + }, + }); + + const reject = await prisma.event.count({ + where: { + EventMaster_Status: { + name: "Reject", + }, + isArsip: false, + }, + }); + + const history = await prisma.event.count({ + where: { + EventMaster_Status: { + name: "Publish", + }, + isArsip: true, + }, + }); + + const typeOfEvent = await prisma.eventMaster_TipeAcara.count({ + where: { + active: true, + }, + }); + + fixData = { + publish, + review, + reject, + history, + typeOfEvent, + }; + } else if (category === "history") { + console.log("[HISTORY HERE]"); + + const data = await prisma.event.findMany({ + take: page ? takeData : undefined, + skip: page ? skipData : undefined, + orderBy: { + createdAt: "desc", + }, + where: { + isArsip: true, + EventMaster_Status: { + name: "Publish", + }, + title: { + contains: search || "", + mode: "insensitive", + }, + }, + select: { + id: true, + title: true, + Author: { + select: { + id: true, + username: true, + Profile: { + select: { + name: true, + }, + }, + }, + }, + }, + }); + + fixData = data; + } else { + if (fixStatus === "Publish") { + const getAllData = await prisma.event.findMany({ + where: { + active: true, + EventMaster_Status: { + name: fixStatus, + }, + isArsip: false, + }, + }); + + for (let i of getAllData) { + if (moment(i.tanggalSelesai).diff(moment(), "minutes") < 0) { + await prisma.event.update({ + where: { + id: i.id, + }, + data: { + isArsip: true, + }, + }); + } + } + } + + const data = await prisma.event.findMany({ + take: page ? takeData : undefined, + skip: page ? skipData : undefined, + orderBy: { + tanggal: "asc", + }, + where: { + active: true, + isArsip: false, + EventMaster_Status: { + name: fixStatus, + }, + title: { + contains: search || "", + mode: "insensitive", + }, + }, + select: { + id: true, + title: true, + Author: { + select: { + id: true, + username: true, + Profile: { + select: { + name: true, + }, + }, + }, + }, + }, + }); + + fixData = data; + } + + return NextResponse.json( + { + success: true, + message: `Success get data event ${category}`, + data: fixData, + }, + { status: 200 } + ); + } catch (error) { + console.log(`[ERROR GET DATA EVENT: ${category}]`, error); + return NextResponse.json( + { + success: false, + message: `Error get data event ${category}`, + reason: (error as Error).message, + }, + { status: 500 } + ); + } +} diff --git a/src/app/api/mobile/admin/forum/[id]/comment/route.ts b/src/app/api/mobile/admin/forum/[id]/comment/route.ts new file mode 100644 index 00000000..fba11a88 --- /dev/null +++ b/src/app/api/mobile/admin/forum/[id]/comment/route.ts @@ -0,0 +1,114 @@ +import _ from "lodash"; +import { NextResponse } from "next/server"; +import prisma from "@/lib/prisma"; + +export { GET, PUT }; + +async function GET(request: Request, { params }: { params: { id: string } }) { + const { id } = params; + const { searchParams } = new URL(request.url); + const search = searchParams.get("search"); + const page = searchParams.get("page"); + const takeData = 10; + const skipData = Number(page) * takeData - takeData; + const category = searchParams.get("category"); + let fixData; + try { + if (category === "get-all") { + const getData = await prisma.forum_Komentar.findMany({ + take: page ? takeData : undefined, + skip: page ? skipData : undefined, + orderBy: { + createdAt: "desc", + }, + where: { + forum_PostingId: id, + isActive: true, + komentar: { + contains: search ?? "", + mode: "insensitive", + }, + }, + include: { + Forum_ReportKomentar: true, + Author: { + select: { + username: true, + }, + }, + }, + }); + + fixData = getData.map((v: any) => ({ + ..._.omit(v, ["Forum_ReportKomentar"]), + countReport: v.Forum_ReportKomentar.length, + })); + } else if (category === "get-one") { + fixData = await prisma.forum_Komentar.findUnique({ + where: { + id: id, + }, + include: { + Forum_ReportKomentar: true, + Author: { + select: { + username: true, + }, + }, + }, + }); + } + + return NextResponse.json( + { + success: true, + message: "Success get detail comment", + data: fixData, + }, + { status: 200 } + ); + } catch (error) { + console.error(`[ERROR GET ${category} COMMENT]`, error); + return NextResponse.json( + { + success: false, + message: "Error get detail data comment", + reason: (error as Error).message, + }, + { status: 500 } + ); + } +} + +async function PUT(request: Request, { params }: { params: { id: string } }) { + const { id } = params; + try { + const deleteData = await prisma.forum_Komentar.update({ + where: { + id: id, + }, + data: { + isActive: false, + }, + }); + + return NextResponse.json( + { + success: true, + message: "Success deactivate comment", + data: deleteData, + }, + { status: 200 } + ); + } catch (error) { + console.error("[ERROR DEACTIVATE COMMENT]", error); + return NextResponse.json( + { + success: false, + message: "Error deactivate comment", + reason: (error as Error).message, + }, + { status: 500 } + ); + } +} diff --git a/src/app/api/mobile/admin/forum/[id]/report-comment/route.ts b/src/app/api/mobile/admin/forum/[id]/report-comment/route.ts new file mode 100644 index 00000000..986f4ac8 --- /dev/null +++ b/src/app/api/mobile/admin/forum/[id]/report-comment/route.ts @@ -0,0 +1,69 @@ +import prisma from "@/lib/prisma"; +import { NextResponse } from "next/server"; + +export async function GET( + request: Request, + { params }: { params: { id: string } } +) { + const { searchParams } = new URL(request.url); + const page = searchParams.get("page"); + const takeData = 10; + const skipData = Number(page) * takeData - takeData; + + try { + let fixData; + const { id } = params; + const komentarId = id; + + fixData = await prisma.forum_ReportKomentar.findMany({ + take: page ? takeData : undefined, + skip: page ? skipData : undefined, + orderBy: { + createdAt: "desc", + }, + where: { + forum_KomentarId: komentarId, + }, + select: { + id: true, + deskripsi: true, + ForumMaster_KategoriReport: { + select: { + title: true, + deskripsi: true, + }, + }, + User: { + select: { + username: true, + Profile: { + select: { + id: true, + name: true, + }, + }, + }, + }, + }, + }); + + return NextResponse.json( + { + success: true, + message: "Success get list report comment", + data: fixData, + }, + { status: 200 } + ); + } catch (error) { + console.error("[ERROR GET LIST REPORT COMMENT]", error); + return NextResponse.json( + { + success: false, + message: "Error get list report comment", + reason: (error as Error).message, + }, + { status: 500 } + ); + } +} diff --git a/src/app/api/mobile/admin/forum/[id]/report-posting/route.ts b/src/app/api/mobile/admin/forum/[id]/report-posting/route.ts new file mode 100644 index 00000000..d171e725 --- /dev/null +++ b/src/app/api/mobile/admin/forum/[id]/report-posting/route.ts @@ -0,0 +1,76 @@ +import { NextResponse } from "next/server"; +import { prisma } from "@/lib"; + +export async function GET( + request: Request, + { params }: { params: { id: string } } +) { + const { id } = params; + const { searchParams } = new URL(request.url); + const search = searchParams.get("search"); + const page = searchParams.get("page"); + const takeData = 10; + const skipData = Number(page) * takeData - takeData; + let fixData; + + try { + fixData = await prisma.forum_ReportPosting.findMany({ + take: page ? takeData : undefined, + skip: page ? skipData : undefined, + orderBy: { + createdAt: "desc", + }, + where: { + forum_PostingId: id, + Forum_Posting: { + isActive: true, + diskusi: { + contains: search ? search : "", + mode: "insensitive", + }, + }, + }, + select: { + id: true, + deskripsi: true, + User: { + select: { + id: true, + username: true, + Profile: { + select: { + name: true, + }, + }, + }, + }, + ForumMaster_KategoriReport: { + select: { + id: true, + title: true, + deskripsi: true, + }, + }, + }, + }); + + return NextResponse.json( + { + success: true, + message: "Success get list report posting", + data: fixData, + }, + { status: 200 } + ); + } catch (error) { + console.error("[ERROR GET LIST REPORT POSTING]", error); + return NextResponse.json( + { + success: false, + message: "Error get list report posting", + reason: (error as Error).message, + }, + { status: 500 } + ); + } +} diff --git a/src/app/api/mobile/admin/forum/[id]/route.ts b/src/app/api/mobile/admin/forum/[id]/route.ts new file mode 100644 index 00000000..67798fa8 --- /dev/null +++ b/src/app/api/mobile/admin/forum/[id]/route.ts @@ -0,0 +1,120 @@ +import { NextResponse } from "next/server"; +import prisma from "@/lib/prisma"; +import _ from "lodash"; + +export { GET, PUT }; + +async function GET(request: Request, { params }: { params: { id: string } }) { + const { searchParams } = new URL(request.url); + const search = searchParams.get("search"); + const page = searchParams.get("page"); + const takeData = 10; + const skipData = Number(page) * takeData - takeData; + + const { id } = params; + try { + const data = await prisma.forum_Posting.findFirst({ + where: { + id: id, + }, + select: { + id: true, + isActive: true, + diskusi: true, + ForumMaster_StatusPosting: { + select: { + id: true, + status: true, + }, + }, + authorId: true, + Author: { + select: { + id: true, + username: true, + Profile: { + select: { + name: true, + }, + }, + }, + }, + Forum_Komentar: { + where: { + isActive: true, + }, + }, + Forum_ReportPosting: { + where: { + isActive: true, + }, + }, + }, + }); + + const result = { + ..._.omit(data, "Forum_Komentar", "Forum_ReportPosting"), + JumlahKomentar: data?.Forum_Komentar.length, + JumlahReportPosting: data?.Forum_ReportPosting.length, + }; + + return NextResponse.json({ + success: true, + message: "Success get data", + data: result, + }); + } catch (error) { + console.error("Error get data forum", error); + return NextResponse.json( + { + success: false, + message: "Error get data forum", + reason: (error as Error).message, + }, + { status: 500 } + ); + } +} + +async function PUT(request: Request, { params }: { params: { id: string } }) { + const { id } = params; + try { + const data = await prisma.forum_Posting.update({ + where: { + id: id, + }, + data: { + isActive: false, + }, + }); + + const deactivateComment = await prisma.forum_Komentar.updateMany({ + where: { + forum_PostingId: id, + }, + data: { + isActive: false, + }, + }); + + console.log("[DEACTIVATE COMMENT]", deactivateComment); + return NextResponse.json( + { + success: true, + message: "Success deactivate posting", + data: data, + }, + { status: 200 } + ); + } catch (error) { + console.error("[ERROR DEACTIVATE POSTING]", error); + return NextResponse.json( + { + success: false, + message: "Error deactivate posting", + reason: (error as Error).message, + }, + { status: 500 } + ); + } +} diff --git a/src/app/api/mobile/admin/forum/route.ts b/src/app/api/mobile/admin/forum/route.ts new file mode 100644 index 00000000..bc7e02d2 --- /dev/null +++ b/src/app/api/mobile/admin/forum/route.ts @@ -0,0 +1,193 @@ +import { NextResponse } from "next/server"; +import { prisma } from "@/lib"; + +export { GET }; + +async function GET(request: Request, { params }: { params: { name: string } }) { + const { searchParams } = new URL(request.url); + const category = searchParams.get("category"); + const search = searchParams.get("search"); + const page = searchParams.get("page"); + const takeData = 10; + const skipData = Number(page) * takeData - takeData; + + let fixData; + try { + if (category === "dashboard") { + const posting = await prisma.forum_Posting.count({ + orderBy: { + createdAt: "desc", + }, + where: { + isActive: true, + }, + }); + + const reportPosting = await prisma.forum_ReportPosting.count({ + orderBy: { + createdAt: "desc", + }, + where: { + Forum_Posting: { + isActive: true, + }, + }, + }); + + const reportComment = await prisma.forum_ReportKomentar.count({ + orderBy: { + createdAt: "desc", + }, + where: { + Forum_Komentar: { + isActive: true, + }, + }, + }); + + fixData = { + posting, + reportPosting, + reportComment, + }; + } else if (category === "posting") { + fixData = await prisma.forum_Posting.findMany({ + take: page ? takeData : undefined, + skip: page ? skipData : undefined, + orderBy: { + createdAt: "desc", + }, + where: { + isActive: true, + diskusi: { + contains: search || "", + mode: "insensitive", + }, + }, + select: { + id: true, + diskusi: true, + isActive: true, + Author: { + select: { + id: true, + username: true, + Profile: true, + }, + }, + }, + }); + } else if (category === "report_posting") { + fixData = await prisma.forum_ReportPosting.findMany({ + take: page ? takeData : undefined, + skip: page ? skipData : undefined, + orderBy: { + createdAt: "desc", + }, + where: { + Forum_Posting: { + isActive: true, + diskusi: { + contains: search ? search : "", + mode: "insensitive", + }, + }, + }, + select: { + id: true, + deskripsi: true, + createdAt: true, + User: { + select: { + id: true, + username: true, + Profile: { + select: { + name: true, + }, + }, + }, + }, + ForumMaster_KategoriReport: { + select: { + id: true, + title: true, + deskripsi: true, + }, + }, + Forum_Posting: { + select: { + id: true, + diskusi: true, + }, + }, + }, + }); + } else if (category === "report_comment") { + fixData = await prisma.forum_ReportKomentar.findMany({ + take: page ? takeData : undefined, + skip: page ? skipData : undefined, + orderBy: { + createdAt: "desc", + }, + where: { + Forum_Komentar: { + isActive: true, + komentar: { + contains: search ? search : "", + mode: "insensitive", + }, + }, + }, + include: { + ForumMaster_KategoriReport: true, + User: { + select: { + username: true, + Profile: { + select: { + id: true, + name: true, + }, + }, + }, + }, + Forum_Komentar: { + select: { + id: true, + komentar: true, + }, + }, + }, + }); + } else { + return NextResponse.json( + { + success: false, + message: "Invalid category", + reason: "Invalid category", + }, + { status: 400 } + ); + } + + + return NextResponse.json( + { + success: true, + message: `Success get data forum ${category}`, + data: fixData, + }, + { status: 200 } + ); + } catch (error) { + return NextResponse.json( + { + success: false, + message: `Error get data forum ${category}`, + reason: (error as Error).message, + }, + { status: 500 } + ); + } +} diff --git a/src/app/api/mobile/admin/job/[id]/route.ts b/src/app/api/mobile/admin/job/[id]/route.ts new file mode 100644 index 00000000..67975023 --- /dev/null +++ b/src/app/api/mobile/admin/job/[id]/route.ts @@ -0,0 +1,143 @@ +import { NextResponse } from "next/server"; +import prisma from "@/lib/prisma"; +import _ from "lodash"; + +export { GET, PUT }; + +async function GET(request: Request, { params }: { params: { id: string } }) { + const { id } = params; + try { + const data = await prisma.job.findUnique({ + where: { + id: id, + }, + include: { + Author: { + select: { + username: true, + nomor: true, + Profile: { + select: { + name: true, + alamat: true, + }, + }, + }, + }, + MasterStatus: { + select: { + name: true, + }, + }, + }, + }); + return NextResponse.json( + { + success: true, + message: "Success get data job-vacancy", + data: data, + }, + { status: 200 } + ); + } catch (error) { + return NextResponse.json( + { + success: false, + message: "Error get data job-vacancy", + reason: (error as Error).message, + }, + { status: 500 } + ); + } +} + +async function PUT(request: Request, { params }: { params: { id: string } }) { + const { id } = params; + const { data } = await request.json(); + const { searchParams } = new URL(request.url); + const status = searchParams.get("status"); + const fixStatus = _.startCase(status as string); + + let fixData; + try { + const checkStatus = await prisma.masterStatus.findFirst({ + where: { + name: fixStatus, + }, + }); + + if (!checkStatus) + return NextResponse.json( + { + success: false, + message: "Error update data job-vacancy", + reason: "Status not found", + }, + { status: 500 } + ); + + if (fixStatus === "Reject") { + const updt = await prisma.job.update({ + where: { + id: id, + }, + data: { + masterStatusId: checkStatus.id, + catatan: data, + }, + select: { + id: true, + authorId: true, + MasterStatus: { + select: { + name: true, + }, + }, + title: true, + }, + }); + + fixData = updt; + } else if (fixStatus === "Publish") { + const updt = await prisma.job.update({ + where: { + id: id, + }, + data: { + masterStatusId: checkStatus.id, + }, + select: { + id: true, + authorId: true, + MasterStatus: { + select: { + name: true, + }, + }, + title: true, + }, + }); + + fixData = updt; + } + + return NextResponse.json( + { + success: true, + message: "Success update data job-vacancy", + data: fixData, + }, + { status: 200 } + ); + } catch (error) { + console.log("[ERROR]", error); + return NextResponse.json( + { + success: false, + message: "Error update data job-vacancy", + reason: (error as Error).message, + }, + { status: 500 } + ); + } +} diff --git a/src/app/api/mobile/admin/job/route.ts b/src/app/api/mobile/admin/job/route.ts new file mode 100644 index 00000000..cf986c09 --- /dev/null +++ b/src/app/api/mobile/admin/job/route.ts @@ -0,0 +1,90 @@ +import _ from "lodash"; +import { NextResponse } from "next/server"; +import { prisma } from "@/lib"; + +export { GET }; + +async function GET(request: Request, { params }: { params: { name: string } }) { + const { searchParams } = new URL(request.url); + const category = searchParams.get("category"); + const search = searchParams.get("search"); + let fixData; + + try { + if (category === "dashboard") { + const publish = await prisma.job.count({ + where: { + MasterStatus: { + name: "Publish", + }, + isArsip: false, + }, + }); + + const review = await prisma.job.count({ + where: { + MasterStatus: { + name: "Review", + }, + isArsip: false, + }, + }); + + const reject = await prisma.job.count({ + where: { + MasterStatus: { + name: "Reject", + }, + isArsip: false, + }, + }); + + fixData = { + publish, + review, + reject, + }; + } else { + const fixToStatus = _.startCase(category || ""); + fixData = await prisma.job.findMany({ + orderBy: { + updatedAt: "desc", + }, + where: { + isActive: true, + isArsip: false, + MasterStatus: { + name: fixToStatus, + }, + title: { + contains: search ? search : "", + mode: "insensitive", + }, + }, + select: { + id: true, + title: true, + Author: true, + }, + }); + } + + return NextResponse.json( + { + success: true, + message: "Success get data job-vacancy dashboard", + data: fixData, + }, + { status: 200 } + ); + } catch (error) { + return NextResponse.json( + { + success: false, + message: "Error get data job-vacancy dashboard", + reason: (error as Error).message, + }, + { status: 500 } + ); + } +} diff --git a/src/app/api/mobile/admin/main-dashboard/route.ts b/src/app/api/mobile/admin/main-dashboard/route.ts new file mode 100644 index 00000000..d5d5d0c5 --- /dev/null +++ b/src/app/api/mobile/admin/main-dashboard/route.ts @@ -0,0 +1,39 @@ +import { prisma } from "@/lib"; +import { NextResponse } from "next/server"; + +export async function GET(request: Request) { + let fixDAta; + + try { + const user = await prisma.user.count({ + where: { + active: true, + }, + }); + + const portofolio = await prisma.portofolio.count({ + where: { + active: true, + }, + }); + + fixDAta = { + user: user, + portofolio: portofolio, + }; + + return NextResponse.json({ + status: 200, + success: true, + message: "Success get data main dashboard", + data: fixDAta, + }); + } catch (error) { + return NextResponse.json({ + status: 500, + success: false, + message: "Error get data main dashboard", + reason: (error as Error).message, + }); + } +} diff --git a/src/app/api/mobile/admin/master/bank/[id]/route.ts b/src/app/api/mobile/admin/master/bank/[id]/route.ts new file mode 100644 index 00000000..4b555b19 --- /dev/null +++ b/src/app/api/mobile/admin/master/bank/[id]/route.ts @@ -0,0 +1,63 @@ +import { NextResponse } from "next/server"; +import { prisma } from "@/lib"; + +export { GET, PUT }; + +async function GET(request: Request, { params }: { params: { id: string } }) { + try { + const { id } = params; + const data = await prisma.masterBank.findUnique({ + where: { + id: id, + }, + }); + + return NextResponse.json({ + status: 200, + success: true, + message: "Berhasil mendapatkan data", + data: data, + }); + } catch (error) { + console.error("Error Get Master Bank >>", error); + return NextResponse.json({ + status: 500, + success: false, + message: "API Error Get Data", + reason: (error as Error).message, + }); + } +} + +async function PUT(request: Request, { params }: { params: { id: string } }) { + const { id } = params; + const { data } = await request.json(); + + try { + const updateData = await prisma.masterBank.update({ + where: { + id: id, + }, + data: { + namaBank: data.namaBank, + namaAkun: data.namaAkun, + norek: data.norek, + isActive: data.isActive, + }, + }); + + return NextResponse.json({ + status: 200, + success: true, + message: "Berhasil mengupdate data", + }); + } catch (error) { + console.error("Error Update Master Bank >>", error); + return NextResponse.json({ + status: 500, + success: false, + message: "API Error Update Data", + reason: (error as Error).message, + }); + } +} diff --git a/src/app/api/mobile/admin/master/bank/route.ts b/src/app/api/mobile/admin/master/bank/route.ts new file mode 100644 index 00000000..f17f9ecf --- /dev/null +++ b/src/app/api/mobile/admin/master/bank/route.ts @@ -0,0 +1,61 @@ +import { prisma } from "@/lib"; +import { NextResponse } from "next/server"; + +export { GET, POST }; + +async function GET() { + try { + const data = await prisma.masterBank.findMany({ + orderBy: { + updatedAt: "desc", + }, + }); + + return NextResponse.json( + { success: true, message: "Berhasil mendapatkan data", data: data }, + { status: 200 } + ); + } catch (error) { + console.error("Error Get Master Bank >>", error); + return NextResponse.json( + { + success: false, + message: "API Error Get Data", + reason: (error as Error).message, + }, + { status: 500 } + ); + } +} + +async function POST(request: Request) { + const { data } = await request.json(); + try { + const count = await prisma.masterBank.count(); + const createNewId = count + 1; + + const create = await prisma.masterBank.create({ + data: { + id: createNewId.toString(), + namaBank: data.namaBank, + namaAkun: data.namaAkun, + norek: data.norek, + }, + }); + + return NextResponse.json({ + status: 200, + success: true, + message: "Berhasil menambahkan data", + data: create, + }); + } catch (error) { + console.error("Error Post Master Bank >>", error); + return NextResponse.json({ + status: 500, + success: false, + message: "API Error Post Data", + reason: (error as Error).message, + }); + } +} diff --git a/src/app/api/mobile/admin/master/business-field/[id]/route.ts b/src/app/api/mobile/admin/master/business-field/[id]/route.ts new file mode 100644 index 00000000..9cc26fdf --- /dev/null +++ b/src/app/api/mobile/admin/master/business-field/[id]/route.ts @@ -0,0 +1,61 @@ +import { NextResponse } from "next/server"; +import { prisma } from "@/lib"; + +export { GET, PUT }; + +async function GET(request: Request, { params }: { params: { id: string } }) { + try { + const { id } = params; + const data = await prisma.masterBidangBisnis.findUnique({ + where: { + id: id, + }, + }); + + return NextResponse.json({ + status: 200, + success: true, + message: "Berhasil mendapatkan data", + data: data, + }); + } catch (error) { + console.error("Error Get Master Bank >>", error); + return NextResponse.json({ + status: 500, + success: false, + message: "API Error Get Data", + reason: (error as Error).message, + }); + } +} + +async function PUT(request: Request, { params }: { params: { id: string } }) { + const { id } = params; + const { data } = await request.json(); + + try { + const updateData = await prisma.masterBidangBisnis.update({ + where: { + id: id, + }, + data: { + name: data.name, + active: data.active, + }, + }); + + return NextResponse.json({ + status: 200, + success: true, + message: "Berhasil mengupdate data", + }); + } catch (error) { + console.error("Error Update Master Bank >>", error); + return NextResponse.json({ + status: 500, + success: false, + message: "API Error Update Data", + reason: (error as Error).message, + }); + } +} diff --git a/src/app/api/mobile/admin/master/business-field/route.ts b/src/app/api/mobile/admin/master/business-field/route.ts new file mode 100644 index 00000000..52a6dfa1 --- /dev/null +++ b/src/app/api/mobile/admin/master/business-field/route.ts @@ -0,0 +1,65 @@ +import { NextResponse } from "next/server"; +import { prisma } from "@/lib"; + +export { GET, POST }; + +async function GET(request: Request) { + try { + const data = await prisma.masterBidangBisnis.findMany({ + orderBy: { + createdAt: "asc", + }, + }); + + return NextResponse.json({ + status: 200, + success: true, + message: "Berhasil mendapatkan data", + data: data, + }); + } catch (error) { + console.error( + "Error Get Master Bidang Bisnis >>", + error || (error as Error).message + ); + return NextResponse.json({ + status: 500, + success: false, + message: "API Error Get Master Bidang Bisnis ", + reason: (error as Error).message, + }); + } +} + +async function POST(request: Request) { + const { data } = await request.json(); + try { + const count = await prisma.masterBidangBisnis.count(); + const createNewId = count + 1; + + const slugName = data.name.toLowerCase().replace(/\s+/g, "_"); + + const create = await prisma.masterBidangBisnis.create({ + data: { + id: createNewId.toString(), + name: data.name, + slug: slugName, + }, + }); + + return NextResponse.json({ + status: 200, + success: true, + message: "Berhasil menambahkan data", + data: create, + }); + } catch (error) { + console.error("Error Post Master Business Field >>", error); + return NextResponse.json({ + status: 500, + success: false, + message: "API Error Post Data", + reason: (error as Error).message, + }); + } +} diff --git a/src/app/api/mobile/admin/master/type-of-event/[id]/route.ts b/src/app/api/mobile/admin/master/type-of-event/[id]/route.ts new file mode 100644 index 00000000..14aee2fe --- /dev/null +++ b/src/app/api/mobile/admin/master/type-of-event/[id]/route.ts @@ -0,0 +1,59 @@ +import { NextResponse } from "next/server"; +import prisma from "@/lib/prisma"; + +export { GET, PUT }; + +async function GET(request: Request, { params }: { params: { id: string } }) { + const { id } = params; + + try { + const data = await prisma.eventMaster_TipeAcara.findUnique({ + where: { + id: Number(id), + }, + }); + + return NextResponse.json({ + success: true, + message: "Success get type of event", + data: data, + }); + } catch (error) { + console.error("Error get type of event", error); + return NextResponse.json({ + success: false, + message: "Error get type of event", + reason: (error as Error).message, + }); + } +} + +async function PUT(request: Request, { params }: { params: { id: string } }) { + const { id } = params; + const { data } = await request.json(); + + try { + const updated = await prisma.eventMaster_TipeAcara.update({ + where: { + id: Number(id), + }, + data: { + name: data.name, + active: data.active, + }, + }); + + return NextResponse.json({ + success: true, + message: "Success update type of event", + data: updated, + }); + } catch (error) { + console.error("Error update type of event", error); + return NextResponse.json({ + success: false, + message: "Error update type of event", + reason: (error as Error).message, + }); + } +} diff --git a/src/app/api/mobile/admin/master/type-of-event/route.ts b/src/app/api/mobile/admin/master/type-of-event/route.ts new file mode 100644 index 00000000..86547a0d --- /dev/null +++ b/src/app/api/mobile/admin/master/type-of-event/route.ts @@ -0,0 +1,70 @@ +import { NextResponse } from "next/server"; +import prisma from "@/lib/prisma"; + +export { GET, POST }; + +async function GET(request: Request) { + try { + const data = await prisma.eventMaster_TipeAcara.findMany({ + orderBy: { + updatedAt: "desc", + }, + }); + + return NextResponse.json({ + success: true, + message: "Success get type of event", + data: data, + }); + } catch (error) { + console.error("Error get type of event", error); + return NextResponse.json({ + success: false, + message: "Error get type of event", + reason: (error as Error).message, + }); + } +} + +async function POST(request: Request) { + const { data } = await request.json(); + + try { + const checkList = await prisma.eventMaster_TipeAcara.count({}); + + if (!checkList) { + return NextResponse.json( + { + success: false, + message: "Type of event already exists", + }, + { status: 400 } + ); + } + + const created = await prisma.eventMaster_TipeAcara.create({ + data: { + id: checkList + 1, + name: data, + }, + }); + + return NextResponse.json( + { + success: true, + message: "Success create type of event", + }, + { status: 201 } + ); + } catch (error) { + console.error("Error create type of event", error); + return NextResponse.json( + { + success: false, + message: "Error create type of event", + reason: (error as Error).message, + }, + { status: 500 } + ); + } +} diff --git a/src/app/api/mobile/admin/user/[id]/route.ts b/src/app/api/mobile/admin/user/[id]/route.ts new file mode 100644 index 00000000..c9cec177 --- /dev/null +++ b/src/app/api/mobile/admin/user/[id]/route.ts @@ -0,0 +1,87 @@ +import { prisma } from "@/lib"; +import _ from "lodash"; +import { NextResponse } from "next/server"; + +export { GET, PUT }; + +async function GET(request: Request, { params }: { params: { id: string } }) { + const { id } = params; + + try { + const data = await prisma.user.findUnique({ + where: { + id: id, + }, + }); + + return NextResponse.json({ + status: 200, + success: true, + message: "Success get data user access", + data: data, + }); + } catch (error) { + console.log("[ERROR]", error); + return NextResponse.json({ + status: 500, + success: false, + message: "Error get data user access", + reason: (error as Error).message, + }); + } +} + +async function PUT(request: Request, { params }: { params: { id: string } }) { + const { id } = params; + const { data } = await request.json(); + + try { + if (data.active) { + const updateData = await prisma.user.update({ + where: { + id: id, + }, + data: { + active: data.active, + }, + }); + + console.log("[Update Active Berhasil]", updateData); + } else if (data.role) { + const fixName = _.startCase(data.role.replace(/_/g, " ")); + + const checkRole = await prisma.masterUserRole.findFirst({ + where: { + name: fixName, + }, + }); + + console.log("[CHECK ROLE]", checkRole); + + const updateData = await prisma.user.update({ + where: { + id: id, + }, + data: { + masterUserRoleId: checkRole?.id, + }, + }); + + console.log("[Update Role Berhasil]", updateData); + } + + return NextResponse.json({ + status: 200, + success: true, + message: "Success update data user access", + }); + } catch (error) { + console.log("[ERROR]", error); + return NextResponse.json({ + status: 500, + success: false, + message: "Error update data user access", + reason: (error as Error).message, + }); + } +} diff --git a/src/app/api/mobile/admin/user/route.ts b/src/app/api/mobile/admin/user/route.ts new file mode 100644 index 00000000..ff4aabf8 --- /dev/null +++ b/src/app/api/mobile/admin/user/route.ts @@ -0,0 +1,77 @@ +import { NextResponse } from "next/server"; +import { prisma } from "@/lib"; + +export { GET }; + +async function GET(request: Request) { + const { searchParams } = new URL(request.url); + const search = searchParams.get("search"); + const category = searchParams.get("category"); + + let fixData; + try { + if(category === "only-user"){ + fixData = await prisma.user.findMany({ + orderBy: { + updatedAt: "desc", + }, + where: { + masterUserRoleId: "1", + username: { + contains: search || "", + mode: "insensitive", + }, + }, + }); + } else if(category === "only-admin"){ + fixData = await prisma.user.findMany({ + orderBy: { + updatedAt: "desc", + }, + where: { + masterUserRoleId: "2", + username: { + contains: search || "", + mode: "insensitive", + }, + }, + }); + } else if (category === "all-role"){ + fixData = await prisma.user.findMany({ + orderBy: { + updatedAt: "desc", + }, + where: { + OR: [ + { + masterUserRoleId: "1", + }, + { + masterUserRoleId: "2", + } + ], + username: { + contains: search || "", + mode: "insensitive", + }, + }, + }); + } + + return NextResponse.json({ + status: 200, + success: true, + message: "Success get data user access", + data: fixData, + }); + } catch (error) { + return NextResponse.json( + { + status: 500, + success: false, + message: "Error get data user access", + reason: (error as Error).message, + }, + ); + } +} diff --git a/src/app/api/mobile/admin/voting/[id]/route.ts b/src/app/api/mobile/admin/voting/[id]/route.ts new file mode 100644 index 00000000..e88bdccb --- /dev/null +++ b/src/app/api/mobile/admin/voting/[id]/route.ts @@ -0,0 +1,109 @@ +import { NextResponse } from "next/server"; +import { prisma } from "@/lib"; +import _ from "lodash"; + +export { GET , PUT}; + +async function GET(request: Request, { params }: { params: { id: string } }) { + const { id } = params; + try { + const data = await prisma.voting.findUnique({ + where: { + id: id, + }, + include: { + Author: true, + Voting_Status: true, + Voting_DaftarNamaVote: true, + }, + }); + return NextResponse.json( + { + success: true, + message: "Success get data voting", + data: data, + }, + { status: 200 } + ); + } catch (error) { + console.log("[ERROR GET DATA VOTING]", error); + return NextResponse.json( + { + success: false, + message: "Error get data voting", + reason: (error as Error).message, + }, + { status: 500 } + ); + } +} + +async function PUT(request: Request, { params }: { params: { id: string } }) { + const { id } = params; + const { data } = await request.json(); + const { searchParams } = new URL(request.url); + const status = searchParams.get("status"); + const fixStatus = _.startCase(status as string); + let fixData; + + + try { + const checkStatus = await prisma.voting_Status.findFirst({ + where: { + name: fixStatus, + }, + }); + + if (!checkStatus) + return NextResponse.json( + { + success: false, + message: "Error update data voting", + reason: "Status not found", + }, + { status: 500 } + ); + + if (fixStatus === "Reject") { + const updateStatus = await prisma.voting.update({ + where: { + id: id, + }, + data: { + voting_StatusId: checkStatus.id, + catatan: data, + }, + }); + fixData = updateStatus; + } else if (fixStatus === "Publish") { + const updateStatus = await prisma.voting.update({ + where: { + id: id, + }, + data: { + voting_StatusId: checkStatus.id, + }, + }); + fixData = updateStatus; + } + + return NextResponse.json( + { + success: true, + message: "Success update data voting", + data: fixData, + }, + { status: 200 } + ); + } catch (error) { + console.log("[ERROR UPDATE DATA VOTING]", error); + return NextResponse.json( + { + success: false, + message: "Error update data voting", + reason: (error as Error).message, + }, + { status: 500 } + ); + } +} diff --git a/src/app/api/mobile/admin/voting/route.ts b/src/app/api/mobile/admin/voting/route.ts new file mode 100644 index 00000000..3b3f90ce --- /dev/null +++ b/src/app/api/mobile/admin/voting/route.ts @@ -0,0 +1,249 @@ +import _ from "lodash"; +import moment from "moment"; +import { NextResponse } from "next/server"; +import { prisma } from "@/lib"; + +export { GET }; + +async function GET(request: Request) { + const { searchParams } = new URL(request.url); + const category = searchParams.get("category"); + const fixToStatus = _.startCase(category || ""); + + const search = searchParams.get("search"); + const page = searchParams.get("page"); + const takeData = 10; + const skipData = Number(page) * takeData - takeData; + let fixData; + + try { + if (category === "dashboard") { + const publish = await prisma.voting.count({ + where: { + Voting_Status: { + name: "Publish", + }, + isActive: true, + isArsip: false, + akhirVote: { + gte: new Date(), + }, + }, + }); + + const review = await prisma.voting.count({ + where: { + Voting_Status: { + name: "Review", + }, + isActive: true, + isArsip: false, + akhirVote: { + gte: new Date(), + }, + }, + }); + + const reject = await prisma.voting.count({ + where: { + Voting_Status: { + name: "Reject", + }, + isActive: true, + isArsip: false, + akhirVote: { + gte: new Date(), + }, + }, + }); + + const history = await prisma.voting.count({ + where: { + Voting_Status: { + name: "Publish", + }, + isActive: true, + isArsip: false, + akhirVote: { + lte: new Date(), + }, + }, + }); + + fixData = { + publish, + review, + reject, + history, + }; + } else if (category === "history") { + fixData = await prisma.voting.findMany({ + take: page ? takeData : undefined, + skip: page ? skipData : undefined, + orderBy: { + updatedAt: "desc", + }, + where: { + Voting_Status: { + name: "Publish", + }, + isActive: true, + isArsip: false, + akhirVote: { + lte: new Date(), + }, + title: { + contains: search ? search : "", + mode: "insensitive", + }, + }, + include: { + Author: { + select: { + id: true, + username: true, + Profile: { + select: { + id: true, + name: true, + }, + }, + }, + }, + Voting_Kontributor: true, + Voting_DaftarNamaVote: true, + }, + }); + } else { + // ====== Status Publish Start ====== // + if (fixToStatus === "Publish") { + const getAllData = await prisma.voting.findMany({ + where: { + Voting_Status: { + name: "Publish", + }, + isActive: true, + isArsip: false, + akhirVote: { + gte: new Date(), + }, + }, + }); + + for (let i of getAllData) { + if (moment(i.akhirVote).diff(moment(), "minutes") < 0) { + await prisma.voting.update({ + where: { + id: i.id, + }, + data: { + isArsip: true, + }, + }); + } + } + + const data = await prisma.voting.findMany({ + take: page ? takeData : undefined, + skip: page ? skipData : undefined, + orderBy: { + createdAt: "desc", + }, + where: { + Voting_Status: { + name: "Publish", + }, + isActive: true, + title: { + contains: search ? search : "", + mode: "insensitive", + }, + akhirVote: { + gte: new Date(), + }, + isArsip: false, + }, + include: { + Author: { + select: { + id: true, + username: true, + Profile: { + select: { + id: true, + name: true, + }, + }, + }, + }, + Voting_Kontributor: true, + Voting_DaftarNamaVote: true, + }, + }); + + fixData = data; + + // ====== Status Publish End ====== // + } else { + // ====== Status Other Start ====== // + const data = await prisma.voting.findMany({ + take: page ? takeData : undefined, + skip: page ? skipData : undefined, + orderBy: { + createdAt: "desc", + }, + where: { + Voting_Status: { + name: fixToStatus, + }, + isActive: true, + title: { + contains: search ? search : "", + mode: "insensitive", + }, + isArsip: false, + }, + include: { + Author: { + select: { + id: true, + username: true, + Profile: { + select: { + id: true, + name: true, + }, + }, + }, + }, + Voting_Kontributor: true, + Voting_DaftarNamaVote: true, + }, + }); + + fixData = data; + + // ====== Status Other End ====== // + } + } + + return NextResponse.json( + { + success: true, + message: `Success get data voting ${category}`, + data: fixData, + }, + { status: 200 } + ); + } catch (error) { + console.log(`[ERROR GET DATA VOTING: ${category}]`, error); + return NextResponse.json( + { + success: false, + message: `Error get data voting ${category}`, + reason: (error as Error).message, + }, + { status: 500 } + ); + } +} diff --git a/src/app/api/mobile/donation/[id]/[status]/route.ts b/src/app/api/mobile/donation/[id]/[status]/route.ts index 9b67d81a..94fd76f3 100644 --- a/src/app/api/mobile/donation/[id]/[status]/route.ts +++ b/src/app/api/mobile/donation/[id]/[status]/route.ts @@ -19,8 +19,6 @@ async function GET( }, }); - console.log("[CHECK STATUS]", checkStatus); - if (!checkStatus) return NextResponse.json({ status: 400, diff --git a/src/app/api/mobile/donation/[id]/fundrising/route.ts b/src/app/api/mobile/donation/[id]/fundrising/route.ts new file mode 100644 index 00000000..20aa1b2e --- /dev/null +++ b/src/app/api/mobile/donation/[id]/fundrising/route.ts @@ -0,0 +1,103 @@ +import { NextResponse } from "next/server"; +import { prisma } from "@/lib"; + +export async function GET( + request: Request, + { params }: { params: { id: string } } +) { + let fixData; + try { + const { id } = params; + const user = await prisma.user.findUnique({ + where: { + id: id, + }, + select: { + id: true, + username: true, + nomor: true, + Profile: { + select: { + id: true, + name: true, + email: true, + imageId: true, + }, + }, + // Donasi: { + // orderBy: { + // createdAt: "desc", + // }, + // where: { + // donasiMaster_StatusDonasiId: "1", + // }, + // select: { + // id: true, + // title: true, + // target: true, + // active: true, + // createdAt: true, + // updatedAt: true, + // publishTime: true, + // catatan: true, + // authorId: true, + // progres: true, + // terkumpul: true, + // imagesId: true, + // donasiMaster_KategoriId: true, + // donasiMaster_DurasiId: true, + // donasiMaster_StatusDonasiId: true, + // Author: true, + // imageDonasi: true, + // CeritaDonasi: true, + // DonasiMaster_Ketegori: true, + // DonasiMaster_Durasi: true, + // DonasiMaster_Status: true, + // imageId: true, + // }, + // }, + }, + }); + + const donasi = await prisma.donasi.findMany({ + where: { + authorId: id, + donasiMaster_StatusDonasiId: "1", + active: true, + }, + orderBy: { + publishTime: "desc", + }, + select: { + id: true, + imageId: true, + title: true, + publishTime: true, + progres: true, + terkumpul: true, + DonasiMaster_Durasi: { + select: { + name: true, + }, + }, + }, + }); + + fixData = { + user, + donasi, + }; + + return NextResponse.json({ + success: true, + message: "Data berhasil diambil", + data: fixData, + }); + } catch (error) { + return NextResponse.json({ + success: false, + message: "Terjadi kesalahan saat mengambil data", + reason: error as Error, + }); + } +} diff --git a/src/app/api/mobile/donation/[id]/invoice/route.ts b/src/app/api/mobile/donation/[id]/invoice/route.ts new file mode 100644 index 00000000..b9be4fbb --- /dev/null +++ b/src/app/api/mobile/donation/[id]/invoice/route.ts @@ -0,0 +1,178 @@ +import _ from "lodash"; +import { NextResponse } from "next/server"; +import prisma from "@/lib/prisma"; + +export { POST, GET, PUT }; + +async function POST(request: Request, { params }: { params: { id: string } }) { + const { id } = params; + const { data } = await request.json(); + + try { + const create = await prisma.donasi_Invoice.create({ + data: { + donasiId: id, + nominal: data.nominal, + donasiMaster_BankId: data.bankId, + authorId: data.authorId, + }, + select: { + id: true, + DonasiMaster_StatusInvoice: { + select: { + name: true, + }, + }, + Donasi: { + select: { + id: true, + title: true, + authorId: true, + }, + }, + }, + }); + + return NextResponse.json({ + status: 201, + success: true, + message: "Berhasil membuat invoice", + data: create, + }); + } catch (error) { + console.log("[ERROR]", error); + return NextResponse.json({ + status: 500, + success: false, + message: "Gagal membuat invoice", + reason: (error as Error).message, + }); + } +} + +async function GET(request: Request, { params }: { params: { id: string } }) { + try { + const { id } = params; + const data = await prisma.donasi_Invoice.findUnique({ + where: { + id: id, + }, + select: { + id: true, + authorId: true, + nominal: true, + donasiId: true, + createdAt: true, + donasiMaster_BankId: true, + donasiMaster_StatusInvoiceId: true, + Donasi: { + select: { + id: true, + title: true, + target: true, + active: true, + createdAt: true, + updatedAt: true, + publishTime: true, + catatan: true, + progres: true, + terkumpul: true, + authorId: true, + imagesId: true, + donasiMaster_KategoriId: true, + donasiMaster_DurasiId: true, + donasiMaster_StatusDonasiId: true, + Author: true, + imageDonasi: true, + CeritaDonasi: true, + DonasiMaster_Ketegori: true, + DonasiMaster_Durasi: true, + DonasiMaster_Status: true, + imageId: true, + }, + }, + DonasiMaster_Bank: true, + DonasiMaster_StatusInvoice: true, + }, + }); + + if (!data) { + return NextResponse.json({ + success: false, + message: "Data tidak ditemukan", + }); + } + + return NextResponse.json({ + success: true, + message: "Data berhasil diambil", + data: data, + }); + } catch (error) { + return NextResponse.json({ + success: false, + message: "Terjadi kesalahan saat mengambil data", + reason: (error as Error).message || error, + }); + } +} + +async function PUT(request: Request, { params }: { params: { id: string } }) { + const { id } = params; + const { data } = await request.json(); + const { searchParams } = new URL(request.url); + const status = searchParams.get("status"); + const fixStatus = _.startCase(status as string); + + try { + const checkStatus = await prisma.donasiMaster_StatusInvoice.findFirst({ + where: { + name: fixStatus, + }, + }); + + if (!checkStatus) { + return NextResponse.json({ + success: false, + message: "Status tidak ditemukan", + }); + } + const update = await prisma.donasi_Invoice.update({ + where: { + id: id, + }, + data: { + donasiMaster_StatusInvoiceId: checkStatus.id, + imageId: data.fileId, + }, + select: { + id: true, + DonasiMaster_StatusInvoice: { + select: { + name: true, + }, + }, + Donasi: { + select: { + id: true, + title: true, + authorId: true, + }, + }, + }, + }); + + return NextResponse.json({ + status: 200, + success: true, + message: "Data berhasil diperbarui", + }); + } catch (error) { + return NextResponse.json({ + status: 500, + success: false, + message: "Terjadi kesalahan saat memperbarui data", + reason: (error as Error).message || error, + }); + } +} diff --git a/src/app/api/mobile/donation/[id]/news/route.ts b/src/app/api/mobile/donation/[id]/news/route.ts new file mode 100644 index 00000000..94f8b5d9 --- /dev/null +++ b/src/app/api/mobile/donation/[id]/news/route.ts @@ -0,0 +1,222 @@ +import { NextRequest, NextResponse } from "next/server"; +import { prisma } from "@/lib"; +import _ from "lodash"; + +export { POST, GET, PUT, DELETE }; + +async function POST( + request: NextRequest, + { params }: { params: { id: string } } +) { + const { id } = params; + const { data } = await request.json(); + + + try { + if (data && data?.imageId) { + const createWithFile = await prisma.donasi_Kabar.create({ + data: { + title: data.title, + deskripsi: data.deskripsi, + donasiId: id, + imageId: data.imageId, + }, + }); + + if (!createWithFile) + return NextResponse.json({ status: 400, message: "Gagal disimpan" }); + } else { + const create = await prisma.donasi_Kabar.create({ + data: { + title: data.title, + deskripsi: data.deskripsi, + donasiId: id, + }, + }); + + if (!create) + return NextResponse.json({ status: 400, message: "Gagal disimpan" }); + } + + return NextResponse.json({ + status: 200, + success: true, + message: "Berhasil membuat kabar", + }); + } catch (error) { + console.error("[ERROR CREATE NEWS]", error); + return NextResponse.json({ + status: 500, + success: false, + message: "Error Create Donation News", + reason: (error as Error).message, + }); + } +} + +async function GET( + request: NextRequest, + { params }: { params: { id: string } } +) { + const { id } = params; + const { searchParams } = new URL(request.url); + const category = searchParams.get("category"); + let fixData; + + try { + if (category === "get-all") { + fixData = await prisma.donasi_Kabar.findMany({ + orderBy: { + updatedAt: "desc", + }, + where: { + donasiId: id, + active: true, + }, + select: { + id: true, + title: true, + deskripsi: true, + createdAt: true, + }, + }); + } else if (category === "get-one") { + const data = await prisma.donasi_Kabar.findUnique({ + where: { + id: id, + }, + include: { + Donasi: { + select: { + authorId: true, + }, + }, + }, + }); + + const authorId = data?.Donasi?.authorId; + + fixData = { + ..._.omit(data, ["Donasi"]), + authorId: authorId, + }; + } + + return NextResponse.json({ + status: 200, + success: true, + message: "Berhasil mengambil kabar", + data: fixData, + }); + } catch (error) { + console.error("[ERROR GET NEWS]", error); + return NextResponse.json({ + status: 500, + success: false, + message: "Error Get Donation News", + reason: (error as Error).message, + }); + } +} + +async function PUT(request: Request, { params }: { params: { id: string } }) { + const { id } = params; + const { data } = await request.json(); + + try { + if (data && data.newImageId) { + const updateWithImage = await prisma.donasi_Kabar.update({ + where: { + id: id, + }, + data: { + title: data.title, + deskripsi: data.deskripsi, + imageId: data.newImageId, + }, + }); + + if (!updateWithImage) + return NextResponse.json({ + status: 400, + success: false, + message: "Gagal Update", + }); + } else { + const updateData = await prisma.donasi_Kabar.update({ + where: { + id: id, + }, + data: { + title: data.title, + deskripsi: data.deskripsi, + }, + }); + + if (!updateData) + return NextResponse.json({ + status: 400, + success: false, + message: "Gagal Update", + }); + } + return NextResponse.json({ + status: 200, + success: true, + message: "Berhasil Update", + }); + } catch (error) { + console.error("[ERROR UPDATE NEWS]", error); + return NextResponse.json({ + status: 500, + success: false, + message: "Error Update Donation News", + reason: (error as Error).message, + }); + } +} + +async function DELETE( + request: Request, + { params }: { params: { id: string } } +) { + const { id } = params; + try { + const deleteData = await prisma.donasi_Kabar.delete({ + where: { + id: id, + }, + select: { + imageId: true, + }, + }); + + const deleteImage = await fetch( + `https://wibu-storage.wibudev.com/api/files/${deleteData?.imageId}/delete`, + { + method: "DELETE", + headers: { + Authorization: `Bearer ${process.env.WS_APIKEY}`, + }, + } + ); + + if (!deleteImage) { + console.log("[FAILED DELETE IMAGE]", deleteImage); + } + + return NextResponse.json({ + status: 200, + success: true, + message: "Berhasil Delete", + }); + } catch (error) { + console.error("[ERROR DELETE NEWS]", error); + return NextResponse.json({ + status: 500, + success: false, + message: "Error Delete Donation News", + reason: (error as Error).message, + }); + } +} diff --git a/src/app/api/mobile/donation/[id]/route.ts b/src/app/api/mobile/donation/[id]/route.ts index 7639bd14..0dbac928 100644 --- a/src/app/api/mobile/donation/[id]/route.ts +++ b/src/app/api/mobile/donation/[id]/route.ts @@ -22,7 +22,19 @@ async function GET(request: Request, { params }: { params: { id: string } }) { id: id, }, include: { - Author: true, + Author: { + select: { + id: true, + username: true, + Profile: { + select: { + id: true, + name: true, + imageId: true, + }, + }, + }, + }, imageDonasi: true, CeritaDonasi: true, DonasiMaster_Ketegori: true, @@ -192,9 +204,7 @@ async function PUT(request: Request, { params }: { params: { id: string } }) { if (!deleteImageDonasi) { console.log("[DELETE IMAGE DONASI]", deleteImageDonasi); } - } else if (category === "edit-story") { - if (data && data.newImageId) { await prisma.donasi_Cerita.update({ where: { diff --git a/src/app/api/mobile/donation/route.ts b/src/app/api/mobile/donation/route.ts index 95d44403..5aa9c781 100644 --- a/src/app/api/mobile/donation/route.ts +++ b/src/app/api/mobile/donation/route.ts @@ -1,6 +1,6 @@ +import prisma from "@/lib/prisma"; import _ from "lodash"; import { NextResponse } from "next/server"; -import prisma from "@/lib/prisma"; export { POST }; @@ -10,7 +10,6 @@ async function POST(request: Request) { const category = searchParams.get("category"); let fixData; - try { // CODE HERE @@ -93,3 +92,102 @@ async function POST(request: Request) { }); } } + +// GET ALL DATA DONASI +export async function GET(request: Request) { + const { searchParams } = new URL(request.url); + const category = searchParams.get("category"); + const authorId = searchParams.get("authorId"); + let fixData; + + try { + if (category === "beranda") { + const data = await prisma.donasi.findMany({ + orderBy: { + publishTime: "desc", + }, + where: { + donasiMaster_StatusDonasiId: "1", + active: true, + }, + select: { + id: true, + imageId: true, + title: true, + publishTime: true, + progres: true, + terkumpul: true, + DonasiMaster_Durasi: { + select: { + name: true, + }, + }, + }, + }); + + fixData = data.map((v: any) => ({ + ..._.omit(v, ["DonasiMaster_Durasi"]), + durasiDonasi: v.DonasiMaster_Durasi.name, + })); + } else if (category === "my-donation") { + const data = await prisma.donasi_Invoice.findMany({ + orderBy: { + createdAt: "desc", + }, + where: { + authorId: authorId, + }, + select: { + id: true, + nominal: true, + donasiMaster_StatusInvoiceId: true, + DonasiMaster_StatusInvoice: { + select: { + name: true, + }, + }, + Donasi: { + select: { + id: true, + title: true, + publishTime: true, + progres: true, + imageId: true, + DonasiMaster_Durasi: { + select: { + name: true, + }, + }, + }, + }, + }, + }); + + fixData = data.map((v: any) => ({ + ..._.omit(v, ["DonasiMaster_StatusInvoice", "Donasi"]), + statusInvoice: v.DonasiMaster_StatusInvoice.name, + donasiId: v.Donasi.id, + title: v.Donasi.title, + publishTime: v.Donasi.publishTime, + progres: v.Donasi.progres, + imageId: v.Donasi.imageId, + durasiDonasi: v.Donasi.DonasiMaster_Durasi.name, + })); + } + + return NextResponse.json( + { success: true, message: "Data berhasil diambil", data: fixData }, + { status: 200 } + ); + } catch (error) { + console.error("[ERROR]", error); + return NextResponse.json( + { + success: false, + message: "Gagal mendapatkan data, coba lagi nanti ", + reason: (error as Error).message, + }, + { status: 500 } + ); + } +} diff --git a/src/app/api/mobile/event/[id]/check-participants/route.ts b/src/app/api/mobile/event/[id]/check-participants/route.ts index 3121be58..3cfed6d0 100644 --- a/src/app/api/mobile/event/[id]/check-participants/route.ts +++ b/src/app/api/mobile/event/[id]/check-participants/route.ts @@ -9,6 +9,9 @@ async function GET(request: Request, { params }: { params: { id: string } }) { const { searchParams } = new URL(request.url); const userId = searchParams.get("userId"); + console.log("id", id); + console.log("userId", userId); + let fixData const checkParticipant = await prisma.event_Peserta.findFirst({ diff --git a/src/app/api/mobile/event/[id]/confirmation/route.ts b/src/app/api/mobile/event/[id]/confirmation/route.ts new file mode 100644 index 00000000..450d2fbe --- /dev/null +++ b/src/app/api/mobile/event/[id]/confirmation/route.ts @@ -0,0 +1,168 @@ +import { prisma } from "@/lib"; +import { NextResponse } from "next/server"; + +export async function GET( + request: Request, + { params }: { params: { id: string } } +) { + try { + const { id } = params; + let fixData; + const { searchParams } = new URL(request.url); + const userId = searchParams.get("userId"); + + const checkDataEvent = await prisma.event.findUnique({ + where: { + id: id, + }, + select: { + id: true, + title: true, + tanggal: true, + tanggalSelesai: true, + lokasi: true, + Author: { + select: { + id: true, + username: true, + Profile: { + select: { + id: true, + name: true, + }, + }, + }, + }, + }, + }); + + if (!checkDataEvent) { + return NextResponse.json( + { message: "Event Not Found", response: null }, + { status: 400 } + ); + } + + let peserta; + const checkPeserta = await prisma.event_Peserta.findFirst({ + where: { + userId: userId, + eventId: id, + }, + }); + + if (checkPeserta) { + peserta = true; + } else { + peserta = false; + } + + let kehadiran; + const checkKehadiran = await prisma.event_Peserta.findFirst({ + where: { + userId: userId, + eventId: id, + }, + select: { + isPresent: true, + }, + }); + + if (checkKehadiran?.isPresent) { + kehadiran = true; + } else { + kehadiran = false; + } + + fixData = { + dataEvent: checkDataEvent, + peserta: peserta, + kehadiran: kehadiran, + }; + + return NextResponse.json( + { success: true, message: "Event Found", data: fixData }, + { status: 200 } + ); + } catch (error) { + console.error("Error get confirmation event", error); + return NextResponse.json( + { + success: false, + message: "Error get confirmation event", + reason: (error as Error).message || error, + }, + { status: 500 } + ); + } +} + +export async function POST( + request: Request, + { params }: { params: { id: string } } +) { + const { id } = params; + const { data } = await request.json(); + const { searchParams } = new URL(request.url); + const category = searchParams.get("category"); + + let fixData; + try { + console.log("category", category); + console.log("id", id); + console.log("data", data); + + if (category === "join_and_confirm") { + const join = await prisma.event_Peserta.create({ + data: { + eventId: id, + userId: data.userId, + isPresent: true, + }, + }); + + fixData = join; + } else if (category === "confirmation") { + const checkPeserta = await prisma.event_Peserta.findFirst({ + where: { + userId: data.userId, + eventId: id, + isPresent: false, + }, + }); + + if (!checkPeserta) { + return NextResponse.json( + { message: "Peserta Not Found", response: null }, + { status: 400 } + ); + } + + const confirm = await prisma.event_Peserta.update({ + where: { + id: checkPeserta.id, + }, + data: { + isPresent: true, + }, + }); + + fixData = confirm; + } + + return NextResponse.json( + { success: true, message: `Success ${category}`, data: fixData }, + { status: 200 } + ); + } catch (error) { + console.error("Error upsert confirmation event", error); + return NextResponse.json( + { + success: false, + message: "Error upsert confirmation event", + reason: (error as Error).message || error, + }, + { status: 500 } + ); + } +} diff --git a/src/app/api/mobile/maps/[id]/route.ts b/src/app/api/mobile/maps/[id]/route.ts new file mode 100644 index 00000000..7308d9a8 --- /dev/null +++ b/src/app/api/mobile/maps/[id]/route.ts @@ -0,0 +1,107 @@ +import { NextResponse } from "next/server"; +import { prisma } from "@/lib"; + +export { GET }; + +async function GET(request: Request, { params }: { params: { id: string } }) { + const { id } = params; + try { + const data = await prisma.businessMaps.findUnique({ + where: { + id: id, + }, + }); + return NextResponse.json({ + success: true, + message: "Berhasil mendapatkan data pin map", + data: data, + }); + } catch (error) { + console.error("[ERROR]", error); + return NextResponse.json({ + success: false, + message: "Gagal mendapatkan data pin map", + reason: (error as Error).message, + }); + } +} + +export async function PUT( + request: Request, + { params }: { params: { id: string } } +) { + const { id } = params; + const { data } = await request.json(); + + try { + let fixData; + + const ceheckData = await prisma.businessMaps.findUnique({ + where: { + id: id, + }, + }); + + if (!ceheckData) { + return NextResponse.json({ + status: 404, + success: false, + message: "Data tidak ditemukan", + }); + } + + if (data.newImageId) { + const updated = await prisma.businessMaps.update({ + where: { + id: id, + }, + data: { + namePin: data.namePin, + latitude: data.latitude, + longitude: data.longitude, + imageId: data.newImageId, + }, + }); + + if (updated) { + const deleteImage = await fetch( + `https://wibu-storage.wibudev.com/api/files/${ceheckData.imageId}/delete`, + { + method: "DELETE", + headers: { + Authorization: `Bearer ${process.env.WS_APIKEY}`, + }, + } + ); + } + + fixData = updated; + } else { + const updated = await prisma.businessMaps.update({ + where: { + id: id, + }, + data: { + namePin: data.namePin, + latitude: data.latitude, + longitude: data.longitude, + }, + }); + + fixData = updated; + } + + return NextResponse.json({ + success: true, + message: "Berhasil mengupdate data pin map", + data: data, + }); + } catch (error) { + console.error("[ERROR]", error); + return NextResponse.json({ + success: false, + message: "Gagal mengupdate data pin map", + reason: (error as Error).message, + }); + } +} diff --git a/src/app/api/mobile/maps/route.ts b/src/app/api/mobile/maps/route.ts new file mode 100644 index 00000000..d5f9c21b --- /dev/null +++ b/src/app/api/mobile/maps/route.ts @@ -0,0 +1,73 @@ +import { NextResponse } from "next/server"; +import { prisma } from "@/lib"; + +export { POST }; + +async function POST(request: Request) { + const { data } = await request.json(); + + try { + const created = await prisma.businessMaps.create({ + data: { + latitude: data.latitude, + longitude: data.longitude, + namePin: data.namePin, + imageId: data.imageId || null, + portofolioId: data.portofolioId, + authorId: data.authorId, + }, + }); + + return NextResponse.json({ + success: true, + message: "Berhasil membuat pin map", + data: created, + }); + } catch (error) { + console.error("[ERROR]", error); + return NextResponse.json({ + success: false, + message: "Gagal membuat pin map", + reason: (error as Error).message, + }); + } +} + +export async function GET(request: Request) { + try { + const data = await prisma.businessMaps.findMany({ + orderBy: { + updatedAt: "desc", + }, + include: { + Portofolio: { + select: { + id: true, + namaBisnis: true, + logoId: true, + alamatKantor: true, + tlpn: true, + MasterBidangBisnis: { + select: { + id: true, + name: true, + }, + }, + }, + }, + }, + }); + return NextResponse.json({ + success: true, + message: "Berhasil mendapatkan data pin map", + data: data, + }); + } catch (error) { + console.error("[ERROR]", error); + return NextResponse.json({ + success: false, + message: "Gagal mendapatkan data pin map", + reason: (error as Error).message, + }); + } +} diff --git a/src/app/api/mobile/portofolio/[id]/route.ts b/src/app/api/mobile/portofolio/[id]/route.ts index 1c4105a5..6a119737 100644 --- a/src/app/api/mobile/portofolio/[id]/route.ts +++ b/src/app/api/mobile/portofolio/[id]/route.ts @@ -55,6 +55,16 @@ async function GET(request: Request, { params }: { params: { id: string } }) { }, }, }, + BusinessMaps: { + select: { + id: true, + namePin: true, + latitude: true, + longitude: true, + imageId: true, + pinId: true, + }, + }, }, }); @@ -98,6 +108,7 @@ async function DELETE(request: Request, context: { params: { id: string } }) { include: { BusinessMaps: { select: { + id: true, pinId: true, imageId: true, }, @@ -123,61 +134,66 @@ async function DELETE(request: Request, context: { params: { id: string } }) { } } - if (data?.BusinessMaps?.pinId != null) { + if (data?.BusinessMaps) { const pinId = data?.BusinessMaps?.pinId; - const deletePin = await fetch( - `https://wibu-storage.wibudev.com/api/files/${pinId}/delete`, - { - method: "DELETE", - headers: { - Authorization: `Bearer ${process.env.WS_APIKEY}`, - }, - } - ); - if (deletePin.ok) { - console.log(`Success delete pin`); + if (pinId) { + const deletePin = await fetch( + `https://wibu-storage.wibudev.com/api/files/${pinId}/delete`, + { + method: "DELETE", + headers: { + Authorization: `Bearer ${process.env.WS_APIKEY}`, + }, + } + ); + + if (deletePin.ok) { + console.log(`Success delete business map pin`); + } } - const imageId = data?.BusinessMaps?.imageId; - const deleteImage = await fetch( - `https://wibu-storage.wibudev.com/api/files/${imageId}/delete`, - { - method: "DELETE", - headers: { - Authorization: `Bearer ${process.env.WS_APIKEY}`, - }, - } - ); + const mapImageId = data?.BusinessMaps?.imageId; - if (deleteImage.ok) { - console.log(`Success delete image`); + if (mapImageId) { + const deleteImage = await fetch( + `https://wibu-storage.wibudev.com/api/files/${mapImageId}/delete`, + { + method: "DELETE", + headers: { + Authorization: `Bearer ${process.env.WS_APIKEY}`, + }, + } + ); + + if (deleteImage.ok) { + console.log(`Success delete business map image `); + } } } + + const deletePortoMedsos = await prisma.portofolio_MediaSosial.delete({ + where: { + portofolioId: id, + }, + }); + + const deleteMap = await prisma.businessMaps.delete({ + where: { + portofolioId: id, + }, + }); + + const deletePortofolio = await prisma.portofolio.delete({ + where: { + id: id, + }, + }); + } catch (error) { console.error("Error delete logo", error); } - const deletePortoMedsos = await prisma.portofolio_MediaSosial.delete({ - where: { - portofolioId: id, - }, - }); - - // const deleteMap = await prisma.businessMaps.delete({ - // where: { - // portofolioId: id, - // }, - // }); - - // console.log("DELETE PORTOFOLIO MEDSOS >>", deletePortoMedsos); - - const deletePortofolio = await prisma.portofolio.delete({ - where: { - id: id, - }, - }); - return NextResponse.json( { success: true, message: "Berhasil menghapus data" }, { status: 200 } @@ -205,9 +221,6 @@ async function PUT(request: Request, { params }: { params: { id: string } }) { let message; if (category === "detail") { - console.log("UPDATE PORTOFOLIO DETAIL >>"); - console.log("DATA >>", data); - const checkData = await prisma.portofolio.findUnique({ where: { id }, include: { @@ -222,8 +235,6 @@ async function PUT(request: Request, { params }: { params: { id: string } }) { }); } - console.log("CHECK DATA >>", checkData); - const updateDetail = await prisma.portofolio.update({ where: { id }, data: {