## feat
- Voting user
- Halaman kontribusi
- Halaman riwayat
### No issuue
This commit is contained in:
2024-02-16 17:20:06 +08:00
parent 0dd8e287f4
commit e629157960
135 changed files with 3160 additions and 1501 deletions

View File

@@ -0,0 +1,46 @@
"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 Vote_funCreateHasil(
pilihanVotingId: string,
votingId: string
) {
const authorId = await User_getUserId();
const get = await prisma.voting_DaftarNamaVote.findFirst({
where: {
id: pilihanVotingId,
},
select: {
jumlah: true,
},
});
if (!get) return { status: 400, message: "Gagal Voting" };
const updt = await prisma.voting_DaftarNamaVote.update({
where: {
id: pilihanVotingId,
},
data: {
jumlah: get.jumlah + 1,
},
});
if (!updt) return { status: 400, message: "Gagal Update" };
const create = await prisma.voting_Kontributor.create({
data: {
voting_DaftarNamaVoteId: pilihanVotingId,
votingId: votingId,
authorId: authorId,
},
});
if (!create) return { status: 400, message: "Gagal Menjadi Kontributor" };
revalidatePath("/dev/vote/detail/main/");
return { status: 201, message: "Berhasil Voting" };
}

View 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 Vote_funCreatePilihanVotingById(
namaVotingId: string,
votingId: string
) {
const authorId = await User_getUserId();
const create = await prisma.voting_Kontributor.create({
data: {
voting_DaftarNamaVoteId: namaVotingId,
votingId: votingId,
authorId: authorId,
},
});
if(!create) return {status: 400, message: "Gagal Voting"}
revalidatePath("/dev/vote/detail/main/");
return {status: 201, message: "Berhasil Voting"}
}

View File

@@ -0,0 +1,41 @@
"use server";
import { User_getUserId } from "@/app_modules/fun_global/get_user_token";
import { MODEL_VOTING } from "../../model/interface";
import prisma from "@/app/lib/prisma";
import { revalidatePath } from "next/cache";
export async function Vote_funCreate(req: MODEL_VOTING, listVote: any[]) {
const authorId = await User_getUserId();
const create = await prisma.voting.create({
data: {
title: req.title,
deskripsi: req.deskripsi,
awalVote: req.awalVote,
akhirVote: req.akhirVote,
authorId: authorId,
},
});
if (!create) return { status: 400, message: "Gagal Membuat Vote" };
for (let v of listVote) {
const val = v.value;
const namaVote = await prisma.voting_DaftarNamaVote.createMany({
data: {
value: val,
votingId: create.id,
},
});
if (!namaVote) return { status: 400, message: "Gagal Membuat List" };
}
revalidatePath("/dev/vote/main/status");
return {
status: 201,
message: "Berhasil Membuat Vote",
};
}

View File

@@ -0,0 +1,26 @@
"use server";
import prisma from "@/app/lib/prisma";
import { revalidatePath } from "next/cache";
/**
* @param voteId
* @returns isActive berubah menjadi false
*/
export async function Vote_funDeleteById(voteId: string) {
const del = await prisma.voting.update({
where: {
id: voteId,
},
data: {
isActive: false,
},
});
if (!del) return { status: 400, message: "Gagal Hapus Data" };
revalidatePath("/dev/vote/main/status");
return {
status: 200,
message: "Hapus Berhasil",
};
}

View File

@@ -0,0 +1,48 @@
"use server";
import prisma from "@/app/lib/prisma";
import {
MODEL_VOTING,
MODEL_VOTING_DAFTAR_NAMA_VOTE,
} from "../../model/interface";
import { revalidatePath } from "next/cache";
export async function Vote_funEditById(
data: MODEL_VOTING,
listVoting: MODEL_VOTING_DAFTAR_NAMA_VOTE[]
) {
// console.log(listVoting)
const updtVoting = await prisma.voting.update({
where: {
id: data.id,
},
data: {
title: data.title,
deskripsi: data.deskripsi,
awalVote: data.awalVote,
akhirVote: data.akhirVote,
},
});
if (!updtVoting) return { status: 400, message: "Gagal Update" };
for (let e of listVoting) {
const updtListVoting = await prisma.voting_DaftarNamaVote.updateMany({
where: {
id: e.id,
},
data: {
value: e.value,
},
});
if (!updtListVoting)
return { status: 400, message: "Gagal Update Daftar Vote" };
}
revalidatePath("/dev/vote/detail/draft");
return {
status: 200,
message: "Berhasil Update",
};
}

View File

