Merge pull request #363 from bipproduction/amalia/27-des-24
revisi: notifikasi
This commit is contained in:
@@ -219,6 +219,7 @@ model ProjectTask {
|
|||||||
title String
|
title String
|
||||||
desc String?
|
desc String?
|
||||||
status Int @default(0) // 0 = todo, 1 = done
|
status Int @default(0) // 0 = todo, 1 = done
|
||||||
|
notifikasi Boolean @default(false)
|
||||||
dateStart DateTime @db.Date
|
dateStart DateTime @db.Date
|
||||||
dateEnd DateTime @db.Date
|
dateEnd DateTime @db.Date
|
||||||
isActive Boolean @default(true)
|
isActive Boolean @default(true)
|
||||||
@@ -303,6 +304,7 @@ model DivisionProjectTask {
|
|||||||
title String
|
title String
|
||||||
desc String? @db.Text
|
desc String? @db.Text
|
||||||
status Int @default(0) // 0 = todo, 1 = done
|
status Int @default(0) // 0 = todo, 1 = done
|
||||||
|
notifikasi Boolean @default(false)
|
||||||
dateStart DateTime @db.Date
|
dateStart DateTime @db.Date
|
||||||
dateEnd DateTime @db.Date
|
dateEnd DateTime @db.Date
|
||||||
isActive Boolean @default(true)
|
isActive Boolean @default(true)
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { DivisionProject } from './../../../../node_modules/.prisma/client/index.d';
|
||||||
import { prisma } from "@/module/_global";
|
import { prisma } from "@/module/_global";
|
||||||
import { funGetUserByCookies } from "@/module/auth";
|
import { funGetUserByCookies } from "@/module/auth";
|
||||||
import _, { ceil } from "lodash";
|
import _, { ceil } from "lodash";
|
||||||
@@ -445,6 +446,134 @@ export async function GET(request: Request) {
|
|||||||
totalNotif: total,
|
totalNotif: total,
|
||||||
village: desa?.name
|
village: desa?.name
|
||||||
}
|
}
|
||||||
|
} else if (kategori == "check-late-project") {
|
||||||
|
const supadmin = await prisma.user.findFirst({
|
||||||
|
where: {
|
||||||
|
idUserRole: "supadmin",
|
||||||
|
idVillage: idVillage
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const dataUmum = await prisma.projectTask.findMany({
|
||||||
|
where: {
|
||||||
|
Project: {
|
||||||
|
idVillage: idVillage,
|
||||||
|
isActive: true,
|
||||||
|
status: {
|
||||||
|
not: {
|
||||||
|
in: [2, 3]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
notifikasi: false,
|
||||||
|
isActive: true,
|
||||||
|
status: 0,
|
||||||
|
dateEnd: {
|
||||||
|
lt: new Date()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
title: true,
|
||||||
|
dateEnd: true,
|
||||||
|
Project: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
for (let index = 0; index < dataUmum.length; index++) {
|
||||||
|
await prisma.projectTask.update({
|
||||||
|
where: {
|
||||||
|
id: dataUmum[index].id
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
notifikasi: true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const pertama = dataUmum.map((v: any) => ({
|
||||||
|
..._.omit(v, ["Project", "title", "id", "dateEnd"]),
|
||||||
|
idUserTo: String(supadmin?.id),
|
||||||
|
idUserFrom: String(user.id),
|
||||||
|
category: 'project',
|
||||||
|
idContent: v.Project.id,
|
||||||
|
title: `Tugas ${v.title} Telah Melewati Batas Waktu`,
|
||||||
|
desc: `Tugas dengan deadline ${moment(v.dateEnd).format('DD-MM-yyyy')} telah berakhir. Silakan segera melakukan tindakan yang diperlukan.`
|
||||||
|
}))
|
||||||
|
|
||||||
|
const insertNotif = await prisma.notifications.createMany({
|
||||||
|
data: pertama
|
||||||
|
})
|
||||||
|
|
||||||
|
const dataDivisi = await prisma.divisionProjectTask.findMany({
|
||||||
|
where: {
|
||||||
|
Division: {
|
||||||
|
idVillage: idVillage,
|
||||||
|
isActive: true
|
||||||
|
},
|
||||||
|
DivisionProject: {
|
||||||
|
isActive: true,
|
||||||
|
status: {
|
||||||
|
not: {
|
||||||
|
in: [2, 3]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
notifikasi: false,
|
||||||
|
isActive: true,
|
||||||
|
status: 0,
|
||||||
|
dateEnd: {
|
||||||
|
lt: new Date()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
title: true,
|
||||||
|
dateEnd: true,
|
||||||
|
DivisionProject: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
idDivision: true
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
for (let index = 0; index < dataDivisi.length; index++) {
|
||||||
|
await prisma.divisionProjectTask.update({
|
||||||
|
where: {
|
||||||
|
id: dataDivisi[index].id
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
notifikasi: true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const kedua = dataDivisi.map((v: any) => ({
|
||||||
|
..._.omit(v, ["DivisionProject", "title", "id", "dateEnd"]),
|
||||||
|
idUserTo: String(supadmin?.id),
|
||||||
|
idUserFrom: String(user.id),
|
||||||
|
category: 'division/' + v.DivisionProject.idDivision + '/task',
|
||||||
|
idContent: v.DivisionProject.id,
|
||||||
|
title: `Tugas ${v.title} Telah Melewati Batas Waktu`,
|
||||||
|
desc: `Tugas dengan deadline ${moment(v.dateEnd).format('DD-MM-yyyy')} telah berakhir. Silakan segera melakukan tindakan yang diperlukan.`
|
||||||
|
}))
|
||||||
|
|
||||||
|
const insertNotif2 = await prisma.notifications.createMany({
|
||||||
|
data: kedua
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
const merge = [...pertama, ...kedua]
|
||||||
|
|
||||||
|
allData = merge
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return NextResponse.json({ success: true, message: "Berhasil mendapatkan data", data: allData }, { status: 200 });
|
return NextResponse.json({ success: true, message: "Berhasil mendapatkan data", data: allData }, { status: 200 });
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
'use client'
|
'use client'
|
||||||
import { TEMA } from '@/module/_global';
|
import { keyWibu, TEMA } from '@/module/_global';
|
||||||
import { funGetAllBanner, IDataBanner } from '@/module/banner';
|
import { funGetAllBanner, IDataBanner } from '@/module/banner';
|
||||||
import { useHookstate } from '@hookstate/core';
|
import { useHookstate } from '@hookstate/core';
|
||||||
import { Carousel } from '@mantine/carousel';
|
import { Carousel } from '@mantine/carousel';
|
||||||
@@ -9,11 +9,16 @@ import Autoplay from 'embla-carousel-autoplay';
|
|||||||
import { useRef, useState } from 'react';
|
import { useRef, useState } from 'react';
|
||||||
import toast from 'react-hot-toast';
|
import toast from 'react-hot-toast';
|
||||||
import { funGetHome } from '../lib/api_home';
|
import { funGetHome } from '../lib/api_home';
|
||||||
|
import { useWibuRealtime } from 'wibu-realtime';
|
||||||
export default function Carosole() {
|
export default function Carosole() {
|
||||||
const autoplay = useRef(Autoplay({ delay: 5000 }));
|
const autoplay = useRef(Autoplay({ delay: 5000 }));
|
||||||
const tema = useHookstate(TEMA)
|
const tema = useHookstate(TEMA)
|
||||||
const [isDesa, setDesa] = useState("")
|
const [isDesa, setDesa] = useState("")
|
||||||
const [isData, setData] = useState<IDataBanner[]>([])
|
const [isData, setData] = useState<IDataBanner[]>([])
|
||||||
|
const [data, setDataRealtime] = useWibuRealtime({
|
||||||
|
WIBU_REALTIME_TOKEN: keyWibu,
|
||||||
|
project: "sdm"
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
const fetchData = async () => {
|
const fetchData = async () => {
|
||||||
@@ -36,9 +41,19 @@ export default function Carosole() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
async function cekData() {
|
||||||
|
try {
|
||||||
|
const response = await funGetHome('?cat=check-late-project')
|
||||||
|
setDataRealtime(response.data)
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
useShallowEffect(() => {
|
useShallowEffect(() => {
|
||||||
fetchData();
|
fetchData();
|
||||||
|
cekData();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in New Issue
Block a user