This commit is contained in:
2026-05-07 23:18:34 +02:00
commit 07c58f23ab
39 changed files with 6044 additions and 0 deletions

39
backend/routes/offer.js Normal file
View File

@@ -0,0 +1,39 @@
import { prisma } from '../prisma.js'
export const createOffer = async (req, res) => {
const { titulo, empresa, ubicacion, salario, contrato, descripcion } = req.body;
const authorId = req.user.id
if (!titulo || !empresa || !ubicacion || !salario || !contrato || !descripcion) return res.status(400).json({ error: ""})
try {
const offer = await prisma.oferta.create({
data: {
titulo, empresa, ubicacion, salario, descripcion
}
})
res.status(201).json(offer)
} catch (err) {
res.status(400).json({ error: "Ha ocurrido un error al crear la oferta de trabajo." })
}
}
export const deleteOffer = async (req, res) => {
const { offerId } = req.params;
const authorId = req.user.id;
const id = parseInt(offerId)
try {
const offer = await prisma.offer.findFirst({ where: { id }})
if (!offer) return res.status(404).json({ error: "Invalid project" })
if (authorId !== offer.authorId) return res.status(403).json({ error: "Missing permissions" })
await prisma.offer.delete({ where: { id } })
res.status(200).json({ message: "Project has been deleted" })
} catch (err) {
res.status(400).json({ error: "Ha ocurrido un error al borrar el proyecto" })
}
}