@@ -0,0 +1,26 @@
"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 Vote_funEditStatusByStatusId(
voteId: string,
statusId: string
) {
const updt = await prisma.voting.update({
where: {
id: voteId,
},
data: {
voting_StatusId: statusId,
},
});
if (!updt) return { status: 400, message: "Gagal Update" };
revalidatePath("/dev/vote/main/status");
return {
status: 200,
message: "Update Berhasil",
};
}

View File

@@ -0,0 +1,21 @@
"use server";
import prisma from "@/app/lib/prisma";
import { User_getUserId } from "@/app_modules/fun_global/get_user_token";
export async function Vote_cekKontributorById(votingId: string) {
const UserId = await User_getUserId()
const cek = await prisma.voting_Kontributor.count({
where: {
authorId: UserId,
votingId: votingId,
},
});
if (cek > 0) {
return true;
} else {
return false;
}
}

View File

@@ -0,0 +1,47 @@
"use server";
import prisma from "@/app/lib/prisma";
import { User_getUserId } from "@/app_modules/fun_global/get_user_token";
export async function Vote_getAllListPublish() {
const data = await prisma.voting.findMany({
orderBy: {
updatedAt: "desc",
},
where: {
voting_StatusId: "1",
isActive: true,
akhirVote: {
gte: new Date(),
},
},
select: {
id: true,
title: true,
isActive: true,
createdAt: true,
updatedAt: true,
deskripsi: true,
awalVote: true,
akhirVote: true,
catatan: true,
authorId: true,
voting_StatusId: true,
Voting_DaftarNamaVote: {
orderBy: {
createdAt: "asc",
},
},
Author: {
select: {
id: true,
username: true,
nomor: true,
Profile: true,
},
},
},
});
return data;
}

View File

@@ -0,0 +1,46 @@
"use server"
import prisma from "@/app/lib/prisma"
export async function Vote_getAllListRiwayat() {
const data = await prisma.voting.findMany({
orderBy: {
createdAt: "asc",
},
where: {
voting_StatusId: "1",
isActive: true,
akhirVote: {
lte: new Date(),
},
},
select: {
id: true,
title: true,
isActive: true,
createdAt: true,
updatedAt: true,
deskripsi: true,
awalVote: true,
akhirVote: true,
catatan: true,
authorId: true,
voting_StatusId: true,
Voting_DaftarNamaVote: {
orderBy: {
createdAt: "asc",
},
},
Author: {
select: {
id: true,
username: true,
nomor: true,
Profile: true,
},
},
},
});
return data
}

View File

@@ -0,0 +1,49 @@
"use server";
import { User_getUserId } from "@/app_modules/fun_global/get_user_token";
import prisma from "@/app/lib/prisma";
export async function Vote_getAllListRiwayatSaya() {
const authorId = await User_getUserId();
const data = await prisma.voting.findMany({
orderBy: {
createdAt: "asc",
},
where: {
voting_StatusId: "1",
authorId: authorId,
isActive: true,
akhirVote: {
lte: new Date(),
},
},
select: {
id: true,
title: true,
isActive: true,
createdAt: true,
updatedAt: true,
deskripsi: true,
awalVote: true,
akhirVote: true,
catatan: true,
authorId: true,
voting_StatusId: true,
Voting_DaftarNamaVote: {
orderBy: {
createdAt: "asc",
},
},
Author: {
select: {
id: true,
username: true,
nomor: true,
Profile: true,
},
},
},
});
return data;
}

View File

@@ -0,0 +1,13 @@
"use server";
import prisma from "@/app/lib/prisma";
export async function Vote_getListDaftarNamaById(voteId: string) {
const data = await prisma.voting_DaftarNamaVote.findMany({
where: {
votingId: voteId,
},
});
return data;
}

View File

@@ -0,0 +1,42 @@
"use server";
import prisma from "@/app/lib/prisma";
import { MODEL_VOTING_DAFTAR_NAMA_VOTE } from "../../model/interface";
import _ from "lodash";
export async function Vote_getHasilVoteById(
daftarPilihanVoting: MODEL_VOTING_DAFTAR_NAMA_VOTE[]
) {
// console.log(daftarPilihanVoting)
// for (let e of daftarPilihanVoting) {
// const get = await prisma.voting_Kontributor.count({
// where: {
// voting_DaftarNamaVoteId: e.id,
// },
// });
// console.log(get);
// return get
// }
const data = await prisma.voting_Kontributor.findMany({
where: {
votingId: "clsijw6uf0001x5logh7msuh1",
},
});
const hitung = _.map(
_.groupBy(data, "voting_DaftarNamaVoteId"),
(v: any) => ({
jumlah: v.length,
idDaftarNama: v[0].voting_DaftarNamaVoteId,
})
);
// const filter = hitung.filter(
// (i: any) => i.idDaftarNama == "clsijw6ur0002x5loqsq6g4id"
// );
return hitung
}

