Compare commits
6 Commits
amalia/17-
...
amalia/30-
| Author | SHA1 | Date | |
|---|---|---|---|
| bf9ef48a70 | |||
| 97ae638472 | |||
| 183d40580d | |||
| 60702256a3 | |||
| 9e11208a13 | |||
| 0077ebda05 |
@@ -1,4 +1,4 @@
|
||||
import { countTime, prisma } from "@/module/_global";
|
||||
import { countTime, DIR, funUploadFile, prisma } from "@/module/_global";
|
||||
import { funGetUserById } from "@/module/auth";
|
||||
import { createLogUserMobile } from "@/module/user";
|
||||
import _ from "lodash";
|
||||
@@ -227,7 +227,13 @@ export async function PUT(request: Request, context: { params: { id: string } })
|
||||
export async function POST(request: Request, context: { params: { id: string } }) {
|
||||
try {
|
||||
const { id } = context.params
|
||||
const { title, desc, user } = (await request.json())
|
||||
const body = await request.formData()
|
||||
const dataBody = body.get("data")
|
||||
const cekFile = body.has("file0")
|
||||
|
||||
// const { title, desc, user } = (await request.json())
|
||||
const { title, desc, user, oldFile } = JSON.parse(dataBody as string)
|
||||
|
||||
|
||||
const userMobile = await funGetUserById({ id: String(user) })
|
||||
|
||||
@@ -254,6 +260,41 @@ export async function POST(request: Request, context: { params: { id: string } }
|
||||
}
|
||||
});
|
||||
|
||||
if (oldFile.length > 0) {
|
||||
for (let index = 0; index < oldFile.length; index++) {
|
||||
const element = oldFile[index];
|
||||
if (element.delete) {
|
||||
await prisma.divisionDiscussionFile.delete({
|
||||
where: {
|
||||
id: element.id
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (cekFile) {
|
||||
body.delete("data")
|
||||
for (var pair of body.entries()) {
|
||||
if (String(pair[0]).substring(0, 4) == "file") {
|
||||
const file = body.get(pair[0]) as File
|
||||
const fExt = file.name.split(".").pop()
|
||||
const fName = decodeURIComponent(file.name.replace("." + fExt, ""))
|
||||
const upload = await funUploadFile({ file: file, dirId: DIR.discussionDivision })
|
||||
if (upload.success) {
|
||||
await prisma.divisionDiscussionFile.create({
|
||||
data: {
|
||||
idStorage: upload.data.id,
|
||||
idDiscussion: id,
|
||||
name: fName,
|
||||
extension: String(fExt)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// create log user
|
||||
const log = await createLogUserMobile({ act: 'UPDATE', desc: 'User mengupdate data diskusi', table: 'divisionDisscussion', data: id, user: userMobile.id })
|
||||
return NextResponse.json({ success: true, message: "Berhasil mengedit diskusi" }, { status: 200 });
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { DivisionDiscussionFile } from './../../../../../node_modules/.prisma/client/index.d';
|
||||
import { DIR, funSendWebPush, funUploadFile, prisma } from "@/module/_global";
|
||||
import { funGetUserById } from "@/module/auth";
|
||||
import { createLogUserMobile } from "@/module/user";
|
||||
|
||||
@@ -33,13 +33,21 @@ export async function GET(request: Request, context: { params: { id: string } })
|
||||
}
|
||||
|
||||
if (kategori == "jumlah") {
|
||||
const tahunFilter = new Date().getFullYear().toString();
|
||||
const startTahun = new Date(`${tahunFilter}-01-01T00:00:00.000Z`);
|
||||
const endTahun = new Date(`${parseInt(tahunFilter) + 1}-01-01T00:00:00.000Z`);
|
||||
|
||||
const tugas = await prisma.divisionProject.count({
|
||||
where: {
|
||||
idDivision: String(id),
|
||||
status: {
|
||||
lte: 1
|
||||
},
|
||||
isActive: true
|
||||
isActive: true,
|
||||
createdAt: {
|
||||
gte: startTahun,
|
||||
lt: endTahun
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ export async function GET(request: Request) {
|
||||
const name = searchParams.get('search');
|
||||
const status = searchParams.get('status');
|
||||
const idGroup = searchParams.get("group");
|
||||
const tahun = searchParams.get("year");
|
||||
const page = searchParams.get('page');
|
||||
const kategori = searchParams.get('cat');
|
||||
const user = searchParams.get('user');
|
||||
@@ -30,6 +31,9 @@ export async function GET(request: Request) {
|
||||
const roleUser = userMobile.idUserRole
|
||||
const villageId = userMobile.idVillage
|
||||
const userId = userMobile.id
|
||||
const tahunFilter = tahun ? tahun : new Date().getFullYear().toString();
|
||||
const startTahun = new Date(`${tahunFilter}-01-01T00:00:00.000Z`);
|
||||
const endTahun = new Date(`${parseInt(tahunFilter) + 1}-01-01T00:00:00.000Z`);
|
||||
|
||||
if (idGroup == "null" || idGroup == undefined || idGroup == "" || idGroup == "undefined") {
|
||||
grup = userMobile.idGroup
|
||||
@@ -58,7 +62,11 @@ export async function GET(request: Request) {
|
||||
contains: (name == undefined || name == "null") ? "" : name,
|
||||
mode: "insensitive"
|
||||
},
|
||||
status: (status == "0" || status == "1" || status == "2" || status == "3") ? Number(status) : 0
|
||||
status: (status == "0" || status == "1" || status == "2" || status == "3") ? Number(status) : 0,
|
||||
createdAt: {
|
||||
gte: startTahun,
|
||||
lt: endTahun
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -78,6 +86,10 @@ export async function GET(request: Request) {
|
||||
some: {
|
||||
idUser: String(userId)
|
||||
}
|
||||
},
|
||||
createdAt: {
|
||||
gte: startTahun,
|
||||
lt: endTahun
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
41
src/app/api/mobile/project/tahun/route.ts
Normal file
41
src/app/api/mobile/project/tahun/route.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { prisma } from "@/module/_global";
|
||||
import { funGetUserById } from "@/module/auth";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const user = searchParams.get('user');
|
||||
const userMobile = await funGetUserById({ id: String(user) })
|
||||
|
||||
if (userMobile.id == "null" || userMobile.id == undefined || userMobile.id == "") {
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 200 });
|
||||
}
|
||||
|
||||
const villageId = userMobile.idVillage
|
||||
const currentYear = new Date().getFullYear();
|
||||
|
||||
const data = await prisma.project.findMany({
|
||||
where: {
|
||||
isActive: true,
|
||||
idVillage: villageId,
|
||||
},
|
||||
select: {
|
||||
createdAt: true,
|
||||
},
|
||||
})
|
||||
|
||||
const dataYear = data.map((item: any) => item.createdAt.getFullYear())
|
||||
// Hapus duplikat pakai Set
|
||||
const uniqueYears = [...new Set(dataYear)];
|
||||
|
||||
// Tambahkan tahun sekarang kalau belum ada
|
||||
if (!uniqueYears.includes(currentYear)) {
|
||||
uniqueYears.push(currentYear);
|
||||
}
|
||||
|
||||
// (opsional) urutkan dari terbaru ke lama
|
||||
uniqueYears.sort((a, b) => b - a);
|
||||
|
||||
return NextResponse.json({ success: true, message: "Success", data: uniqueYears }, { status: 200 });
|
||||
}
|
||||
|
||||
@@ -16,6 +16,11 @@ export async function GET(request: Request) {
|
||||
const page = searchParams.get('page');
|
||||
const user = searchParams.get('user');
|
||||
const dataSkip = Number(page) * 10 - 10;
|
||||
const tahun = searchParams.get("year");
|
||||
|
||||
const tahunFilter = tahun ? tahun : new Date().getFullYear().toString();
|
||||
const startTahun = new Date(`${tahunFilter}-01-01T00:00:00.000Z`);
|
||||
const endTahun = new Date(`${parseInt(tahunFilter) + 1}-01-01T00:00:00.000Z`);
|
||||
|
||||
const userMobile = await funGetUserById({ id: String(user) })
|
||||
if (userMobile.id == "null" || userMobile.id == undefined || userMobile.id == "") {
|
||||
@@ -43,6 +48,10 @@ export async function GET(request: Request) {
|
||||
title: {
|
||||
contains: (name == undefined || name == "null") ? "" : name,
|
||||
mode: "insensitive"
|
||||
},
|
||||
createdAt: {
|
||||
gte: startTahun,
|
||||
lt: endTahun
|
||||
}
|
||||
},
|
||||
select: {
|
||||
@@ -87,6 +96,10 @@ export async function GET(request: Request) {
|
||||
title: {
|
||||
contains: (name == undefined || name == "null") ? "" : name,
|
||||
mode: "insensitive"
|
||||
},
|
||||
createdAt: {
|
||||
gte: startTahun,
|
||||
lt: endTahun
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
41
src/app/api/mobile/task/tahun/route.ts
Normal file
41
src/app/api/mobile/task/tahun/route.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { prisma } from "@/module/_global";
|
||||
import { funGetUserById } from "@/module/auth";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const user = searchParams.get('user');
|
||||
const divisi = searchParams.get('division');
|
||||
const userMobile = await funGetUserById({ id: String(user) })
|
||||
const currentYear = new Date().getFullYear();
|
||||
|
||||
if (userMobile.id == "null" || userMobile.id == undefined || userMobile.id == "") {
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 200 });
|
||||
}
|
||||
|
||||
const data = await prisma.divisionProject.findMany({
|
||||
where: {
|
||||
isActive: true,
|
||||
idDivision: String(divisi),
|
||||
},
|
||||
select: {
|
||||
createdAt: true,
|
||||
},
|
||||
})
|
||||
|
||||
const dataYear = data.map((item: any) => item.createdAt.getFullYear())
|
||||
// Hapus duplikat pakai Set
|
||||
const uniqueYears = [...new Set(dataYear)];
|
||||
|
||||
// Tambahkan tahun sekarang kalau belum ada
|
||||
if (!uniqueYears.includes(currentYear)) {
|
||||
uniqueYears.push(currentYear);
|
||||
}
|
||||
|
||||
// (opsional) urutkan dari terbaru ke lama
|
||||
uniqueYears.sort((a, b) => b - a);
|
||||
|
||||
|
||||
return NextResponse.json({ success: true, message: "Success", data: uniqueYears }, { status: 200 });
|
||||
|
||||
}
|
||||
@@ -8,15 +8,7 @@
|
||||
"gender": "F"
|
||||
},
|
||||
{
|
||||
"id": "devLukman",
|
||||
"idAdminRole": "dev",
|
||||
"name": "Lukman",
|
||||
"phone": "6287701790942",
|
||||
"email": "lukman@bip.com",
|
||||
"gender": "M"
|
||||
},
|
||||
{
|
||||
"id": "devLukman",
|
||||
"id": "devMalik",
|
||||
"idAdminRole": "dev",
|
||||
"name": "Malik",
|
||||
"phone": "6289697338821",
|
||||
|
||||
Reference in New Issue
Block a user