Voting notifikasi for mobile
Fix: - src/app/api/mobile/admin/voting/[id]/route.ts - src/app/api/mobile/event/route.ts - src/app/api/mobile/voting/[id]/route.ts - src/app/api/mobile/voting/route.ts - src/lib/mobile/route-page-mobile.ts ### No Issue
This commit is contained in:
@@ -1,8 +1,17 @@
|
|||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
import { prisma } from "@/lib";
|
import { prisma } from "@/lib";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
|
import {
|
||||||
|
sendNotificationMobileToManyUser,
|
||||||
|
sendNotificationMobileToOneUser,
|
||||||
|
} from "@/lib/mobile/notification/send-notification";
|
||||||
|
import { routeUserMobile } from "@/lib/mobile/route-page-mobile";
|
||||||
|
import {
|
||||||
|
NotificationMobileBodyType,
|
||||||
|
NotificationMobileTitleType,
|
||||||
|
} from "../../../../../../../types/type-mobile-notification";
|
||||||
|
|
||||||
export { GET , PUT};
|
export { GET, PUT };
|
||||||
|
|
||||||
async function GET(request: Request, { params }: { params: { id: string } }) {
|
async function GET(request: Request, { params }: { params: { id: string } }) {
|
||||||
const { id } = params;
|
const { id } = params;
|
||||||
@@ -41,12 +50,16 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
|||||||
async function PUT(request: Request, { params }: { params: { id: string } }) {
|
async function PUT(request: Request, { params }: { params: { id: string } }) {
|
||||||
const { id } = params;
|
const { id } = params;
|
||||||
const { data } = await request.json();
|
const { data } = await request.json();
|
||||||
|
const { catatan, senderId } = data;
|
||||||
|
|
||||||
|
console.log("catatan", catatan);
|
||||||
|
console.log("senderId", senderId);
|
||||||
|
|
||||||
const { searchParams } = new URL(request.url);
|
const { searchParams } = new URL(request.url);
|
||||||
const status = searchParams.get("status");
|
const status = searchParams.get("status");
|
||||||
const fixStatus = _.startCase(status as string);
|
const fixStatus = _.startCase(status as string);
|
||||||
let fixData;
|
let fixData;
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const checkStatus = await prisma.voting_Status.findFirst({
|
const checkStatus = await prisma.voting_Status.findFirst({
|
||||||
where: {
|
where: {
|
||||||
@@ -71,9 +84,23 @@ async function PUT(request: Request, { params }: { params: { id: string } }) {
|
|||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
voting_StatusId: checkStatus.id,
|
voting_StatusId: checkStatus.id,
|
||||||
catatan: data,
|
catatan: catatan,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// SEND NOTIFICATION
|
||||||
|
await sendNotificationMobileToOneUser({
|
||||||
|
recipientId: updateStatus.authorId as any,
|
||||||
|
senderId: senderId,
|
||||||
|
payload: {
|
||||||
|
title: "Pengajuan Review Ditolak",
|
||||||
|
body: "Mohon perbaiki data sesuai catatan penolakan !",
|
||||||
|
type: "announcement",
|
||||||
|
kategoriApp: "VOTING",
|
||||||
|
deepLink: routeUserMobile.votingByStatus({ status: "reject" }),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
fixData = updateStatus;
|
fixData = updateStatus;
|
||||||
} else if (fixStatus === "Publish") {
|
} else if (fixStatus === "Publish") {
|
||||||
const updateStatus = await prisma.voting.update({
|
const updateStatus = await prisma.voting.update({
|
||||||
@@ -84,6 +111,39 @@ async function PUT(request: Request, { params }: { params: { id: string } }) {
|
|||||||
voting_StatusId: checkStatus.id,
|
voting_StatusId: checkStatus.id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await sendNotificationMobileToOneUser({
|
||||||
|
recipientId: updateStatus.authorId as any,
|
||||||
|
senderId: senderId,
|
||||||
|
payload: {
|
||||||
|
title: "Review Selesai",
|
||||||
|
body: "Voting kamu telah dipublikasikan !" as NotificationMobileBodyType,
|
||||||
|
type: "announcement",
|
||||||
|
kategoriApp: "VOTING",
|
||||||
|
deepLink: routeUserMobile.votingByStatus({ status: "publish" }),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const adminUsers = await prisma.user.findMany({
|
||||||
|
where: {
|
||||||
|
masterUserRoleId: "1",
|
||||||
|
NOT: { id: updateStatus.authorId as any },
|
||||||
|
},
|
||||||
|
select: { id: true },
|
||||||
|
});
|
||||||
|
|
||||||
|
await sendNotificationMobileToManyUser({
|
||||||
|
recipientIds: adminUsers.map((user) => user.id),
|
||||||
|
senderId: senderId,
|
||||||
|
payload: {
|
||||||
|
title: "Cek Voting Baru Terpublikasi" as NotificationMobileTitleType,
|
||||||
|
body: `${updateStatus.title}` as NotificationMobileBodyType,
|
||||||
|
type: "announcement",
|
||||||
|
kategoriApp: "VOTING",
|
||||||
|
deepLink: routeUserMobile.votingDetailPublised({ id: id }),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
fixData = updateStatus;
|
fixData = updateStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ async function POST(request: Request) {
|
|||||||
select: { id: true },
|
select: { id: true },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// SEND NOTIFICATION
|
||||||
await sendNotificationMobileToManyUser({
|
await sendNotificationMobileToManyUser({
|
||||||
recipientIds: adminUsers.map((user) => user.id),
|
recipientIds: adminUsers.map((user) => user.id),
|
||||||
senderId: data.authorId,
|
senderId: data.authorId,
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
import prisma from "@/lib/prisma";
|
import prisma from "@/lib/prisma";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
|
import { sendNotificationMobileToOneUser } from "@/lib/mobile/notification/send-notification";
|
||||||
|
import {
|
||||||
|
NotificationMobileBodyType,
|
||||||
|
NotificationMobileTitleType,
|
||||||
|
} from "../../../../../../types/type-mobile-notification";
|
||||||
|
import { routeUserMobile } from "@/lib/mobile/route-page-mobile";
|
||||||
|
|
||||||
export { GET, DELETE, PUT, POST };
|
export { GET, DELETE, PUT, POST };
|
||||||
|
|
||||||
@@ -39,7 +45,6 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
|||||||
const listNamaVote = data?.Voting_DaftarNamaVote || [];
|
const listNamaVote = data?.Voting_DaftarNamaVote || [];
|
||||||
|
|
||||||
for (let v of listNamaVote) {
|
for (let v of listNamaVote) {
|
||||||
|
|
||||||
const kontributor = await prisma.voting_Kontributor.findMany({
|
const kontributor = await prisma.voting_Kontributor.findMany({
|
||||||
where: {
|
where: {
|
||||||
voting_DaftarNamaVoteId: v.id,
|
voting_DaftarNamaVoteId: v.id,
|
||||||
@@ -90,7 +95,6 @@ async function DELETE(
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
success: true,
|
success: true,
|
||||||
message: "Berhasil menghapus data",
|
message: "Berhasil menghapus data",
|
||||||
@@ -171,7 +175,6 @@ async function PUT(request: Request, { params }: { params: { id: string } }) {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
if (!updateVoting)
|
if (!updateVoting)
|
||||||
return NextResponse.json({ status: 400, message: "Gagal Update" });
|
return NextResponse.json({ status: 400, message: "Gagal Update" });
|
||||||
}
|
}
|
||||||
@@ -193,11 +196,12 @@ async function PUT(request: Request, { params }: { params: { id: string } }) {
|
|||||||
async function POST(request: Request, { params }: { params: { id: string } }) {
|
async function POST(request: Request, { params }: { params: { id: string } }) {
|
||||||
const { id } = params;
|
const { id } = params;
|
||||||
const { data } = await request.json();
|
const { data } = await request.json();
|
||||||
|
const { chooseId, userId } = data;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const findData = await prisma.voting_DaftarNamaVote.findFirst({
|
const findDatapilihan = await prisma.voting_DaftarNamaVote.findFirst({
|
||||||
where: {
|
where: {
|
||||||
id: data.chooseId,
|
id: chooseId,
|
||||||
},
|
},
|
||||||
select: {
|
select: {
|
||||||
jumlah: true,
|
jumlah: true,
|
||||||
@@ -205,28 +209,32 @@ async function POST(request: Request, { params }: { params: { id: string } }) {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!findData)
|
if (!findDatapilihan)
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
success: false,
|
success: false,
|
||||||
message: "Data tidak ditemukan",
|
message: "Data tidak ditemukan",
|
||||||
});
|
});
|
||||||
|
|
||||||
const updateData = await prisma.voting_DaftarNamaVote.update({
|
const updateDataPilihan = await prisma.voting_DaftarNamaVote.update({
|
||||||
where: {
|
where: {
|
||||||
id: data.chooseId,
|
id: data.chooseId,
|
||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
jumlah: findData.jumlah + 1,
|
jumlah: findDatapilihan.jumlah + 1,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!updateDataPilihan)
|
||||||
if (!updateData)
|
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
success: false,
|
success: false,
|
||||||
message: "Gagal Update Data",
|
message: "Gagal Update Data",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const findVotingData = await prisma.voting.findUnique({
|
||||||
|
where: { id: id },
|
||||||
|
select: { authorId: true, title: true },
|
||||||
|
});
|
||||||
|
|
||||||
const createKontributor = await prisma.voting_Kontributor.create({
|
const createKontributor = await prisma.voting_Kontributor.create({
|
||||||
data: {
|
data: {
|
||||||
votingId: id,
|
votingId: id,
|
||||||
@@ -250,6 +258,21 @@ async function POST(request: Request, { params }: { params: { id: string } }) {
|
|||||||
message: "Gagal Menjadi Kontributor",
|
message: "Gagal Menjadi Kontributor",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// SEND NOTIFICATION
|
||||||
|
if (userId !== findVotingData?.authorId) {
|
||||||
|
await sendNotificationMobileToOneUser({
|
||||||
|
recipientId: findVotingData?.authorId as string,
|
||||||
|
senderId: userId,
|
||||||
|
payload: {
|
||||||
|
title: "User Melakukan Vote" as NotificationMobileTitleType,
|
||||||
|
body: `Salah satu user telah melakukan voting pada: ${findVotingData?.title}` as NotificationMobileBodyType,
|
||||||
|
type: "announcement",
|
||||||
|
deepLink: routeUserMobile.votingDetailPublised({ id: id }),
|
||||||
|
kategoriApp: "VOTING",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
success: true,
|
success: true,
|
||||||
message: "Berhasil Voting",
|
message: "Berhasil Voting",
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
import prisma from "@/lib/prisma";
|
import prisma from "@/lib/prisma";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
|
import { sendNotificationMobileToManyUser } from "@/lib/mobile/notification/send-notification";
|
||||||
|
import { NotificationMobileBodyType } from "../../../../../types/type-mobile-notification";
|
||||||
|
import { routeAdminMobile } from "@/lib/mobile/route-page-mobile";
|
||||||
|
|
||||||
export { POST, GET };
|
export { POST, GET };
|
||||||
|
|
||||||
@@ -41,6 +44,24 @@ async function POST(request: Request) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const adminUsers = await prisma.user.findMany({
|
||||||
|
where: { masterUserRoleId: "2", NOT: { id: data.authorId } },
|
||||||
|
select: { id: true },
|
||||||
|
});
|
||||||
|
|
||||||
|
// SEND NOTIFICATION
|
||||||
|
await sendNotificationMobileToManyUser({
|
||||||
|
recipientIds: adminUsers.map((user) => user.id),
|
||||||
|
senderId: data.authorId,
|
||||||
|
payload: {
|
||||||
|
title: "Pengajuan Review Baru",
|
||||||
|
body: create.title as NotificationMobileBodyType,
|
||||||
|
type: "announcement",
|
||||||
|
deepLink: routeAdminMobile.votingByStatus({ status: "review" }),
|
||||||
|
kategoriApp: "VOTING",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{
|
{
|
||||||
success: true,
|
success: true,
|
||||||
@@ -125,8 +146,6 @@ async function GET(request: Request) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
fixData = data;
|
fixData = data;
|
||||||
|
|
||||||
|
|
||||||
} else if (category === "contribution") {
|
} else if (category === "contribution") {
|
||||||
const data = await prisma.voting_Kontributor.findMany({
|
const data = await prisma.voting_Kontributor.findMany({
|
||||||
orderBy: {
|
orderBy: {
|
||||||
|
|||||||
@@ -5,14 +5,16 @@ type StatusApp = "review" | "draft" | "reject" | "publish";
|
|||||||
const routeAdminMobile = {
|
const routeAdminMobile = {
|
||||||
userAccess: ({ id }: { id: string }) => `/admin/user-access/${id}`,
|
userAccess: ({ id }: { id: string }) => `/admin/user-access/${id}`,
|
||||||
// JOB
|
// JOB
|
||||||
jobDetail: ({ id, status }: { id: string; status: StatusApp }) =>
|
|
||||||
`/admin/job/${id}/${status}`,
|
|
||||||
jobByStatus: ({ status }: { status: StatusApp }) =>
|
jobByStatus: ({ status }: { status: StatusApp }) =>
|
||||||
`/admin/job/${status}/status`,
|
`/admin/job/${status}/status`,
|
||||||
|
|
||||||
// EVENT
|
// EVENT
|
||||||
eventByStatus: ({ status }: { status: StatusApp }) =>
|
eventByStatus: ({ status }: { status: StatusApp }) =>
|
||||||
`/admin/event/${status}/status`,
|
`/admin/event/${status}/status`,
|
||||||
|
|
||||||
|
// VOTING
|
||||||
|
votingByStatus: ({ status }: { status: StatusApp }) =>
|
||||||
|
`/admin/voting/${status}/status`,
|
||||||
};
|
};
|
||||||
|
|
||||||
const routeUserMobile = {
|
const routeUserMobile = {
|
||||||
@@ -26,4 +28,9 @@ const routeUserMobile = {
|
|||||||
eventByStatus: ({ status }: { status?: StatusApp }) =>
|
eventByStatus: ({ status }: { status?: StatusApp }) =>
|
||||||
`/event/(tabs)/status?status=${status}`,
|
`/event/(tabs)/status?status=${status}`,
|
||||||
eventDetailPublised: ({ id }: { id: string }) => `/event/${id}/publish`,
|
eventDetailPublised: ({ id }: { id: string }) => `/event/${id}/publish`,
|
||||||
|
|
||||||
|
// VOTING
|
||||||
|
votingByStatus: ({ status }: { status?: StatusApp }) =>
|
||||||
|
`/voting/(tabs)/status?status=${status}`,
|
||||||
|
votingDetailPublised: ({ id }: { id: string }) => `/voting/${id}`,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user