Merge pull request 'join' (#5) from join into staging
Reviewed-on: bip/sistem-desa-mandiri#5
This commit is contained in:
@@ -152,6 +152,7 @@ export async function GET(request: Request, context: { params: { id: string } })
|
|||||||
name: true,
|
name: true,
|
||||||
extension: true,
|
extension: true,
|
||||||
path: true,
|
path: true,
|
||||||
|
idStorage: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
createdAt: true
|
createdAt: true
|
||||||
@@ -166,13 +167,14 @@ export async function GET(request: Request, context: { params: { id: string } })
|
|||||||
id: v.DivisionDocumentFolderFile.id,
|
id: v.DivisionDocumentFolderFile.id,
|
||||||
name: v.DivisionDocumentFolderFile.name,
|
name: v.DivisionDocumentFolderFile.name,
|
||||||
extension: v.DivisionDocumentFolderFile.extension,
|
extension: v.DivisionDocumentFolderFile.extension,
|
||||||
|
idStorage: v.DivisionDocumentFolderFile.idStorage,
|
||||||
path: 'home',
|
path: 'home',
|
||||||
share: true
|
share: true
|
||||||
}))
|
}))
|
||||||
|
|
||||||
const dataDokumen = await prisma.divisionDocumentFolderFile.findMany({
|
const dataDokumen = await prisma.divisionDocumentFolderFile.findMany({
|
||||||
skip: 0,
|
skip: 0,
|
||||||
take: 5,
|
take: 4,
|
||||||
where: {
|
where: {
|
||||||
idDivision: String(id),
|
idDivision: String(id),
|
||||||
isActive: true,
|
isActive: true,
|
||||||
@@ -183,7 +185,8 @@ export async function GET(request: Request, context: { params: { id: string } })
|
|||||||
name: true,
|
name: true,
|
||||||
extension: true,
|
extension: true,
|
||||||
path: true,
|
path: true,
|
||||||
createdAt: true
|
createdAt: true,
|
||||||
|
idStorage: true
|
||||||
},
|
},
|
||||||
orderBy: {
|
orderBy: {
|
||||||
createdAt: "desc"
|
createdAt: "desc"
|
||||||
@@ -200,6 +203,7 @@ export async function GET(request: Request, context: { params: { id: string } })
|
|||||||
}
|
}
|
||||||
|
|
||||||
allData = _.orderBy(fixData, ['createdAt'], ['desc']);
|
allData = _.orderBy(fixData, ['createdAt'], ['desc']);
|
||||||
|
allData.slice(0, 4)
|
||||||
|
|
||||||
} else if (kategori == "new-discussion") {
|
} else if (kategori == "new-discussion") {
|
||||||
const diskusi = await prisma.divisionDisscussion.findMany({
|
const diskusi = await prisma.divisionDisscussion.findMany({
|
||||||
|
|||||||
@@ -10,8 +10,6 @@ export async function POST(request: Request) {
|
|||||||
try {
|
try {
|
||||||
const body = await request.formData()
|
const body = await request.formData()
|
||||||
const dataBody = body.get("data")
|
const dataBody = body.get("data")
|
||||||
const file = body.get("file") as File
|
|
||||||
const fileName = file.name
|
|
||||||
|
|
||||||
const { idPath, idDivision, user } = JSON.parse(dataBody as string)
|
const { idPath, idDivision, user } = JSON.parse(dataBody as string)
|
||||||
|
|
||||||
@@ -57,39 +55,48 @@ export async function POST(request: Request) {
|
|||||||
..._.omit(v, [""]),
|
..._.omit(v, [""]),
|
||||||
file: v.name + '.' + v.extension,
|
file: v.name + '.' + v.extension,
|
||||||
}))
|
}))
|
||||||
|
let failed = 0
|
||||||
const cek = dataOmit.some((i: any) => i.file == fileName)
|
body.delete("data")
|
||||||
|
for (var pair of body.entries()) {
|
||||||
if (cek) {
|
if (String(pair[0]).substring(0, 4) == "file") {
|
||||||
return NextResponse.json({ success: false, message: "Terdapat file dengan nama yang sama" }, { status: 200 });
|
const file = body.get(pair[0]) as File
|
||||||
}
|
const fileName = file.name
|
||||||
|
const fExt = file.name.split(".").pop()
|
||||||
|
let fName = file.name.replace("." + fExt, "")
|
||||||
const fExt = file.name.split(".").pop()
|
const cek = dataOmit.some((i: any) => i.file == fileName)
|
||||||
const fName = file.name.replace("." + fExt, "")
|
if (cek) {
|
||||||
const upload = await funUploadFile({ file: file, dirId: DIR.document })
|
const random = Math.floor(Math.random() * 1000)
|
||||||
if (upload.success) {
|
fName = `${fName}_${random}`
|
||||||
const dataInsert = await prisma.divisionDocumentFolderFile.create({
|
|
||||||
data: {
|
|
||||||
name: fName,
|
|
||||||
path: idPath,
|
|
||||||
idDivision,
|
|
||||||
category: "FILE",
|
|
||||||
extension: String(fExt),
|
|
||||||
createdBy: userMobile.id,
|
|
||||||
idStorage: upload.data.id
|
|
||||||
},
|
|
||||||
select: {
|
|
||||||
id: true
|
|
||||||
}
|
}
|
||||||
});
|
const upload = await funUploadFile({ file: file, dirId: DIR.document })
|
||||||
|
if (upload.success) {
|
||||||
|
const dataInsert = await prisma.divisionDocumentFolderFile.create({
|
||||||
|
data: {
|
||||||
|
name: fName,
|
||||||
|
path: idPath,
|
||||||
|
idDivision,
|
||||||
|
category: "FILE",
|
||||||
|
extension: String(fExt),
|
||||||
|
createdBy: userMobile.id,
|
||||||
|
idStorage: upload.data.id
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// create log user
|
// create log user
|
||||||
const log = await createLogUserMobile({ act: 'CREATE', desc: 'User mengupload file baru', table: 'divisionDocumentFolderFile', data: dataInsert.id, user: userMobile.id })
|
const log = await createLogUserMobile({ act: 'CREATE', desc: 'User mengupload file baru', table: 'divisionDocumentFolderFile', data: dataInsert.id, user: userMobile.id })
|
||||||
return NextResponse.json({ success: true, message: "Berhasil upload file" }, { status: 200 });
|
} else {
|
||||||
} else {
|
failed++
|
||||||
return NextResponse.json({ success: false, message: "Gagal upload file, coba lagi nanti" }, { status: 200 });
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (failed > 0) {
|
||||||
|
return NextResponse.json({ success: false, message: "Beberapa file gagal diupload", failed }, { status: 200 });
|
||||||
|
}
|
||||||
|
return NextResponse.json({ success: true, message: "Berhasil upload file" }, { status: 200 });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
return NextResponse.json({ success: false, message: "Gagal upload file, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 });
|
return NextResponse.json({ success: false, message: "Gagal upload file, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 });
|
||||||
|
|||||||
@@ -81,8 +81,8 @@ export async function GET(request: Request, context: { params: { id: string } })
|
|||||||
dateEnd: moment(v.dateEnd).format("DD-MM-YYYY"),
|
dateEnd: moment(v.dateEnd).format("DD-MM-YYYY"),
|
||||||
createdAt: moment(v.createdAt).format("DD-MM-YYYY HH:mm"),
|
createdAt: moment(v.createdAt).format("DD-MM-YYYY HH:mm"),
|
||||||
}))
|
}))
|
||||||
const dataFix = _.orderBy(formatData, 'createdAt', 'asc')
|
// const dataFix = _.orderBy(formatData, 'createdAt', 'asc')
|
||||||
allData = dataFix
|
allData = formatData
|
||||||
|
|
||||||
} else if (kategori == "file") {
|
} else if (kategori == "file") {
|
||||||
const dataFile = await prisma.projectFile.findMany({
|
const dataFile = await prisma.projectFile.findMany({
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { NextResponse } from "next/server";
|
|||||||
|
|
||||||
export async function GET(request: Request) {
|
export async function GET(request: Request) {
|
||||||
try {
|
try {
|
||||||
return NextResponse.json({ success: true, version: "1.5.6", tahap: "beta", update: "-fix mobile api" }, { status: 200 });
|
return NextResponse.json({ success: true, version: "1.5.7", tahap: "beta", update: "-fix mobile api" }, { status: 200 });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
return NextResponse.json({ success: false, version: "Gagal mendapatkan version, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 });
|
return NextResponse.json({ success: false, version: "Gagal mendapatkan version, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 });
|
||||||
|
|||||||
@@ -23,8 +23,6 @@ export function countTime(date: Date) {
|
|||||||
return `${hours} jam`
|
return `${hours} jam`
|
||||||
} else if (minutes > 0) {
|
} else if (minutes > 0) {
|
||||||
return `${minutes} mnt`
|
return `${minutes} mnt`
|
||||||
} else if (seconds > 10) {
|
|
||||||
return `${seconds} dtk`
|
|
||||||
} else {
|
} else {
|
||||||
return `baru saja`
|
return `baru saja`
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user