#Job admin
- Tampilan user done - Tampilan admin done git commit -m
This commit is contained in:
67
src/app_modules/job/fun/create/fun_create.ts
Normal file
67
src/app_modules/job/fun/create/fun_create.ts
Normal file
@@ -0,0 +1,67 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { User_getUserId } from "@/app_modules/fun_global/get_user_token";
|
||||
import _ from "lodash";
|
||||
import { v4 } from "uuid";
|
||||
import fs from "fs";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { MODEL_JOB } from "../../model/interface";
|
||||
|
||||
export async function Job_funCreate(req: MODEL_JOB, file: FormData) {
|
||||
const authorId = await User_getUserId();
|
||||
|
||||
const dataImage: any = file.get("file");
|
||||
if (dataImage !== "null") {
|
||||
const fileName = dataImage.name;
|
||||
const fileExtension = _.lowerCase(dataImage.name.split(".").pop());
|
||||
const fRandomName = v4(fileName) + "." + fileExtension;
|
||||
|
||||
const upload = await prisma.images.create({
|
||||
data: {
|
||||
url: fRandomName,
|
||||
label: "JOB",
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
url: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!upload) return { status: 400, message: "Gagal upload gambar" };
|
||||
const uploadFolder = Buffer.from(await dataImage.arrayBuffer());
|
||||
fs.writeFileSync(`./public/job/${upload.url}`, uploadFolder);
|
||||
const create = await prisma.job.create({
|
||||
data: {
|
||||
title: req.title,
|
||||
content: req.content,
|
||||
deskripsi: req.deskripsi,
|
||||
authorId: authorId,
|
||||
imagesId: upload.id,
|
||||
},
|
||||
});
|
||||
|
||||
if (!create) return { status: 400, message: "Gagal Disimpan" };
|
||||
revalidatePath("/dev/job/main/status");
|
||||
return {
|
||||
status: 201,
|
||||
message: "Berhasil Disimpan",
|
||||
};
|
||||
} else {
|
||||
const create = await prisma.job.create({
|
||||
data: {
|
||||
title: req.title,
|
||||
content: req.content,
|
||||
deskripsi: req.deskripsi,
|
||||
authorId: authorId,
|
||||
},
|
||||
});
|
||||
|
||||
if (!create) return { status: 400, message: "Gagal Disimpan" };
|
||||
revalidatePath("/dev/job/main/status");
|
||||
return {
|
||||
status: 201,
|
||||
message: "Berhasil Disimpan",
|
||||
};
|
||||
}
|
||||
}
|
||||
19
src/app_modules/job/fun/delete/fun_delete_by_id.ts
Normal file
19
src/app_modules/job/fun/delete/fun_delete_by_id.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { revalidatePath } from "next/cache";
|
||||
|
||||
export async function Job_funDeleteById(jobId: string) {
|
||||
const del = await prisma.job.update({
|
||||
where: {
|
||||
id: jobId,
|
||||
},
|
||||
data: {
|
||||
isActive: false,
|
||||
},
|
||||
});
|
||||
|
||||
if (!del) return { status: 400, message: "Gagal hapus" };
|
||||
revalidatePath("/dev/job/main/status");
|
||||
return { status: 200, message: "Berhasil hapus" };
|
||||
}
|
||||
21
src/app_modules/job/fun/edit/fun_edit_arsip_by_id.ts
Normal file
21
src/app_modules/job/fun/edit/fun_edit_arsip_by_id.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { revalidatePath } from "next/cache";
|
||||
|
||||
export async function Job_funEditArsipById(jobId: string, aktifasi: boolean) {
|
||||
const updt = await prisma.job.update({
|
||||
where: {
|
||||
id: jobId,
|
||||
},
|
||||
data: {
|
||||
isArsip: aktifasi,
|
||||
},
|
||||
});
|
||||
if (!updt) return { status: 400, message: "Gagal Arsip" };
|
||||
|
||||
revalidatePath("/dev/job/main/arsip");
|
||||
revalidatePath("/dev/job/main/status");
|
||||
revalidatePath("/dev/job/main/beranda");
|
||||
return { status: 200, message: "Berhasil Arsip" };
|
||||
}
|
||||
73
src/app_modules/job/fun/edit/fun_edit_by_id.ts
Normal file
73
src/app_modules/job/fun/edit/fun_edit_by_id.ts
Normal file
@@ -0,0 +1,73 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import _ from "lodash";
|
||||
import { v4 } from "uuid";
|
||||
import fs from "fs";
|
||||
import { MODEL_JOB } from "../../model/interface";
|
||||
import { revalidatePath } from "next/cache";
|
||||
|
||||
export async function Job_EditById(req: MODEL_JOB, file: FormData) {
|
||||
// console.log(file);
|
||||
// console.log(req);
|
||||
// return { status: 200 };
|
||||
|
||||
const dataImage: any = file.get("file");
|
||||
if (dataImage !== "null") {
|
||||
const fileName = dataImage.name;
|
||||
const fileExtension = _.lowerCase(dataImage.name.split(".").pop());
|
||||
const fRandomName = v4(fileName) + "." + fileExtension;
|
||||
|
||||
const upload = await prisma.images.create({
|
||||
data: {
|
||||
url: fRandomName,
|
||||
label: "JOB",
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
url: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!upload) return { status: 400, message: "Gagal upload gambar" };
|
||||
const uploadFolder = Buffer.from(await dataImage.arrayBuffer());
|
||||
fs.writeFileSync(`./public/job/${upload.url}`, uploadFolder);
|
||||
|
||||
const updt = await prisma.job.update({
|
||||
where: {
|
||||
id: req.id,
|
||||
},
|
||||
data: {
|
||||
title: req.title,
|
||||
content: req.content,
|
||||
deskripsi: req.deskripsi,
|
||||
imagesId: upload.id,
|
||||
},
|
||||
});
|
||||
|
||||
if (!updt) return { status: 400, message: "Gagal Update" };
|
||||
revalidatePath("/dev/job/detail/draft");
|
||||
return {
|
||||
status: 200,
|
||||
message: "Berhasil Disimpan",
|
||||
};
|
||||
} else {
|
||||
const updt = await prisma.job.update({
|
||||
where: {
|
||||
id: req.id,
|
||||
},
|
||||
data: {
|
||||
title: req.title,
|
||||
content: req.content,
|
||||
deskripsi: req.deskripsi,
|
||||
},
|
||||
});
|
||||
|
||||
if (!updt) return { status: 400, message: "Gagal Update" };
|
||||
revalidatePath("/dev/job/detail/draft");
|
||||
return {
|
||||
status: 200,
|
||||
message: "Berhasil Disimpan",
|
||||
};
|
||||
}
|
||||
}
|
||||
22
src/app_modules/job/fun/edit/fun_edit_status_by_status_id.ts
Normal file
22
src/app_modules/job/fun/edit/fun_edit_status_by_status_id.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { revalidatePath } from "next/cache";
|
||||
|
||||
export async function Job_funEditStatusByStatusId(
|
||||
jobId: string,
|
||||
statusId: string
|
||||
) {
|
||||
const updt = await prisma.job.update({
|
||||
where: {
|
||||
id: jobId,
|
||||
},
|
||||
data: {
|
||||
masterStatusId: statusId,
|
||||
},
|
||||
});
|
||||
|
||||
if (!updt) return { status: 400, message: "Gagal ganti status" };
|
||||
revalidatePath("/dev/job/main/status");
|
||||
return { status: 200, message: "Berhasil ganti status" };
|
||||
}
|
||||
17
src/app_modules/job/fun/get/get_list_all_arsip.ts
Normal file
17
src/app_modules/job/fun/get/get_list_all_arsip.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { User_getUserId } from "@/app_modules/fun_global/get_user_token";
|
||||
|
||||
export async function Job_getListAllArsipById() {
|
||||
const authorId = await User_getUserId();
|
||||
|
||||
const get = await prisma.job.findMany({
|
||||
where: {
|
||||
authorId: authorId,
|
||||
isArsip: true,
|
||||
},
|
||||
});
|
||||
|
||||
return get;
|
||||
}
|
||||
28
src/app_modules/job/fun/get/get_list_all_publish.ts
Normal file
28
src/app_modules/job/fun/get/get_list_all_publish.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { User_getUserId } from "@/app_modules/fun_global/get_user_token";
|
||||
|
||||
export async function Job_getAllListPublish() {
|
||||
const data = await prisma.job.findMany({
|
||||
orderBy: {
|
||||
updatedAt: "desc",
|
||||
},
|
||||
where: {
|
||||
masterStatusId: "1",
|
||||
isActive: true,
|
||||
isArsip: false,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
Author: {
|
||||
select: {
|
||||
Profile: true
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return data;
|
||||
}
|
||||
68
src/app_modules/job/fun/get/get_list_status_by_status_id.ts
Normal file
68
src/app_modules/job/fun/get/get_list_status_by_status_id.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { User_getUserId } from "@/app_modules/fun_global/get_user_token";
|
||||
|
||||
export async function Job_getListStatusByStatusId(statusId: string) {
|
||||
const authorId = await User_getUserId();
|
||||
if (statusId === "1") {
|
||||
const data = await prisma.job.findMany({
|
||||
orderBy: {
|
||||
updatedAt: "desc",
|
||||
},
|
||||
where: {
|
||||
masterStatusId: "1",
|
||||
authorId: authorId,
|
||||
isActive: true,
|
||||
isArsip: false
|
||||
},
|
||||
});
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
if (statusId === "2") {
|
||||
const data = await prisma.job.findMany({
|
||||
orderBy: {
|
||||
updatedAt: "desc",
|
||||
},
|
||||
where: {
|
||||
masterStatusId: "2",
|
||||
authorId: authorId,
|
||||
isActive: true,
|
||||
},
|
||||
});
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
if (statusId === "3") {
|
||||
const data = await prisma.job.findMany({
|
||||
orderBy: {
|
||||
updatedAt: "desc",
|
||||
},
|
||||
where: {
|
||||
masterStatusId: "3",
|
||||
authorId: authorId,
|
||||
isActive: true,
|
||||
},
|
||||
});
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
if (statusId === "4") {
|
||||
const data = await prisma.job.findMany({
|
||||
orderBy: {
|
||||
updatedAt: "desc",
|
||||
},
|
||||
where: {
|
||||
masterStatusId: "4",
|
||||
authorId: authorId,
|
||||
isActive: true,
|
||||
},
|
||||
});
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
13
src/app_modules/job/fun/get/get_one_by_id.ts
Normal file
13
src/app_modules/job/fun/get/get_one_by_id.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
|
||||
export async function Job_getOneById(jobId: any) {
|
||||
const get = await prisma.job.findFirst({
|
||||
where: {
|
||||
id: jobId,
|
||||
},
|
||||
});
|
||||
|
||||
return get;
|
||||
}
|
||||
Reference in New Issue
Block a user