feat:add candidate pages
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
import prisma from "../prisma/client.js";
|
||||
|
||||
import { sendEmail } from "../utils/sendEmail.js";
|
||||
import { getEmailsByType } from "../utils/getEmailByTypes.js";
|
||||
|
||||
// CREATE CANDIDATE
|
||||
|
||||
export const createCandidate = async (req, res) => {
|
||||
try {
|
||||
const {fullName, mobile, email, subject, coverLetter, careerId} = req.body;
|
||||
const { fullName, mobile, email, subject, coverLetter, careerId } =
|
||||
req.body;
|
||||
|
||||
if (!fullName || !mobile || !email || !careerId) {
|
||||
return res.status(400).json({
|
||||
@@ -22,8 +26,38 @@ export const createCandidate = async (req, res) => {
|
||||
coverLetter,
|
||||
careerId: Number(careerId),
|
||||
},
|
||||
include: {
|
||||
career: true,
|
||||
},
|
||||
});
|
||||
|
||||
try {
|
||||
const emailList = await getEmailsByType("CANDIDATE");
|
||||
|
||||
if (emailList && emailList.length > 0) {
|
||||
await sendEmail({
|
||||
to: emailList,
|
||||
subject: "New Job Application Received",
|
||||
html: `
|
||||
<h2>New Candidate Application</h2>
|
||||
|
||||
<p><b>Name:</b> ${fullName}</p>
|
||||
<p><b>Phone:</b> ${mobile}</p>
|
||||
<p><b>Email:</b> ${email}</p>
|
||||
|
||||
<p><b>Applied For:</b> ${candidate.career?.post || "-"}</p>
|
||||
<p><b>Designation:</b> ${candidate.career?.designation || "-"}</p>
|
||||
|
||||
<p><b>Subject:</b> ${subject || "-"}</p>
|
||||
<p><b>Cover Letter:</b></p>
|
||||
<p>${coverLetter || "-"}</p>
|
||||
`,
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("Candidate email failed:", err);
|
||||
}
|
||||
|
||||
res.status(201).json({
|
||||
success: true,
|
||||
message: "Application submitted successfully",
|
||||
@@ -68,7 +102,7 @@ export const getCandidates = async (req, res) => {
|
||||
|
||||
export const getCandidate = async (req, res) => {
|
||||
try {
|
||||
const {id} = req.params;
|
||||
const { id } = req.params;
|
||||
|
||||
const candidate = await prisma.candidate.findUnique({
|
||||
where: {
|
||||
@@ -103,7 +137,7 @@ export const getCandidate = async (req, res) => {
|
||||
|
||||
export const getCandidatesByCareer = async (req, res) => {
|
||||
try {
|
||||
const {careerId} = req.params;
|
||||
const { careerId } = req.params;
|
||||
|
||||
const candidates = await prisma.candidate.findMany({
|
||||
where: {
|
||||
@@ -134,7 +168,7 @@ export const getCandidatesByCareer = async (req, res) => {
|
||||
|
||||
export const updateCandidate = async (req, res) => {
|
||||
try {
|
||||
const {id} = req.params;
|
||||
const { id } = req.params;
|
||||
|
||||
const candidate = await prisma.candidate.update({
|
||||
where: {
|
||||
@@ -161,7 +195,7 @@ export const updateCandidate = async (req, res) => {
|
||||
|
||||
export const deleteCandidate = async (req, res) => {
|
||||
try {
|
||||
const {id} = req.params;
|
||||
const { id } = req.params;
|
||||
|
||||
await prisma.candidate.delete({
|
||||
where: {
|
||||
|
||||
Reference in New Issue
Block a user