Merge pull request 'upd: api mobile revisi' (#14) from amalia/23-feb-26 into join
Reviewed-on: #14
This commit is contained in:
@@ -167,12 +167,19 @@ export async function DELETE(request: Request, context: { params: { id: string }
|
||||
// EDIT PENGUMUMAN
|
||||
export async function PUT(request: Request, context: { params: { id: string } }) {
|
||||
try {
|
||||
const body = await request.formData()
|
||||
const dataBody = body.get("data")
|
||||
const cekFile = body.has("file0")
|
||||
const contentType = request.headers.get("content-type");
|
||||
let title, desc, groups, user, oldFile: any[] = [], cekFile, body: FormData | undefined
|
||||
|
||||
if (contentType?.includes("multipart/form-data")) {
|
||||
body = await request.formData()
|
||||
const dataBody = body.get("data")
|
||||
cekFile = body.has("file0");
|
||||
({ title, desc, groups, user, oldFile } = JSON.parse(dataBody as string))
|
||||
} else {
|
||||
({ title, desc, groups, user } = await request.json());
|
||||
}
|
||||
|
||||
|
||||
// const { title, desc, groups, user } = (await request.json());
|
||||
const { title, desc, groups, user, oldFile } = JSON.parse(dataBody as string)
|
||||
const { id } = context.params;
|
||||
const userMobile = await funGetUserById({ id: String(user) })
|
||||
|
||||
@@ -245,7 +252,7 @@ export async function PUT(request: Request, context: { params: { id: string } })
|
||||
}
|
||||
}
|
||||
|
||||
if (cekFile) {
|
||||
if (cekFile && body) {
|
||||
body.delete("data")
|
||||
for (var pair of body.entries()) {
|
||||
if (String(pair[0]).substring(0, 4) == "file") {
|
||||
|
||||
@@ -113,12 +113,19 @@ export async function GET(request: Request) {
|
||||
// CREATE PENGUMUMAN
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const body = await request.formData()
|
||||
const dataBody = body.get("data")
|
||||
const cekFile = body.has("file0")
|
||||
const contentType = request.headers.get("content-type");
|
||||
|
||||
let title, desc, groups, user, cekFile, body: FormData | undefined
|
||||
if (contentType?.includes("multipart/form-data")) {
|
||||
body = await request.formData()
|
||||
const dataBody = body.get("data")
|
||||
cekFile = body.has("file0");
|
||||
({ title, desc, groups, user } = JSON.parse(dataBody as string))
|
||||
} else {
|
||||
({ title, desc, groups, user } = await request.json());
|
||||
}
|
||||
|
||||
|
||||
// const { title, desc, groups, user } = (await request.json());
|
||||
const { title, desc, groups, user } = JSON.parse(dataBody as string)
|
||||
const userMobile = await funGetUserById({ id: String(user) })
|
||||
|
||||
if (userMobile.id == "null" || userMobile.id == undefined || userMobile.id == "") {
|
||||
@@ -144,7 +151,6 @@ export async function POST(request: Request) {
|
||||
let memberDivision = []
|
||||
|
||||
for (var i = 0, l = groups.length; i < l; i++) {
|
||||
2
|
||||
var obj = groups[i].Division;
|
||||
for (let index = 0; index < obj.length; index++) {
|
||||
const element = obj[index];
|
||||
@@ -158,7 +164,7 @@ export async function POST(request: Request) {
|
||||
}
|
||||
|
||||
|
||||
if (cekFile) {
|
||||
if (cekFile && body) {
|
||||
body.delete("data")
|
||||
for (var pair of body.entries()) {
|
||||
if (String(pair[0]).substring(0, 4) == "file") {
|
||||
@@ -247,7 +253,7 @@ export async function POST(request: Request) {
|
||||
where: {
|
||||
isActive: true,
|
||||
idUserRole: "supadmin",
|
||||
idVillage: user.idVillage
|
||||
idVillage: String(villaId)
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
|
||||
@@ -242,10 +242,10 @@ export async function DELETE(request: Request, context: { params: { id: string }
|
||||
// create log user
|
||||
if (active) {
|
||||
const log = await createLogUserMobile({ act: 'DELETE', desc: 'User mengaktifkan data diskusi umum', table: 'disscussion', data: id, user: userMobile.id })
|
||||
return NextResponse.json({ success: true, message: "Berhasil mengaktifkan diskusi umum", user: user.id }, { status: 200 });
|
||||
return NextResponse.json({ success: true, message: "Berhasil mengaktifkan diskusi umum" }, { status: 200 });
|
||||
} else {
|
||||
const log = await createLogUserMobile({ act: 'DELETE', desc: 'User mengarsipkan data diskusi umum', table: 'disscussion', data: id, user: userMobile.id })
|
||||
return NextResponse.json({ success: true, message: "Berhasil mengarsipkan diskusi umum", user: user.id }, { status: 200 });
|
||||
return NextResponse.json({ success: true, message: "Berhasil mengarsipkan diskusi umum" }, { status: 200 });
|
||||
}
|
||||
|
||||
|
||||
@@ -260,12 +260,19 @@ export async function DELETE(request: Request, context: { params: { id: string }
|
||||
export async function PUT(request: Request, context: { params: { id: string } }) {
|
||||
try {
|
||||
const { id } = context.params
|
||||
const body = await request.formData()
|
||||
const dataBody = body.get("data")
|
||||
const cekFile = body.has("file0")
|
||||
const contentType = request.headers.get("content-type");
|
||||
|
||||
let title, desc, user, oldFile: any[] = [], cekFile, body: FormData | undefined
|
||||
|
||||
if (contentType?.includes("multipart/form-data")) {
|
||||
body = await request.formData()
|
||||
const dataBody = body.get("data")
|
||||
cekFile = body.has("file0");
|
||||
({ title, desc, user, oldFile } = JSON.parse(dataBody as string))
|
||||
} else {
|
||||
({ title, desc, user } = await request.json());
|
||||
}
|
||||
|
||||
// const { title, desc, user } = (await request.json());
|
||||
const { title, desc, user, oldFile } = JSON.parse(dataBody as string)
|
||||
|
||||
const userMobile = await funGetUserById({ id: String(user) })
|
||||
|
||||
@@ -306,7 +313,7 @@ export async function PUT(request: Request, context: { params: { id: string } })
|
||||
}
|
||||
}
|
||||
|
||||
if (cekFile) {
|
||||
if (cekFile && body) {
|
||||
body.delete("data")
|
||||
for (var pair of body.entries()) {
|
||||
if (String(pair[0]).substring(0, 4) == "file") {
|
||||
|
||||
@@ -109,16 +109,20 @@ export async function GET(request: Request) {
|
||||
|
||||
|
||||
|
||||
// CREATE DISCUSSION GENERALE
|
||||
// CREATE DISCUSSION GENERAL
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const contentType = request.headers.get("content-type");
|
||||
let idGroup, user, title, desc, member, cekFile, body: FormData | undefined
|
||||
if (contentType?.includes("multipart/form-data")) {
|
||||
body = await request.formData()
|
||||
const dataBody = body.get("data")
|
||||
cekFile = body.has("file0");
|
||||
({ idGroup, user, title, desc, member } = JSON.parse(dataBody as string))
|
||||
} else {
|
||||
({ idGroup, user, title, desc, member } = await request.json());
|
||||
}
|
||||
|
||||
const body = await request.formData()
|
||||
const dataBody = body.get("data")
|
||||
const cekFile = body.has("file0")
|
||||
|
||||
// const { idGroup, user, title, desc, member } = await request.json();
|
||||
const { idGroup, user, title, desc, member } = JSON.parse(dataBody as string)
|
||||
|
||||
const userMobile = await funGetUserById({ id: user })
|
||||
|
||||
@@ -153,7 +157,7 @@ export async function POST(request: Request) {
|
||||
})
|
||||
|
||||
|
||||
if (cekFile) {
|
||||
if (cekFile && body) {
|
||||
body.delete("data")
|
||||
for (var pair of body.entries()) {
|
||||
if (String(pair[0]).substring(0, 4) == "file") {
|
||||
@@ -213,7 +217,7 @@ export async function POST(request: Request) {
|
||||
where: {
|
||||
isActive: true,
|
||||
idUserRole: "supadmin",
|
||||
idVillage: user.idVillage
|
||||
idVillage: String(userMobile.idVillage)
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
|
||||
@@ -227,12 +227,18 @@ 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 body = await request.formData()
|
||||
const dataBody = body.get("data")
|
||||
const cekFile = body.has("file0")
|
||||
const contentType = request.headers.get("content-type");
|
||||
|
||||
// const { title, desc, user } = (await request.json())
|
||||
const { title, desc, user, oldFile } = JSON.parse(dataBody as string)
|
||||
let title, desc, user, oldFile: any[] = [], cekFile, body: FormData | undefined
|
||||
|
||||
if (contentType?.includes("multipart/form-data")) {
|
||||
body = await request.formData()
|
||||
const dataBody = body.get("data")
|
||||
cekFile = body.has("file0");
|
||||
({ title, desc, user, oldFile } = JSON.parse(dataBody as string))
|
||||
} else {
|
||||
({ title, desc, user } = await request.json());
|
||||
}
|
||||
|
||||
|
||||
const userMobile = await funGetUserById({ id: String(user) })
|
||||
@@ -273,7 +279,7 @@ export async function POST(request: Request, context: { params: { id: string } }
|
||||
}
|
||||
}
|
||||
|
||||
if (cekFile) {
|
||||
if (cekFile && body) {
|
||||
body.delete("data")
|
||||
for (var pair of body.entries()) {
|
||||
if (String(pair[0]).substring(0, 4) == "file") {
|
||||
|
||||
@@ -102,12 +102,17 @@ export async function GET(request: Request) {
|
||||
// CREATE DISCUSSION
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const body = await request.formData()
|
||||
const dataBody = body.get("data")
|
||||
const cekFile = body.has("file0")
|
||||
const contentType = request.headers.get("content-type");
|
||||
|
||||
// const { idDivision, desc, user } = (await request.json());
|
||||
const { idDivision, desc, user } = JSON.parse(String(dataBody));
|
||||
let idDivision, desc, user, cekFile, body: FormData | undefined
|
||||
if (contentType?.includes("multipart/form-data")) {
|
||||
body = await request.formData()
|
||||
const dataBody = body.get("data")
|
||||
cekFile = body.has("file0");
|
||||
({ idDivision, desc, user } = JSON.parse(String(dataBody)));
|
||||
} else {
|
||||
({ idDivision, desc, user } = await request.json());
|
||||
}
|
||||
|
||||
|
||||
const userMobile = await funGetUserById({ id: String(user) })
|
||||
@@ -143,7 +148,7 @@ export async function POST(request: Request) {
|
||||
});
|
||||
|
||||
|
||||
if (cekFile) {
|
||||
if (cekFile && body) {
|
||||
body.delete("data")
|
||||
for (var pair of body.entries()) {
|
||||
if (String(pair[0]).substring(0, 4) == "file") {
|
||||
|
||||
Reference in New Issue
Block a user