Fix: Event
Deskripsi: - Fix database event - Fix style detal
This commit is contained in:
@@ -3,15 +3,17 @@
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { MODEL_EVENT } from "../../model/interface";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import _ from "lodash";
|
||||
|
||||
export async function Event_funCreate(req: MODEL_EVENT) {
|
||||
const res = await prisma.event.create({
|
||||
data: {
|
||||
title: req.title,
|
||||
title: _.startCase(req.title),
|
||||
lokasi: req.lokasi,
|
||||
deskripsi: req.deskripsi,
|
||||
eventMaster_TipeAcaraId: req.eventMaster_TipeAcaraId,
|
||||
tanggal: req.tanggal,
|
||||
tanggalSelesai: req.tanggalSelesai,
|
||||
authorId: req.authorId,
|
||||
},
|
||||
select: {
|
||||
@@ -20,10 +22,10 @@ export async function Event_funCreate(req: MODEL_EVENT) {
|
||||
EventMaster_Status: {
|
||||
select: {
|
||||
name: true,
|
||||
}
|
||||
},
|
||||
},
|
||||
authorId: true,
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
if (!res) return { status: 400, message: "Gagal Disimpan" };
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { MODEL_EVENT } from "../../model/interface";
|
||||
import _ from "lodash";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { RouterEvent } from "@/app/lib/router_hipmi/router_event";
|
||||
import { MODEL_EVENT } from "../../model/interface";
|
||||
|
||||
export async function Event_funEditById(data: MODEL_EVENT) {
|
||||
const updt = await prisma.event.update({
|
||||
@@ -11,10 +11,11 @@ export async function Event_funEditById(data: MODEL_EVENT) {
|
||||
id: data.id,
|
||||
},
|
||||
data: {
|
||||
title: data.title,
|
||||
title: _.startCase(data.title),
|
||||
lokasi: data.lokasi,
|
||||
deskripsi: data.deskripsi,
|
||||
tanggal: data.tanggal,
|
||||
tanggalSelesai: data.tanggalSelesai,
|
||||
eventMaster_TipeAcaraId: data.EventMaster_TipeAcara.id as any,
|
||||
},
|
||||
});
|
||||
|
||||
14
src/app_modules/event/fun/get/fun_check_status_by_id.ts
Normal file
14
src/app_modules/event/fun/get/fun_check_status_by_id.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
"use server";
|
||||
|
||||
import { prisma } from "@/app/lib";
|
||||
|
||||
export async function event_checkStatus({ id }: { id: string }) {
|
||||
const checkStatus = await prisma.event.findFirst({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
});
|
||||
|
||||
if (checkStatus?.eventMaster_StatusId == "2") return true;
|
||||
return false;
|
||||
}
|
||||
@@ -2,14 +2,42 @@
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import _ from "lodash";
|
||||
import moment from "moment";
|
||||
|
||||
export async function event_getListAllPublish({ page }: { page: number }) {
|
||||
const allData = await prisma.event.findMany({
|
||||
where: {
|
||||
active: true,
|
||||
eventMaster_StatusId: "1",
|
||||
isArsip: false,
|
||||
},
|
||||
});
|
||||
|
||||
for (let i of allData) {
|
||||
if (moment(i.tanggalSelesai).diff(moment(), "minutes") < 0) {
|
||||
const updateArsip = await prisma.event.update({
|
||||
where: {
|
||||
id: i.id,
|
||||
},
|
||||
data: {
|
||||
isArsip: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!updateArsip) {
|
||||
console.log("gagal update arsip");
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const takeData = 10;
|
||||
const skipData = page * takeData - takeData;
|
||||
|
||||
const data = await prisma.event.findMany({
|
||||
take: takeData,
|
||||
skip: skipData,
|
||||
|
||||
orderBy: [
|
||||
{
|
||||
tanggal: "asc",
|
||||
@@ -18,9 +46,7 @@ export async function event_getListAllPublish({ page }: { page: number }) {
|
||||
where: {
|
||||
active: true,
|
||||
eventMaster_StatusId: "1",
|
||||
tanggal: {
|
||||
gte: new Date(),
|
||||
},
|
||||
isArsip: false,
|
||||
},
|
||||
include: {
|
||||
Author: {
|
||||
|
||||
@@ -1,88 +0,0 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
|
||||
export async function Event_getListByStatusId(
|
||||
statusId: string,
|
||||
authorId: string
|
||||
) {
|
||||
if (statusId === "1") {
|
||||
const data = await prisma.event.findMany({
|
||||
orderBy: {
|
||||
tanggal: "desc",
|
||||
},
|
||||
where: {
|
||||
active: true,
|
||||
eventMaster_StatusId: "1",
|
||||
authorId: authorId,
|
||||
tanggal: {
|
||||
gte: new Date(),
|
||||
},
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
deskripsi: true,
|
||||
tanggal: true,
|
||||
},
|
||||
});
|
||||
return data;
|
||||
}
|
||||
if (statusId === "2") {
|
||||
const data = await prisma.event.findMany({
|
||||
orderBy: {
|
||||
updatedAt: "desc",
|
||||
},
|
||||
where: {
|
||||
active: true,
|
||||
eventMaster_StatusId: "2",
|
||||
authorId: authorId,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
deskripsi: true,
|
||||
tanggal: true,
|
||||
},
|
||||
});
|
||||
return data;
|
||||
}
|
||||
if (statusId === "3") {
|
||||
const data = await prisma.event.findMany({
|
||||
orderBy: {
|
||||
updatedAt: "desc",
|
||||
},
|
||||
where: {
|
||||
active: true,
|
||||
eventMaster_StatusId: "3",
|
||||
authorId: authorId,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
deskripsi: true,
|
||||
tanggal: true,
|
||||
},
|
||||
});
|
||||
return data;
|
||||
}
|
||||
if (statusId === "4") {
|
||||
const data = await prisma.event.findMany({
|
||||
orderBy: {
|
||||
updatedAt: "desc",
|
||||
},
|
||||
where: {
|
||||
active: true,
|
||||
eventMaster_StatusId: "4",
|
||||
authorId: authorId,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
deskripsi: true,
|
||||
tanggal: true,
|
||||
},
|
||||
});
|
||||
return data;
|
||||
}
|
||||
}
|
||||
@@ -8,25 +8,13 @@ export async function event_getOneById(eventId: string) {
|
||||
where: {
|
||||
id: eventId,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
lokasi: true,
|
||||
tanggal: true,
|
||||
deskripsi: true,
|
||||
active: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
catatan: true,
|
||||
authorId: true,
|
||||
include: {
|
||||
Author: {
|
||||
include: {
|
||||
Profile: true,
|
||||
},
|
||||
},
|
||||
eventMaster_StatusId: true,
|
||||
EventMaster_Status: true,
|
||||
eventMaster_TipeAcaraId: true,
|
||||
EventMaster_TipeAcara: true,
|
||||
// Event_Peserta: true,
|
||||
},
|
||||
|
||||
@@ -18,9 +18,7 @@ export async function event_getListRiwayatSaya({ page }: { page: number }) {
|
||||
where: {
|
||||
authorId: userLoginId,
|
||||
eventMaster_StatusId: "1",
|
||||
tanggal: {
|
||||
lte: new Date(),
|
||||
},
|
||||
isArsip: true,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
|
||||
@@ -3,8 +3,7 @@
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import _ from "lodash";
|
||||
|
||||
export async function event_getListSemuaRiwayat({page}: {page: number}) {
|
||||
|
||||
export async function event_getListSemuaRiwayat({ page }: { page: number }) {
|
||||
const takeData = 10;
|
||||
const skipData = page * takeData - takeData;
|
||||
|
||||
@@ -16,9 +15,7 @@ export async function event_getListSemuaRiwayat({page}: {page: number}) {
|
||||
},
|
||||
where: {
|
||||
eventMaster_StatusId: "1",
|
||||
tanggal: {
|
||||
lte: new Date(),
|
||||
},
|
||||
isArsip: true,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
|
||||
@@ -26,9 +26,7 @@ export async function event_getAllByStatusId({
|
||||
active: true,
|
||||
eventMaster_StatusId: "1",
|
||||
authorId: userLoginId,
|
||||
tanggal: {
|
||||
gte: new Date(),
|
||||
},
|
||||
isArsip: false,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
|
||||
@@ -19,9 +19,7 @@ export async function event_funGetAllStatusPublish({ page }: { page: number }) {
|
||||
active: true,
|
||||
eventMaster_StatusId: "1",
|
||||
authorId: userLoginId,
|
||||
tanggal: {
|
||||
gte: new Date(),
|
||||
},
|
||||
isArsip: false,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
|
||||
Reference in New Issue
Block a user