# Forum Created
## feat - CRUD Forum - CRD Koment - Tampilan forum profile ### No issue
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { revalidatePath } from "next/cache";
|
||||
|
||||
export async function forum_countOneTotalKomentarById(postingId: any) {
|
||||
const data = await prisma.forum_Komentar.count({
|
||||
where: {
|
||||
forum_PostingId: postingId,
|
||||
isActive: true,
|
||||
},
|
||||
});
|
||||
|
||||
return data
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { User_getUserId } from "@/app_modules/fun_global/get_user_token";
|
||||
|
||||
export async function forum_countPostingByAuthorId(authorId: string) {
|
||||
|
||||
|
||||
const data = await prisma.forum_Posting.count({
|
||||
where: {
|
||||
authorId: authorId,
|
||||
isActive: true
|
||||
},
|
||||
});
|
||||
|
||||
return data
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
|
||||
|
||||
// PERCOBAAN
|
||||
export async function forum_countTotalKomenById(postingId: any[]) {
|
||||
// console.log(postingId)
|
||||
|
||||
const data = postingId.map(async (e) => {
|
||||
const get = await prisma.forum_Komentar.count({
|
||||
where: {
|
||||
forum_PostingId: e,
|
||||
isActive: true,
|
||||
},
|
||||
select: {
|
||||
forum_PostingId: true,
|
||||
|
||||
},
|
||||
});
|
||||
console.log(get);
|
||||
});
|
||||
|
||||
// const data = await prisma.forum_Komentar.count({
|
||||
// where: {
|
||||
// forum_PostingId: postingId,
|
||||
// isActive: true,
|
||||
// },
|
||||
// });
|
||||
|
||||
// return data;
|
||||
}
|
||||
20
src/app_modules/forum/fun/create/fun_create.tsx
Normal file
20
src/app_modules/forum/fun/create/fun_create.tsx
Normal file
@@ -0,0 +1,20 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { User_getUserId } from "@/app_modules/fun_global/get_user_token";
|
||||
import { revalidatePath } from "next/cache";
|
||||
|
||||
export async function forum_funCreate(value: string) {
|
||||
const AuthorId = await User_getUserId();
|
||||
|
||||
const create = await prisma.forum_Posting.create({
|
||||
data: {
|
||||
diskusi: value,
|
||||
authorId: AuthorId,
|
||||
},
|
||||
});
|
||||
|
||||
if (!create) return { status: 400, message: "Gagal menambahkan postingan" };
|
||||
revalidatePath("/dev/forum/main");
|
||||
return { status: 201, message: "Berhasil menambahkan postingan" };
|
||||
}
|
||||
24
src/app_modules/forum/fun/create/fun_create_komentra.tsx
Normal file
24
src/app_modules/forum/fun/create/fun_create_komentra.tsx
Normal file
@@ -0,0 +1,24 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { User_getUserId } from "@/app_modules/fun_global/get_user_token";
|
||||
import { revalidatePath } from "next/cache";
|
||||
|
||||
export async function forum_funCreateKomentar(
|
||||
postingId: string,
|
||||
komentar: string
|
||||
) {
|
||||
const authorId = await User_getUserId();
|
||||
|
||||
const create = await prisma.forum_Komentar.create({
|
||||
data: {
|
||||
komentar: komentar,
|
||||
forum_PostingId: postingId,
|
||||
authorId: authorId,
|
||||
},
|
||||
});
|
||||
|
||||
if (!create) return { status: 400, message: "Gagal menambahkan komentar" };
|
||||
revalidatePath("/dev/forum/detail");
|
||||
return { status: 201, message: "Berhasil menambahkan komentar" };
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { revalidatePath } from "next/cache";
|
||||
|
||||
export async function forum_funDeleteKomentarById(komentarId: string) {
|
||||
const del = await prisma.forum_Komentar.update({
|
||||
where: {
|
||||
id: komentarId,
|
||||
},
|
||||
data: {
|
||||
isActive: false,
|
||||
},
|
||||
});
|
||||
|
||||
if (!del) return { status: 400, message: "Gagal Dihapus" };
|
||||
revalidatePath("/dev/forum/detail");
|
||||
return { status: 200, message: "Berhasil Dihapus" };
|
||||
}
|
||||
19
src/app_modules/forum/fun/delete/fun_delete_posting_by_id.ts
Normal file
19
src/app_modules/forum/fun/delete/fun_delete_posting_by_id.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { revalidatePath } from "next/cache";
|
||||
|
||||
export async function forum_funDeletePostingById(forumId: string) {
|
||||
const del = await prisma.forum_Posting.update({
|
||||
where: {
|
||||
id: forumId,
|
||||
},
|
||||
data: {
|
||||
isActive: false,
|
||||
},
|
||||
});
|
||||
|
||||
if (!del) return { status: 400, message: "Gagal dihapus" };
|
||||
revalidatePath("/dev/forum/main");
|
||||
return { status: 200, message: "Berhasil dihapus" };
|
||||
}
|
||||
22
src/app_modules/forum/fun/edit/fun_edit_posting_by_id.ts
Normal file
22
src/app_modules/forum/fun/edit/fun_edit_posting_by_id.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { revalidatePath } from "next/cache";
|
||||
|
||||
export async function forum_funEditPostingById(
|
||||
postingId: string,
|
||||
diskusi: string
|
||||
) {
|
||||
const updt = await prisma.forum_Posting.update({
|
||||
where: {
|
||||
id: postingId,
|
||||
},
|
||||
data: {
|
||||
diskusi: diskusi,
|
||||
},
|
||||
});
|
||||
|
||||
if (!updt) return { status: 400, message: "Gagal update" };
|
||||
revalidatePath("/dev/forum/main");
|
||||
return { status: 200, message: "Berhasil update" };
|
||||
}
|
||||
35
src/app_modules/forum/fun/get/get_komentar_by_id.ts
Normal file
35
src/app_modules/forum/fun/get/get_komentar_by_id.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
|
||||
export async function forum_getKomentarById(postingId: string) {
|
||||
const data = await prisma.forum_Komentar.findMany({
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
},
|
||||
where: {
|
||||
forum_PostingId: postingId,
|
||||
isActive: true,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
isActive: true,
|
||||
komentar: true,
|
||||
createdAt: true,
|
||||
Author: {
|
||||
select: {
|
||||
id: true,
|
||||
Profile: {
|
||||
select: {
|
||||
name: true,
|
||||
imagesId: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
authorId: true,
|
||||
},
|
||||
});
|
||||
|
||||
return data;
|
||||
}
|
||||
54
src/app_modules/forum/fun/get/get_list_all_posting.ts
Normal file
54
src/app_modules/forum/fun/get/get_list_all_posting.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
"use server";
|
||||
|
||||
import _ from "lodash";
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { forum_countOneTotalKomentarById } from "../count/count_one_total_komentar_by_id";
|
||||
import { forum_countTotalKomenById } from "../count/count_total_komentar_by_id";
|
||||
|
||||
export async function forum_getListAllPosting() {
|
||||
const get = await prisma.forum_Posting.findMany({
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
},
|
||||
where: {
|
||||
isActive: true,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
diskusi: true,
|
||||
createdAt: true,
|
||||
isActive: true,
|
||||
authorId: true,
|
||||
Author: {
|
||||
select: {
|
||||
id: true,
|
||||
Profile: true,
|
||||
},
|
||||
},
|
||||
Forum_Komentar: {
|
||||
where: {
|
||||
isActive: true,
|
||||
},
|
||||
},
|
||||
// _count: {
|
||||
// select: {
|
||||
// Forum_Komentar: true,
|
||||
// },
|
||||
// },
|
||||
},
|
||||
});
|
||||
|
||||
// const data = get.map((v) => ({
|
||||
// ..._.omit(v, ['Forum_Komentar']),
|
||||
// total_coment: v.Forum_Komentar.filter((v) => v.isActive).length,
|
||||
// }));
|
||||
|
||||
const data = get.map((val) => ({
|
||||
..._.omit(val, ["Forum_Komentar"]),
|
||||
_count: val.Forum_Komentar.length,
|
||||
}));
|
||||
|
||||
// console.log(JSON.stringify(data, null, 2));
|
||||
|
||||
return data;
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { User_getUserId } from "@/app_modules/fun_global/get_user_token";
|
||||
import _ from "lodash";
|
||||
|
||||
export async function forum_getListPostingByAuhtorId(authorId: string) {
|
||||
const get = await prisma.forum_Posting.findMany({
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
},
|
||||
where: {
|
||||
authorId: authorId,
|
||||
isActive: true,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
diskusi: true,
|
||||
createdAt: true,
|
||||
isActive: true,
|
||||
authorId: true,
|
||||
Author: {
|
||||
select: {
|
||||
id: true,
|
||||
Profile: true,
|
||||
},
|
||||
},
|
||||
Forum_Komentar: {
|
||||
where: {
|
||||
isActive: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const data = get.map((val) => ({
|
||||
..._.omit(val, ["Forum_Komentar"]),
|
||||
_count: val.Forum_Komentar.length,
|
||||
}));
|
||||
|
||||
return data;
|
||||
}
|
||||
32
src/app_modules/forum/fun/get/get_one_posting_by_id.ts
Normal file
32
src/app_modules/forum/fun/get/get_one_posting_by_id.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
|
||||
export async function forum_getOnePostingById(postingId: string) {
|
||||
const data = await prisma.forum_Posting.findFirst({
|
||||
where: {
|
||||
id: postingId,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
diskusi: true,
|
||||
isActive: true,
|
||||
createdAt: true,
|
||||
authorId: true,
|
||||
Author: {
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
Profile: true,
|
||||
},
|
||||
},
|
||||
_count: {
|
||||
select: {
|
||||
Forum_Komentar: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return data;
|
||||
}
|
||||
Reference in New Issue
Block a user