View File

@@ -0,0 +1,41 @@
"use server";
import prisma from "@/app/lib/prisma";
import { User_getUserId } from "@/app_modules/fun_global/get_user_token";
export async function Vote_getAllListKontribusiByAuthorId() {
const authorId = await User_getUserId();
const data = await prisma.voting_Kontributor.findMany({
orderBy: {
createdAt: "asc",
},
where: {
authorId: authorId,
},
select: {
id: true,
Voting: {
select: {
id: true,
title: true,
isActive: true,
awalVote: true,
akhirVote: true,
Voting_DaftarNamaVote: {
orderBy: {
createdAt: "asc",
},
},
Author: {
select: {
Profile: true,
},
},
},
},
Voting_DaftarNamaVote: true,
Author: true,
},
});
return data;
}

View File

@@ -0,0 +1,26 @@
"use server";
import prisma from "@/app/lib/prisma";
export async function Vote_getListKontributorById(votingId: string) {
const data = await prisma.voting_Kontributor.findMany({
where: {
votingId: votingId,
},
select: {
id: true,
Author: {
select: {
Profile: true,
},
},
Voting_DaftarNamaVote: {
select: {
value: true,
},
},
},
});
return data;
}

View File

@@ -0,0 +1,89 @@
"use server";
import prisma from "@/app/lib/prisma";
import { User_getUserId } from "@/app_modules/fun_global/get_user_token";
export async function Vote_getListByStatusId(statusId: string) {
const authorId = await User_getUserId();
if (statusId === "1") {
const data = await prisma.voting.findMany({
orderBy: {
updatedAt: "desc",
},
where: {
voting_StatusId: "1",
authorId: authorId,
isActive: true,
akhirVote: {
gte: new Date(),
},
},
select: {
id: true,
title: true,
isActive: true,
createdAt: true,
updatedAt: true,
deskripsi: true,
awalVote: true,
akhirVote: true,
catatan: true,
authorId: true,
voting_StatusId: true,
Voting_DaftarNamaVote: {
orderBy: {
createdAt: "asc",
},
},
},
});
return data;
}
if (statusId === "2") {
const data = await prisma.voting.findMany({
orderBy: {
updatedAt: "desc",
},
where: {
voting_StatusId: "2",
authorId: authorId,
isActive: true,
},
});
return data;
}
if (statusId === "3") {
const data = await prisma.voting.findMany({
orderBy: {
updatedAt: "desc",
},
where: {
voting_StatusId: "3",
authorId: authorId,
isActive: true,
},
});
return data;
}
if (statusId === "4") {
const data = await prisma.voting.findMany({
orderBy: {
updatedAt: "desc",
},
where: {
voting_StatusId: "4",
authorId: authorId,
isActive: true,
},
});
return data;
}
}

View File

@@ -0,0 +1,37 @@
"use server";
import prisma from "@/app/lib/prisma";
export async function Vote_getOnebyId(voteId: string) {
const data = await prisma.voting.findFirst({
where: {
id: voteId,
},
select: {
id: true,
title: true,
isActive: true,
createdAt: true,
updatedAt: true,
deskripsi: true,
awalVote: true,
akhirVote: true,
catatan: true,
authorId: true,
voting_StatusId: true,
Voting_DaftarNamaVote: {
orderBy: {
createdAt: "asc"
}
},
Author: {
select: {
Profile: true
}
}
},
});
return data;
}

View File

@@ -0,0 +1,23 @@
"use server";
import prisma from "@/app/lib/prisma";
import { User_getUserId } from "@/app_modules/fun_global/get_user_token";
export async function Vote_getOnePilihanVotingByUserId(votingId: string) {
const userId = await User_getUserId();
const get = await prisma.voting_Kontributor.findFirst({
where: {
authorId: userId,
votingId: votingId,
},
select: {
Voting_DaftarNamaVote: {
select: {
value: true,
},
},
},
});
return get;
}

View File

@@ -0,0 +1,36 @@
"use server";
import prisma from "@/app/lib/prisma";
export async function Vote_getOnePublishbyId(voteId: string) {
const data = await prisma.voting.findFirst({
where: {
id: voteId,
},
select: {
id: true,
title: true,
isActive: true,
createdAt: true,
updatedAt: true,
deskripsi: true,
awalVote: true,
akhirVote: true,
catatan: true,
authorId: true,
voting_StatusId: true,
Voting_DaftarNamaVote: {
orderBy: {
createdAt: "asc",
},
},
Author: {
select: {
Profile: true,
},
},
},
});
return data;
}