Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7ab25655f2 | |||
| 9d17b442e2 | |||
| b3410a5804 | |||
| 2cdc57d844 | |||
| 695046583f | |||
| 6ee0b98f07 | |||
| cc78d82ca4 | |||
| 3c2a8b3543 | |||
| 276cf9e970 | |||
| 8ccf722c90 |
@@ -2,6 +2,12 @@
|
|||||||
|
|
||||||
All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
|
All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
|
||||||
|
|
||||||
|
## [1.5.26](https://wibugit.wibudev.com/wibu/hipmi/compare/v1.5.25...v1.5.26) (2025-12-10)
|
||||||
|
|
||||||
|
## [1.5.25](https://wibugit.wibudev.com/wibu/hipmi/compare/v1.5.24...v1.5.25) (2025-12-09)
|
||||||
|
|
||||||
|
## [1.5.24](https://wibugit.wibudev.com/wibu/hipmi/compare/v1.5.22...v1.5.24) (2025-12-08)
|
||||||
|
|
||||||
## [1.5.22](https://wibugit.wibudev.com/wibu/hipmi/compare/v1.5.21...v1.5.22) (2025-12-03)
|
## [1.5.22](https://wibugit.wibudev.com/wibu/hipmi/compare/v1.5.21...v1.5.22) (2025-12-03)
|
||||||
|
|
||||||
## [1.5.21](https://wibugit.wibudev.com/wibu/hipmi/compare/v1.5.20...v1.5.21) (2025-12-03)
|
## [1.5.21](https://wibugit.wibudev.com/wibu/hipmi/compare/v1.5.20...v1.5.21) (2025-12-03)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hipmi",
|
"name": "hipmi",
|
||||||
"version": "1.5.22",
|
"version": "1.5.26",
|
||||||
"private": true,
|
"private": true,
|
||||||
"prisma": {
|
"prisma": {
|
||||||
"seed": "bun prisma/seed.ts"
|
"seed": "bun prisma/seed.ts"
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "User" ADD COLUMN "acceptedForumTermsAt" TIMESTAMP(3),
|
||||||
|
ADD COLUMN "acceptedTermsAt" TIMESTAMP(3);
|
||||||
@@ -55,6 +55,9 @@ model User {
|
|||||||
|
|
||||||
blockedUsers BlockedUser[] @relation("Blocking")
|
blockedUsers BlockedUser[] @relation("Blocking")
|
||||||
blockedBy BlockedUser[] @relation("BlockedBy")
|
blockedBy BlockedUser[] @relation("BlockedBy")
|
||||||
|
|
||||||
|
acceptedTermsAt DateTime?
|
||||||
|
acceptedForumTermsAt DateTime?
|
||||||
}
|
}
|
||||||
|
|
||||||
model MasterUserRole {
|
model MasterUserRole {
|
||||||
|
|||||||
1098
prisma/schema.prisma.backup
Normal file
1098
prisma/schema.prisma.backup
Normal file
File diff suppressed because it is too large
Load Diff
@@ -4,7 +4,6 @@ import { NextResponse } from "next/server";
|
|||||||
|
|
||||||
export async function POST(req: Request) {
|
export async function POST(req: Request) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
const codeOtp = randomOTP();
|
const codeOtp = randomOTP();
|
||||||
const body = await req.json();
|
const body = await req.json();
|
||||||
console.log("[Masuk API]", body);
|
console.log("[Masuk API]", body);
|
||||||
@@ -39,23 +38,29 @@ export async function POST(req: Request) {
|
|||||||
{ status: 400 }
|
{ status: 400 }
|
||||||
);
|
);
|
||||||
|
|
||||||
const msg = `HIPMI - Kode ini bersifat RAHASIA dan JANGAN DI BAGIKAN KEPAADA SIAPAPUN, termasuk anggota ataupun pengurus HIPMI lainnya.\n\n\n> Kode OTP anda: ${codeOtp}.`;
|
// const msg = `HIPMI - Kode ini bersifat RAHASIA dan JANGAN DI BAGIKAN KEPAADA SIAPAPUN, termasuk anggota ataupun pengurus HIPMI lainnya.\n\n\n> Kode OTP anda: ${codeOtp}.`;
|
||||||
// const msg = `HIPMI%20-%20Kode%20ini%20bersifat%20RAHASIA%20dan%20JANGAN%20DI%20BAGIKAN%20KEPADA%20SIAPAPUN%2C%20termasuk%20anggota%20ataupun%20pengurus%20HIPMI%20lainnya.%20Kode%20OTP%20anda%3A%20${codeOtp}.`;
|
// const encodedMsg = encodeURIComponent(msg);
|
||||||
const encodedMsg = encodeURIComponent(msg);
|
const msg = `HIPMI%20-%20Kode%20ini%20bersifat%20RAHASIA%20dan%20JANGAN%20DI%20BAGIKAN%20KEPADA%20SIAPAPUN%2C%20termasuk%20anggota%20ataupun%20pengurus%20HIPMI%20lainnya.%20Kode%20OTP%20anda%3A%20${codeOtp}.`;
|
||||||
|
|
||||||
const res = await fetch(
|
const res = await fetch(
|
||||||
`https://wa.wibudev.com/code?nom=${nomor}&text=${encodedMsg}`,
|
`https://cld-dkr-prod-wajs-server.wibudev.com/api/wa/code?nom=${nomor}&text=${msg}`,
|
||||||
{ cache: "no-cache" }
|
{
|
||||||
|
cache: "no-cache",
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${process.env.WA_SERVER_TOKEN}`,
|
||||||
|
},
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
const sendWa = await res.json();
|
if (res.status !== 200)
|
||||||
|
|
||||||
if (sendWa.status !== "success")
|
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ success: false, message: "Nomor Whatsapp Tidak Aktif" },
|
{ success: false, message: "Nomor Whatsapp Tidak Aktif" },
|
||||||
{ status: 400 }
|
{ status: 400 }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const sendWa = await res.text();
|
||||||
|
console.log("WA Response:", sendWa);
|
||||||
|
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{
|
{
|
||||||
success: true,
|
success: true,
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ export async function POST(req: Request) {
|
|||||||
nomor: data.nomor,
|
nomor: data.nomor,
|
||||||
active: false,
|
active: false,
|
||||||
termsOfServiceAccepted: data.termsOfServiceAccepted,
|
termsOfServiceAccepted: data.termsOfServiceAccepted,
|
||||||
|
acceptedTermsAt: new Date(),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
|||||||
select: {
|
select: {
|
||||||
User: {
|
User: {
|
||||||
select: {
|
select: {
|
||||||
|
nomor: true,
|
||||||
username: true,
|
username: true,
|
||||||
id: true,
|
id: true,
|
||||||
Profile: {
|
Profile: {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
|
import prisma from "@/lib/prisma";
|
||||||
|
|
||||||
export { GET };
|
export { GET };
|
||||||
|
|
||||||
@@ -12,7 +13,6 @@ async function GET(request: Request) {
|
|||||||
const skipData = Number(page) * takeData - takeData;
|
const skipData = Number(page) * takeData - takeData;
|
||||||
console.log("[CATEGORY]", category);
|
console.log("[CATEGORY]", category);
|
||||||
let fixData;
|
let fixData;
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (category === "dashboard") {
|
if (category === "dashboard") {
|
||||||
|
|||||||
@@ -29,6 +29,11 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Event: {
|
||||||
|
select: {
|
||||||
|
tanggal: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -153,6 +153,7 @@ async function GET(request: Request) {
|
|||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
title: true,
|
title: true,
|
||||||
|
tanggal: true,
|
||||||
Author: {
|
Author: {
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
import { prisma } from "@/lib";
|
import { prisma } from "@/lib";
|
||||||
|
import _ from "lodash";
|
||||||
|
|
||||||
export { GET };
|
export { GET };
|
||||||
|
|
||||||
@@ -51,7 +52,7 @@ async function GET(request: Request, { params }: { params: { name: string } }) {
|
|||||||
reportComment,
|
reportComment,
|
||||||
};
|
};
|
||||||
} else if (category === "posting") {
|
} else if (category === "posting") {
|
||||||
fixData = await prisma.forum_Posting.findMany({
|
const data = await prisma.forum_Posting.findMany({
|
||||||
take: page ? takeData : undefined,
|
take: page ? takeData : undefined,
|
||||||
skip: page ? skipData : undefined,
|
skip: page ? skipData : undefined,
|
||||||
orderBy: {
|
orderBy: {
|
||||||
@@ -75,10 +76,24 @@ async function GET(request: Request, { params }: { params: { name: string } }) {
|
|||||||
Profile: true,
|
Profile: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
_count: {
|
||||||
|
select: {
|
||||||
|
Forum_ReportPosting: true,
|
||||||
|
Forum_Komentar: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
fixData = data.map((item) => ({
|
||||||
|
..._.omit(item, "_count"),
|
||||||
|
reportPosting: item._count.Forum_ReportPosting,
|
||||||
|
komentar: item._count.Forum_Komentar,
|
||||||
|
}));
|
||||||
|
|
||||||
|
console.log("fixData >>", fixData);
|
||||||
} else if (category === "report_posting") {
|
} else if (category === "report_posting") {
|
||||||
fixData = await prisma.forum_ReportPosting.findMany({
|
const data = await prisma.forum_ReportPosting.findMany({
|
||||||
take: page ? takeData : undefined,
|
take: page ? takeData : undefined,
|
||||||
skip: page ? skipData : undefined,
|
skip: page ? skipData : undefined,
|
||||||
orderBy: {
|
orderBy: {
|
||||||
@@ -123,8 +138,25 @@ async function GET(request: Request, { params }: { params: { name: string } }) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const filterLatest = (data: any) =>
|
||||||
|
Object.values(
|
||||||
|
data.reduce((acc: any, item: any) => {
|
||||||
|
const key = item.Forum_Posting?.id;
|
||||||
|
if (!key) return acc;
|
||||||
|
if (
|
||||||
|
!acc[key] ||
|
||||||
|
new Date(item.createdAt) > new Date(acc[key].createdAt)
|
||||||
|
) {
|
||||||
|
acc[key] = item;
|
||||||
|
}
|
||||||
|
return acc;
|
||||||
|
}, {})
|
||||||
|
);
|
||||||
|
|
||||||
|
fixData = filterLatest(data);
|
||||||
} else if (category === "report_comment") {
|
} else if (category === "report_comment") {
|
||||||
fixData = await prisma.forum_ReportKomentar.findMany({
|
const data = await prisma.forum_ReportKomentar.findMany({
|
||||||
take: page ? takeData : undefined,
|
take: page ? takeData : undefined,
|
||||||
skip: page ? skipData : undefined,
|
skip: page ? skipData : undefined,
|
||||||
orderBy: {
|
orderBy: {
|
||||||
@@ -160,6 +192,23 @@ async function GET(request: Request, { params }: { params: { name: string } }) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const filterLatest = (data: any) =>
|
||||||
|
Object.values(
|
||||||
|
data.reduce((acc: any, item: any) => {
|
||||||
|
const key = item.Forum_Komentar?.id;
|
||||||
|
if (!key) return acc;
|
||||||
|
if (
|
||||||
|
!acc[key] ||
|
||||||
|
new Date(item.createdAt) > new Date(acc[key].createdAt)
|
||||||
|
) {
|
||||||
|
acc[key] = item;
|
||||||
|
}
|
||||||
|
return acc;
|
||||||
|
}, {})
|
||||||
|
);
|
||||||
|
|
||||||
|
fixData = filterLatest(data);
|
||||||
} else {
|
} else {
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{
|
{
|
||||||
@@ -171,7 +220,6 @@ async function GET(request: Request, { params }: { params: { name: string } }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{
|
{
|
||||||
success: true,
|
success: true,
|
||||||
|
|||||||
@@ -4,19 +4,55 @@ import { prisma } from "@/lib";
|
|||||||
export { GET, PUT };
|
export { GET, PUT };
|
||||||
|
|
||||||
async function GET(request: Request, { params }: { params: { id: string } }) {
|
async function GET(request: Request, { params }: { params: { id: string } }) {
|
||||||
|
let fixData;
|
||||||
try {
|
try {
|
||||||
const { id } = params;
|
const { id } = params;
|
||||||
const data = await prisma.masterBidangBisnis.findUnique({
|
const { searchParams } = new URL(request.url);
|
||||||
where: {
|
const category = searchParams.get("category");
|
||||||
id: id,
|
const subBidangId = searchParams.get("subBidangId");
|
||||||
},
|
|
||||||
});
|
if (category === "all") {
|
||||||
|
const bidang = await prisma.masterBidangBisnis.findUnique({
|
||||||
|
where: {
|
||||||
|
id: id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const subBidang = await prisma.masterSubBidangBisnis.findMany({
|
||||||
|
orderBy: {
|
||||||
|
updatedAt: "desc",
|
||||||
|
},
|
||||||
|
where: {
|
||||||
|
masterBidangBisnisId: id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
fixData = {
|
||||||
|
bidang,
|
||||||
|
subBidang,
|
||||||
|
};
|
||||||
|
} else if (category === "bidang") {
|
||||||
|
const bidang = await prisma.masterBidangBisnis.findUnique({
|
||||||
|
where: {
|
||||||
|
id: id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
fixData = bidang;
|
||||||
|
} else if (category === "sub-bidang") {
|
||||||
|
const subBidang = await prisma.masterSubBidangBisnis.findUnique({
|
||||||
|
where: {
|
||||||
|
id: subBidangId as any,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
fixData = subBidang;
|
||||||
|
}
|
||||||
|
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
status: 200,
|
status: 200,
|
||||||
success: true,
|
success: true,
|
||||||
message: "Berhasil mendapatkan data",
|
message: "Berhasil mendapatkan data",
|
||||||
data: data,
|
data: fixData,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error Get Master Bank >>", error);
|
console.error("Error Get Master Bank >>", error);
|
||||||
@@ -32,17 +68,34 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
|||||||
async function PUT(request: Request, { params }: { params: { id: string } }) {
|
async function PUT(request: Request, { params }: { params: { id: string } }) {
|
||||||
const { id } = params;
|
const { id } = params;
|
||||||
const { data } = await request.json();
|
const { data } = await request.json();
|
||||||
|
const { searchParams } = new URL(request.url);
|
||||||
|
const category = searchParams.get("category");
|
||||||
|
|
||||||
|
console.log("category", category);
|
||||||
|
console.log("data", data);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const updateData = await prisma.masterBidangBisnis.update({
|
if (category === "bidang") {
|
||||||
where: {
|
const updateData = await prisma.masterBidangBisnis.update({
|
||||||
id: id,
|
where: {
|
||||||
},
|
id: id,
|
||||||
data: {
|
},
|
||||||
name: data.name,
|
data: {
|
||||||
active: data.active,
|
name: data.name,
|
||||||
},
|
active: data.active,
|
||||||
});
|
},
|
||||||
|
});
|
||||||
|
} else if (category === "sub-bidang") {
|
||||||
|
const updateData = await prisma.masterSubBidangBisnis.update({
|
||||||
|
where: {
|
||||||
|
id: id,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
name: data.name,
|
||||||
|
isActive: data.isActive,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
status: 200,
|
status: 200,
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
import { prisma } from "@/lib";
|
import { prisma } from "@/lib";
|
||||||
|
import _ from "lodash";
|
||||||
|
import { Prisma } from "@prisma/client";
|
||||||
|
|
||||||
export { GET, POST };
|
export { GET, POST };
|
||||||
|
|
||||||
@@ -31,35 +33,191 @@ async function GET(request: Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type BidangInput = {
|
||||||
|
name: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
type SubBidangInput = {
|
||||||
|
name: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
type RequestBody = {
|
||||||
|
data: {
|
||||||
|
bidang: BidangInput;
|
||||||
|
subBidang: SubBidangInput[];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
/* ---------------------------
|
||||||
|
POST handler
|
||||||
|
- body: { bidang: { name }, subBidang: [{ name }, ...] }
|
||||||
|
- buat masterBidangBisnis (id incremental dari count + 1)
|
||||||
|
- generate id untuk tiap subBidang, cek unik, dan createMany via transaction
|
||||||
|
--------------------------- */
|
||||||
async function POST(request: Request) {
|
async function POST(request: Request) {
|
||||||
const { data } = await request.json();
|
|
||||||
try {
|
try {
|
||||||
const count = await prisma.masterBidangBisnis.count();
|
const { data } = (await request.json()) as RequestBody;
|
||||||
const createNewId = count + 1;
|
|
||||||
|
|
||||||
const slugName = data.name.toLowerCase().replace(/\s+/g, "_");
|
console.log("body >>", data.bidang.name);
|
||||||
|
|
||||||
const create = await prisma.masterBidangBisnis.create({
|
if (!data.bidang.name || !Array.isArray(data.subBidang)) {
|
||||||
data: {
|
return NextResponse.json(
|
||||||
id: createNewId.toString(),
|
{
|
||||||
name: data.name,
|
status: 400,
|
||||||
slug: slugName,
|
success: false,
|
||||||
},
|
message:
|
||||||
|
"Invalid payload. Expect { bidang: { name }, subBidang: [] }",
|
||||||
|
},
|
||||||
|
{ status: 400 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// run in transaction to avoid race conditions
|
||||||
|
const result = await prisma.$transaction(async (tx) => {
|
||||||
|
// ambil last id numerik dengan cast (Postgres)
|
||||||
|
const rows = await tx.$queryRaw<{ id: string }[]>`
|
||||||
|
SELECT id FROM "MasterBidangBisnis" ORDER BY (id::int) DESC LIMIT 1;
|
||||||
|
`;
|
||||||
|
const lastId = rows[0]?.id ?? null;
|
||||||
|
const bidangId = lastId ? String(Number(lastId) + 1) : "1";
|
||||||
|
console.log("bidangId >>", bidangId);
|
||||||
|
|
||||||
|
const slugName = data.bidang.name.toLowerCase().replace(/\s+/g, "_");
|
||||||
|
|
||||||
|
const createdBidang = await tx.masterBidangBisnis.create({
|
||||||
|
data: {
|
||||||
|
id: bidangId,
|
||||||
|
name: data.bidang.name,
|
||||||
|
slug: slugName,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// 2) hitung existing sub bidang untuk bidang ini
|
||||||
|
const existingSubCount = await tx.masterSubBidangBisnis.count({
|
||||||
|
where: { masterBidangBisnisId: createdBidang.id },
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log("existingSubCount >>", existingSubCount);
|
||||||
|
|
||||||
|
// 3) generate unique ids satu-per-satu (cek ke DB via tx)
|
||||||
|
const subBidangToCreate: {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
masterBidangBisnisId: string;
|
||||||
|
}[] = [];
|
||||||
|
|
||||||
|
for (let i = 0; i < data.subBidang.length; i++) {
|
||||||
|
const seqNumber = existingSubCount + i + 1; // 1-based
|
||||||
|
const uniqueId = await generateUniqueSubBidangId(
|
||||||
|
data.bidang.name,
|
||||||
|
seqNumber,
|
||||||
|
tx
|
||||||
|
);
|
||||||
|
|
||||||
|
// push object to array
|
||||||
|
subBidangToCreate.push({
|
||||||
|
id: uniqueId,
|
||||||
|
name: data.subBidang[i].name,
|
||||||
|
masterBidangBisnisId: createdBidang.id,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4) createMany (batched) -- note: createMany doesn't return created rows
|
||||||
|
if (subBidangToCreate.length > 0) {
|
||||||
|
await tx.masterSubBidangBisnis.createMany({
|
||||||
|
data: subBidangToCreate,
|
||||||
|
skipDuplicates: false, // kita sudah memastikan unik, so false
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return { createdBidang, subBidang: subBidangToCreate };
|
||||||
});
|
});
|
||||||
|
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
status: 200,
|
status: 200,
|
||||||
success: true,
|
success: true,
|
||||||
message: "Berhasil menambahkan data",
|
message: "Berhasil menambahkan bidang dan sub bidang",
|
||||||
data: create,
|
data: result,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error Post Master Business Field >>", error);
|
console.error("Error Post Master Business Field >>", error);
|
||||||
return NextResponse.json({
|
const msg = error instanceof Error ? error.message : String(error);
|
||||||
status: 500,
|
return NextResponse.json(
|
||||||
success: false,
|
{
|
||||||
message: "API Error Post Data",
|
status: 500,
|
||||||
reason: (error as Error).message,
|
success: false,
|
||||||
});
|
message: "API Error Post Data",
|
||||||
|
reason: msg,
|
||||||
|
},
|
||||||
|
{ status: 500 }
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ---------------------------
|
||||||
|
Helper: generate base code
|
||||||
|
- mengabaikan stop words: 'dan', 'atau', '&'
|
||||||
|
- ambil dua kata pertama yang tersisa
|
||||||
|
- ambil 3 huruf pertama tiap kata (jika ada)
|
||||||
|
--------------------------- */
|
||||||
|
function generateBaseCode(name: string) {
|
||||||
|
const stopWords = new Set(["dan", "atau", "&"]);
|
||||||
|
// keep only letters and spaces, normalize spaces
|
||||||
|
const cleaned = name
|
||||||
|
.normalize("NFD")
|
||||||
|
.replace(/[\u0300-\u036f]/g, "") // remove diacritics
|
||||||
|
.replace(/[^a-zA-Z\s&]/g, " ")
|
||||||
|
.replace(/\s+/g, " ")
|
||||||
|
.trim()
|
||||||
|
.toLowerCase();
|
||||||
|
|
||||||
|
const words = cleaned
|
||||||
|
.split(" ")
|
||||||
|
.filter((w) => w.length > 0 && !stopWords.has(w));
|
||||||
|
|
||||||
|
const primary = (words[0] ?? "xxx").substring(0, 3).toUpperCase();
|
||||||
|
const secondary = words[1] ? words[1].substring(0, 3).toUpperCase() : "";
|
||||||
|
|
||||||
|
return { primary, secondary };
|
||||||
|
}
|
||||||
|
|
||||||
|
function padNumber(n: number) {
|
||||||
|
return String(n).padStart(2, "0");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------------------------
|
||||||
|
generateUniqueSubBidangId
|
||||||
|
- cek urutan strategi:
|
||||||
|
1) PRIMARY-<NN>
|
||||||
|
2) PRIMARY-SECONDARY-<NN> (jika secondary ada)
|
||||||
|
3) PRIMARYSECONDARY-<NN> (jika secondary ada)
|
||||||
|
4) fallback: PRIMARY + last4Timestamp -<NN>
|
||||||
|
- menggunakan tx (Prisma.TransactionClient) untuk cek di DB
|
||||||
|
--------------------------- */
|
||||||
|
async function generateUniqueSubBidangId(
|
||||||
|
bidangName: string,
|
||||||
|
number: number,
|
||||||
|
tx: Prisma.TransactionClient
|
||||||
|
): Promise<string> {
|
||||||
|
const { primary, secondary } = generateBaseCode(bidangName);
|
||||||
|
const num = padNumber(number);
|
||||||
|
|
||||||
|
const candidates: string[] = [];
|
||||||
|
candidates.push(`${primary}-${num}`);
|
||||||
|
if (secondary) candidates.push(`${primary}-${secondary}-${num}`);
|
||||||
|
if (secondary) candidates.push(`${primary}${secondary}-${num}`);
|
||||||
|
// final fallback
|
||||||
|
candidates.push(`${primary}${String(Date.now()).slice(-4)}-${num}`);
|
||||||
|
|
||||||
|
for (const id of candidates) {
|
||||||
|
// findUnique requires unique field; assuming `id` is the PK/unique
|
||||||
|
const found = await tx.masterSubBidangBisnis.findUnique({
|
||||||
|
where: { id },
|
||||||
|
select: { id: true },
|
||||||
|
});
|
||||||
|
if (!found) return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
// theoretically unreachable, but return a final deterministic fallback
|
||||||
|
return `${primary}-${String(Math.floor(Math.random() * 9000) + 1000)}-${num}`;
|
||||||
|
}
|
||||||
|
|||||||
69
src/app/api/mobile/admin/master/donation/[id]/route.ts
Normal file
69
src/app/api/mobile/admin/master/donation/[id]/route.ts
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
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;
|
||||||
|
let fixData;
|
||||||
|
|
||||||
|
try {
|
||||||
|
fixData = await prisma.donasiMaster_Kategori.findUnique({
|
||||||
|
where: {
|
||||||
|
id: id,
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
name: true,
|
||||||
|
active: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return NextResponse.json({
|
||||||
|
success: true,
|
||||||
|
message: "Master berhasil diambil",
|
||||||
|
data: fixData,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.log("[ERROR]", error);
|
||||||
|
return NextResponse.json({
|
||||||
|
success: false,
|
||||||
|
error: "Gagal mengambil data master",
|
||||||
|
reason: (error as Error).message,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function PUT(request: Request, { params }: { params: { id: string } }) {
|
||||||
|
const { id } = params;
|
||||||
|
const { data } = await request.json();
|
||||||
|
|
||||||
|
console.log("id", id);
|
||||||
|
console.log("data", data);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const updateData = await prisma.donasiMaster_Kategori.update({
|
||||||
|
where: {
|
||||||
|
id: id,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
name: data.name,
|
||||||
|
active: data.active,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return NextResponse.json({
|
||||||
|
success: true,
|
||||||
|
message: "Master berhasil diupdate",
|
||||||
|
data: updateData,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.log("[ERROR]", error);
|
||||||
|
return NextResponse.json({
|
||||||
|
success: false,
|
||||||
|
error: "Gagal mengupdate data master",
|
||||||
|
reason: (error as Error).message,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
105
src/app/api/mobile/admin/master/donation/route.ts
Normal file
105
src/app/api/mobile/admin/master/donation/route.ts
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import prisma from "@/lib/prisma";
|
||||||
|
|
||||||
|
export { GET, POST };
|
||||||
|
|
||||||
|
async function GET(request: Request) {
|
||||||
|
const { searchParams } = new URL(request.url);
|
||||||
|
// const category = searchParams.get("category");
|
||||||
|
let fixData;
|
||||||
|
|
||||||
|
try {
|
||||||
|
fixData = await prisma.donasiMaster_Kategori.findMany({
|
||||||
|
orderBy: {
|
||||||
|
createdAt: "asc",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// if (category === "category") {
|
||||||
|
// fixData = await prisma.donasiMaster_Kategori.findMany({
|
||||||
|
// orderBy: {
|
||||||
|
// createdAt: "asc",
|
||||||
|
// },
|
||||||
|
// where: {
|
||||||
|
// active: true,
|
||||||
|
// },
|
||||||
|
// });
|
||||||
|
// } else if (category === "duration") {
|
||||||
|
// fixData = await prisma.donasiMaster_Durasi.findMany({
|
||||||
|
// orderBy: {
|
||||||
|
// createdAt: "asc",
|
||||||
|
// },
|
||||||
|
// where: {
|
||||||
|
// active: true,
|
||||||
|
// },
|
||||||
|
// });
|
||||||
|
// } else {
|
||||||
|
// const category = await prisma.donasiMaster_Kategori.findMany({
|
||||||
|
// orderBy: {
|
||||||
|
// createdAt: "asc",
|
||||||
|
// },
|
||||||
|
// where: {
|
||||||
|
// active: true,
|
||||||
|
// },
|
||||||
|
// });
|
||||||
|
|
||||||
|
// const duration = await prisma.donasiMaster_Durasi.findMany({
|
||||||
|
// orderBy: {
|
||||||
|
// createdAt: "asc",
|
||||||
|
// },
|
||||||
|
// where: {
|
||||||
|
// active: true,
|
||||||
|
// },
|
||||||
|
// });
|
||||||
|
|
||||||
|
// fixData = {
|
||||||
|
// category: category,
|
||||||
|
// duration: duration,
|
||||||
|
// };
|
||||||
|
// }
|
||||||
|
|
||||||
|
return NextResponse.json({
|
||||||
|
success: true,
|
||||||
|
message: "Master berhasil diambil",
|
||||||
|
data: fixData,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.log("[ERROR]", error);
|
||||||
|
return NextResponse.json({
|
||||||
|
success: false,
|
||||||
|
error: "Gagal mengambil data master",
|
||||||
|
reason: (error as Error).message,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function POST(request: Request) {
|
||||||
|
const { data } = await request.json();
|
||||||
|
|
||||||
|
console.log("data", data);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const count = await prisma.donasiMaster_Kategori.count();
|
||||||
|
const createNewId = count + 1;
|
||||||
|
|
||||||
|
const createData = await prisma.donasiMaster_Kategori.create({
|
||||||
|
data: {
|
||||||
|
id: createNewId.toString(),
|
||||||
|
name: data.name,
|
||||||
|
active: data.active,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return NextResponse.json({
|
||||||
|
success: true,
|
||||||
|
message: "Master berhasil ditambahkan",
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.log("[ERROR]", error);
|
||||||
|
return NextResponse.json({
|
||||||
|
success: false,
|
||||||
|
error: "Gagal menambah data master",
|
||||||
|
reason: (error as Error).message,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -113,6 +113,7 @@ async function GET(request: Request) {
|
|||||||
Author: {
|
Author: {
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
|
username: true,
|
||||||
Profile: true,
|
Profile: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -141,6 +142,7 @@ async function GET(request: Request) {
|
|||||||
Author: {
|
Author: {
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
|
username: true,
|
||||||
Profile: true,
|
Profile: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -11,6 +11,24 @@ async function POST(request: Request, { params }: { params: { id: string } }) {
|
|||||||
console.log("[ID]", id);
|
console.log("[ID]", id);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const content = await prisma.forum_Komentar.findUnique({
|
||||||
|
where: {
|
||||||
|
id: id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const reportList = await prisma.forumMaster_KategoriReport.findUnique({
|
||||||
|
where: {
|
||||||
|
id: data.categoryId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const msg = `Report Komentar: "${content?.komentar}" dengan kategori \n\n\n${reportList?.title} : \n\n${reportList?.deskripsi}`;
|
||||||
|
const res = await fetch(
|
||||||
|
`https://cld-dkr-prod-wajs-server.wibudev.com/api/wa/code?nom=6282340374412&text=${msg}`,
|
||||||
|
{ cache: "no-cache" }
|
||||||
|
);
|
||||||
|
|
||||||
if (data.categoryId) {
|
if (data.categoryId) {
|
||||||
fixData = await prisma.forum_ReportKomentar.create({
|
fixData = await prisma.forum_ReportKomentar.create({
|
||||||
data: {
|
data: {
|
||||||
|
|||||||
@@ -11,6 +11,18 @@ async function POST(request: Request, { params }: { params: { id: string } }) {
|
|||||||
console.log("[ID]", id);
|
console.log("[ID]", id);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const content = await prisma.forum_Posting.findUnique({
|
||||||
|
where: {
|
||||||
|
id: id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const msg = `Report Postingan: "${content?.diskusi}"`;
|
||||||
|
const res = await fetch(
|
||||||
|
`https://cld-dkr-prod-wajs-server.wibudev.com/api/wa/code?nom=6282340374412&text=${msg}`,
|
||||||
|
{ cache: "no-cache" }
|
||||||
|
);
|
||||||
|
|
||||||
if (data.categoryId) {
|
if (data.categoryId) {
|
||||||
fixData = await prisma.forum_ReportPosting.create({
|
fixData = await prisma.forum_ReportPosting.create({
|
||||||
data: {
|
data: {
|
||||||
|
|||||||
@@ -24,18 +24,18 @@ async function POST(request: Request, { params }: { params: { id: string } }) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
fixData = createWithFile;
|
fixData = createWithFile;
|
||||||
|
} else {
|
||||||
|
const createWitOutFile = await prisma.beritaInvestasi.create({
|
||||||
|
data: {
|
||||||
|
investasiId: id,
|
||||||
|
title: _.startCase(data.title),
|
||||||
|
deskripsi: data.deskripsi,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
fixData = createWitOutFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
const createWitOutFile = await prisma.beritaInvestasi.create({
|
|
||||||
data: {
|
|
||||||
investasiId: id,
|
|
||||||
title: _.startCase(data.title),
|
|
||||||
deskripsi: data.deskripsi,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
fixData = createWitOutFile;
|
|
||||||
|
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
status: 201,
|
status: 201,
|
||||||
success: true,
|
success: true,
|
||||||
|
|||||||
68
src/app/api/mobile/user/[id]/terms-of-app/route.ts
Normal file
68
src/app/api/mobile/user/[id]/terms-of-app/route.ts
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import { prisma } from "@/lib";
|
||||||
|
|
||||||
|
export { POST };
|
||||||
|
|
||||||
|
async function POST(request: Request, { params }: { params: { id: string } }) {
|
||||||
|
const { id } = params;
|
||||||
|
const { searchParams } = new URL(request.url);
|
||||||
|
const category = searchParams.get("category");
|
||||||
|
|
||||||
|
console.log("[ID USER", id);
|
||||||
|
console.log("[SEARCH PARAMS", category);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const user = await prisma.user.findUnique({
|
||||||
|
where: {
|
||||||
|
id: id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!user) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{
|
||||||
|
success: false,
|
||||||
|
message: "User not found",
|
||||||
|
},
|
||||||
|
{ status: 404 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const updateUser = await prisma.user.update({
|
||||||
|
where: {
|
||||||
|
id: id,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
acceptedForumTermsAt: new Date(),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!updateUser) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{
|
||||||
|
success: false,
|
||||||
|
message: "Gagal mengupdate data",
|
||||||
|
},
|
||||||
|
{ status: 400 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return NextResponse.json(
|
||||||
|
{
|
||||||
|
success: true,
|
||||||
|
message: "Syarat dan Ketentuan berhasil diterima",
|
||||||
|
},
|
||||||
|
{ status: 200 }
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{
|
||||||
|
success: false,
|
||||||
|
message: "Error update data from API ",
|
||||||
|
reason: (error as Error).message,
|
||||||
|
},
|
||||||
|
{ status: 500 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -123,6 +123,10 @@ async function GET(request: Request) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
fixData = data;
|
||||||
|
|
||||||
|
|
||||||
} else if (category === "contribution") {
|
} else if (category === "contribution") {
|
||||||
const data = await prisma.voting_Kontributor.findMany({
|
const data = await prisma.voting_Kontributor.findMany({
|
||||||
orderBy: {
|
orderBy: {
|
||||||
|
|||||||
@@ -23,6 +23,6 @@
|
|||||||
"@/*": ["./src/*"]
|
"@/*": ["./src/*"]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts", "src/app_modules/investasi/proses_transaksi/view.jsx", "src/app/api/investasi/midtrans/[id]/route.ts", "src/app_modules/job/create/TextEdit.tsx"],
|
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts", "src/app_modules/investasi/proses_transaksi/view.jsx", "src/app/api/investasi/midtrans/[id]/route.ts", "src/app_modules/job/create/TextEdit.tsx", "src/app/api/mobile/forum/[id]/report-comment/route.ts"],
|
||||||
"exclude": ["node_modules"]
|
"exclude": ["node_modules"]
|
||||||
}
|
}
|
||||||
|
|||||||
4
types/env.d.ts
vendored
4
types/env.d.ts
vendored
@@ -9,7 +9,7 @@ declare namespace NodeJS {
|
|||||||
NEXT_PUBLIC_WIBU_REALTIME_TOKEN?: string;
|
NEXT_PUBLIC_WIBU_REALTIME_TOKEN?: string;
|
||||||
NEXT_PUBLIC_BASE_TOKEN_KEY?: string;
|
NEXT_PUBLIC_BASE_TOKEN_KEY?: string;
|
||||||
NEXT_PUBLIC_BASE_SESSION_KEY?: string;
|
NEXT_PUBLIC_BASE_SESSION_KEY?: string;
|
||||||
NEXT_PUBLIC_API_URL?: string;
|
RESEND_APIKEY?: string;
|
||||||
|
WA_SERVER_TOKEN?: string;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user