Merge pull request #335 from bipproduction/bagas/25-feb-25
fix admin investasi
This commit is contained in:
@@ -1,101 +0,0 @@
|
||||
import backendLogger from "@/util/backendLogger";
|
||||
import _ from "lodash";
|
||||
import { NextResponse } from "next/server";
|
||||
import prisma from "@/lib/prisma";
|
||||
|
||||
export async function GET( request: Request,
|
||||
{ params }: { params: { id: string,} }) {
|
||||
|
||||
let fixData;
|
||||
const { searchParams } = new URL(request.url);
|
||||
const page = searchParams.get("page");
|
||||
const selectStatus = searchParams.get("status");
|
||||
const { id } = params;
|
||||
const investasiId = id;
|
||||
const takeData = 10;
|
||||
const skipData = Number(page) * takeData - takeData;
|
||||
try {
|
||||
|
||||
if (!page) {
|
||||
fixData = await prisma.investasi_Invoice.findMany({
|
||||
orderBy: [
|
||||
{
|
||||
createdAt: "desc",
|
||||
},
|
||||
],
|
||||
where: {
|
||||
investasiId: investasiId,
|
||||
isActive: true,
|
||||
statusInvoiceId: {
|
||||
contains: selectStatus ? selectStatus : "",
|
||||
mode: "insensitive",
|
||||
},
|
||||
},
|
||||
include: {
|
||||
Author: true,
|
||||
Images: true,
|
||||
StatusInvoice: true,
|
||||
MasterBank: true,
|
||||
},
|
||||
});
|
||||
|
||||
} else {
|
||||
const data = await prisma.investasi_Invoice.findMany({
|
||||
take: takeData,
|
||||
skip: skipData,
|
||||
orderBy: [
|
||||
{
|
||||
createdAt: "desc",
|
||||
},
|
||||
],
|
||||
where: {
|
||||
investasiId: investasiId,
|
||||
isActive: true,
|
||||
statusInvoiceId: {
|
||||
contains: selectStatus ? selectStatus : "",
|
||||
mode: "insensitive",
|
||||
},
|
||||
},
|
||||
include: {
|
||||
Author: true,
|
||||
Images: true,
|
||||
StatusInvoice: true,
|
||||
MasterBank: true,
|
||||
},
|
||||
});
|
||||
|
||||
const nCount = await prisma.investasi_Invoice.count({
|
||||
where: {
|
||||
investasiId: investasiId,
|
||||
isActive: true,
|
||||
statusInvoiceId: {
|
||||
contains: selectStatus ? selectStatus : "",
|
||||
mode: "insensitive",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
fixData = {
|
||||
data: data,
|
||||
nPage: _.ceil(nCount / takeData),
|
||||
}
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: "Success get data all transaksi investasi dashboard",
|
||||
data: fixData,
|
||||
},
|
||||
{ status: 200 }
|
||||
);
|
||||
} catch (error) {
|
||||
backendLogger.error("Error get data all transaksi investasi dashboard >>", error);
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: "Error get data all transaksi investasi dashboard",
|
||||
reason: (error as Error).message
|
||||
},
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -3,103 +3,98 @@ import _ from "lodash";
|
||||
import { NextResponse } from "next/server";
|
||||
import prisma from "@/lib/prisma";
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: { id: string } }
|
||||
) {
|
||||
try {
|
||||
let fixData;
|
||||
const { id } = params;
|
||||
const { searchParams } = new URL(request.url);
|
||||
const page = searchParams.get("page");
|
||||
const status = searchParams.get("status");
|
||||
const takeData = 10
|
||||
const skipData = Number(page) * takeData - takeData;
|
||||
|
||||
export async function GET(request: Request, { params }: { params: { id: string } }) {
|
||||
try {
|
||||
let fixData
|
||||
const { id } = params;
|
||||
const { searchParams } = new URL(request.url);
|
||||
const page = searchParams.get("page");
|
||||
const status = searchParams.get("status");
|
||||
const takeData = 10;
|
||||
const skipData = Number(page) * takeData - takeData;
|
||||
|
||||
if (!page) {
|
||||
|
||||
fixData = await prisma.investasi_Invoice.findMany({
|
||||
orderBy: [
|
||||
{
|
||||
createdAt: "desc",
|
||||
},
|
||||
],
|
||||
where: {
|
||||
investasiId: id,
|
||||
isActive: true,
|
||||
},
|
||||
include: {
|
||||
Author: true,
|
||||
Images: true,
|
||||
StatusInvoice: true,
|
||||
MasterBank: true,
|
||||
},
|
||||
});
|
||||
|
||||
} else {
|
||||
const data = await prisma.investasi_Invoice.findMany({
|
||||
take: takeData,
|
||||
skip: skipData,
|
||||
orderBy: [
|
||||
{
|
||||
createdAt: "desc",
|
||||
},
|
||||
],
|
||||
where: {
|
||||
investasiId: id,
|
||||
isActive: true,
|
||||
StatusInvoice: {
|
||||
name: {
|
||||
contains: status ? status : "",
|
||||
mode: "insensitive",
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
include: {
|
||||
Author: true,
|
||||
Images: true,
|
||||
StatusInvoice: true,
|
||||
MasterBank: true,
|
||||
},
|
||||
});
|
||||
|
||||
const nCount = await prisma.investasi_Invoice.count({
|
||||
where: {
|
||||
investasiId: id,
|
||||
isActive: true,
|
||||
StatusInvoice: {
|
||||
name: {
|
||||
contains: status ? status : "",
|
||||
mode: "insensitive",
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
});
|
||||
|
||||
fixData = {
|
||||
data: data,
|
||||
nPage: _.ceil(nCount / takeData),
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: "Success get status transaksi",
|
||||
data: fixData
|
||||
if (!page) {
|
||||
fixData = await prisma.investasi_Invoice.findMany({
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
},
|
||||
{ status: 200 }
|
||||
)
|
||||
} catch (error) {
|
||||
backendLogger.error("Eror get status transaksi", error);
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: "Error get status transaksi",
|
||||
reason: (error as Error).message
|
||||
where: {
|
||||
investasiId: id,
|
||||
isActive: true,
|
||||
},
|
||||
{ status: 500 }
|
||||
)
|
||||
include: {
|
||||
Author: true,
|
||||
Images: true,
|
||||
StatusInvoice: true,
|
||||
MasterBank: true,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
const fixStatus = _.startCase(status ? status : "");
|
||||
|
||||
const data = await prisma.investasi_Invoice.findMany({
|
||||
take: takeData,
|
||||
skip: skipData,
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
},
|
||||
where: {
|
||||
investasiId: id,
|
||||
isActive: true,
|
||||
StatusInvoice: {
|
||||
name: {
|
||||
contains: fixStatus,
|
||||
mode: "insensitive",
|
||||
},
|
||||
},
|
||||
},
|
||||
include: {
|
||||
Author: true,
|
||||
Images: true,
|
||||
StatusInvoice: true,
|
||||
MasterBank: true,
|
||||
},
|
||||
});
|
||||
|
||||
const nCount = await prisma.investasi_Invoice.count({
|
||||
where: {
|
||||
investasiId: id,
|
||||
isActive: true,
|
||||
StatusInvoice: {
|
||||
name: {
|
||||
contains: fixStatus,
|
||||
mode: "insensitive",
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
fixData = {
|
||||
data: data,
|
||||
nPage: _.ceil(nCount / takeData),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: true,
|
||||
message: "Success get status transaksi",
|
||||
data: fixData,
|
||||
},
|
||||
{ status: 200 }
|
||||
);
|
||||
} catch (error) {
|
||||
backendLogger.error("Eror get status transaksi", error);
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Error get status transaksi",
|
||||
reason: (error as Error).message,
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,133 +2,137 @@ import { prisma } from "@/lib";
|
||||
import _ from "lodash";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export async function GET(request: Request, { params }: {
|
||||
params: { name: string }
|
||||
}
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{
|
||||
params,
|
||||
}: {
|
||||
params: { name: string };
|
||||
}
|
||||
) {
|
||||
const method = request.method;
|
||||
if (method !== "GET") {
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: "Method not allowed",
|
||||
const method = request.method;
|
||||
if (method !== "GET") {
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Method not allowed",
|
||||
},
|
||||
{ status: 405 }
|
||||
);
|
||||
}
|
||||
|
||||
const { name } = 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;
|
||||
|
||||
try {
|
||||
let fixData;
|
||||
const fixStatus = _.startCase(name);
|
||||
|
||||
if (!page) {
|
||||
fixData = await prisma.investasi.findMany({
|
||||
orderBy: {
|
||||
updatedAt: "desc",
|
||||
},
|
||||
{ status: 405 }
|
||||
)
|
||||
where: {
|
||||
active: true,
|
||||
MasterStatusInvestasi: {
|
||||
name: fixStatus,
|
||||
},
|
||||
title: {
|
||||
contains: search ? search : "",
|
||||
mode: "insensitive",
|
||||
},
|
||||
},
|
||||
include: {
|
||||
MasterStatusInvestasi: true,
|
||||
BeritaInvestasi: true,
|
||||
DokumenInvestasi: true,
|
||||
ProspektusInvestasi: true,
|
||||
MasterPembagianDeviden: true,
|
||||
MasterPencarianInvestor: true,
|
||||
MasterPeriodeDeviden: true,
|
||||
author: true,
|
||||
Investasi_Invoice: {
|
||||
where: {
|
||||
statusInvoiceId: "2",
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
} else {
|
||||
const data = await prisma.investasi.findMany({
|
||||
take: takeData,
|
||||
skip: skipData,
|
||||
orderBy: {
|
||||
updatedAt: "desc",
|
||||
},
|
||||
where: {
|
||||
active: true,
|
||||
MasterStatusInvestasi: {
|
||||
name: fixStatus,
|
||||
},
|
||||
title: {
|
||||
contains: search ? search : "",
|
||||
mode: "insensitive",
|
||||
},
|
||||
},
|
||||
include: {
|
||||
MasterStatusInvestasi: true,
|
||||
BeritaInvestasi: true,
|
||||
DokumenInvestasi: true,
|
||||
ProspektusInvestasi: true,
|
||||
MasterPembagianDeviden: true,
|
||||
MasterPencarianInvestor: true,
|
||||
MasterPeriodeDeviden: true,
|
||||
author: true,
|
||||
Investasi_Invoice: {
|
||||
where: {
|
||||
statusInvoiceId: "2",
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const nCount = await prisma.investasi.count({
|
||||
where: {
|
||||
active: true,
|
||||
MasterStatusInvestasi: {
|
||||
name: fixStatus,
|
||||
},
|
||||
title: {
|
||||
contains: search ? search : "",
|
||||
mode: "insensitive",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
fixData = {
|
||||
data: data,
|
||||
nPage: _.ceil(nCount / takeData),
|
||||
};
|
||||
}
|
||||
|
||||
const { name } = 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;
|
||||
|
||||
try {
|
||||
let fixData;
|
||||
const fixStatus = _.startCase(name);
|
||||
|
||||
|
||||
if (!page) {
|
||||
fixData = await prisma.investasi.findMany({
|
||||
orderBy: {
|
||||
updatedAt: "desc",
|
||||
},
|
||||
where: {
|
||||
active: true,
|
||||
MasterStatusInvestasi: {
|
||||
name: fixStatus
|
||||
},
|
||||
title: {
|
||||
contains: search ? search : "",
|
||||
mode: "insensitive"
|
||||
}
|
||||
},
|
||||
include: {
|
||||
MasterStatusInvestasi: true,
|
||||
BeritaInvestasi: true,
|
||||
DokumenInvestasi: true,
|
||||
ProspektusInvestasi: true,
|
||||
MasterPembagianDeviden: true,
|
||||
MasterPencarianInvestor: true,
|
||||
MasterPeriodeDeviden: true,
|
||||
author: true,
|
||||
Investasi_Invoice: {
|
||||
where: {
|
||||
statusInvoiceId: "2",
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
} else {
|
||||
const data = await prisma.investasi.findMany({
|
||||
take: takeData,
|
||||
skip: skipData,
|
||||
orderBy: {
|
||||
updatedAt: "desc",
|
||||
},
|
||||
where: {
|
||||
active: true,
|
||||
MasterStatusInvestasi: {
|
||||
name: fixStatus
|
||||
},
|
||||
title: {
|
||||
contains: search ? search : "",
|
||||
mode: "insensitive"
|
||||
}
|
||||
},
|
||||
include: {
|
||||
MasterStatusInvestasi: true,
|
||||
BeritaInvestasi: true,
|
||||
DokumenInvestasi: true,
|
||||
ProspektusInvestasi: true,
|
||||
MasterPembagianDeviden: true,
|
||||
MasterPencarianInvestor: true,
|
||||
MasterPeriodeDeviden: true,
|
||||
author: true,
|
||||
Investasi_Invoice: {
|
||||
where: {
|
||||
statusInvoiceId: "2",
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const nCount = await prisma.investasi.count({
|
||||
where: {
|
||||
active: true,
|
||||
MasterStatusInvestasi: {
|
||||
name: fixStatus
|
||||
}
|
||||
|
||||
},
|
||||
});
|
||||
|
||||
fixData = {
|
||||
data: data,
|
||||
nPage: _.ceil(nCount / takeData),
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: "Success",
|
||||
data: fixData,
|
||||
},
|
||||
{ status: 200 }
|
||||
)
|
||||
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: "Failed",
|
||||
reason: (error as Error).message,
|
||||
},
|
||||
{ status: 500 }
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: true,
|
||||
message: "Success",
|
||||
data: fixData,
|
||||
},
|
||||
{ status: 200 }
|
||||
);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Failed",
|
||||
reason: (error as Error).message,
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ export async function GET(request: Request) {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const search = searchParams.get("search");
|
||||
const page = searchParams.get("page");
|
||||
const takeData = 2;
|
||||
const takeData = 10;
|
||||
const skipData = Number(page) * takeData - takeData;
|
||||
|
||||
if (!page) {
|
||||
|
||||
Reference in New Issue
Block a user