upd: api ai
Deskripsi : - update banner api ai No Issues
This commit is contained in:
21
src/app/api/ai/banner/[id]/route.ts
Normal file
21
src/app/api/ai/banner/[id]/route.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import { prisma } from "@/module/_global";
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
|
||||||
|
|
||||||
|
// GET ONE BANNER
|
||||||
|
export async function GET(request: Request, context: { params: { id: string } }) {
|
||||||
|
try {
|
||||||
|
const { id } = context.params;
|
||||||
|
|
||||||
|
const data = await prisma.bannerImage.findUnique({
|
||||||
|
where: {
|
||||||
|
id: String(id)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return NextResponse.json({ success: true, message: "Berhasil mendapatkan banner", data }, { status: 200 });
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
return NextResponse.json({ success: false, message: "Gagal mendapatkan banner, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 });
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import { prisma } from "@/module/_global";
|
import { prisma } from "@/module/_global";
|
||||||
|
import _ from "lodash";
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
|
|
||||||
|
|
||||||
@@ -6,15 +7,24 @@ import { NextResponse } from "next/server";
|
|||||||
export async function GET(request: Request) {
|
export async function GET(request: Request) {
|
||||||
try {
|
try {
|
||||||
const { searchParams } = new URL(request.url);
|
const { searchParams } = new URL(request.url);
|
||||||
const judul = searchParams.get('q');
|
const judul = searchParams.get('search');
|
||||||
const page = searchParams.get('p');
|
const page = searchParams.get('page');
|
||||||
const get = searchParams.get('get');
|
const get = searchParams.get('get');
|
||||||
const villageId = searchParams.get('desa');
|
const villageId = searchParams.get('desa');
|
||||||
const dataSkip = page == null || page == undefined ? 0 : Number(page) * 10 - 10;
|
const active = searchParams.get('active');
|
||||||
|
|
||||||
|
let getFix = 0;
|
||||||
|
if (get == null || get == undefined || get == "" || _.isNaN(Number(get))) {
|
||||||
|
getFix = 10;
|
||||||
|
} else {
|
||||||
|
getFix = Number(get);
|
||||||
|
}
|
||||||
|
|
||||||
|
const dataSkip = page == null || page == undefined ? 0 : Number(page) * getFix - getFix;
|
||||||
|
|
||||||
let kondisi: any = {
|
let kondisi: any = {
|
||||||
idVillage: String(villageId),
|
idVillage: String(villageId),
|
||||||
isActive: true,
|
isActive: (active == "false" || active == undefined) ? false : true,
|
||||||
title: {
|
title: {
|
||||||
contains: (judul == undefined || judul == null) ? "" : judul,
|
contains: (judul == undefined || judul == null) ? "" : judul,
|
||||||
mode: "insensitive"
|
mode: "insensitive"
|
||||||
@@ -22,10 +32,9 @@ export async function GET(request: Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const data = await prisma.bannerImage.findMany({
|
const data = await prisma.bannerImage.findMany({
|
||||||
where: {
|
skip: dataSkip,
|
||||||
isActive: true,
|
take: getFix,
|
||||||
idVillage: String(villageId)
|
where: kondisi,
|
||||||
},
|
|
||||||
orderBy: {
|
orderBy: {
|
||||||
createdAt: 'desc'
|
createdAt: 'desc'
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user