phase 1 backend
This commit is contained in:
parent
a0897c2d38
commit
9653e55453
26 changed files with 3225 additions and 0 deletions
71
backend/dist/controllers/jobSearchController.js
vendored
Normal file
71
backend/dist/controllers/jobSearchController.js
vendored
Normal file
|
@ -0,0 +1,71 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.searchLocalJobOffers = void 0;
|
||||
const client_1 = require("@prisma/client");
|
||||
const prisma = new client_1.PrismaClient();
|
||||
const searchLocalJobOffers = async (req, res) => {
|
||||
try {
|
||||
const page = parseInt(req.query.page) || 1;
|
||||
const limit = parseInt(req.query.limit) || 10;
|
||||
const skip = (page - 1) * limit;
|
||||
const take = limit;
|
||||
const sortBy = req.query.sortBy || 'publicationDate';
|
||||
const sortOrder = req.query.sortOrder || 'desc';
|
||||
const keyword = req.query.keyword;
|
||||
const location = req.query.location;
|
||||
const contractType = req.query.contractType;
|
||||
console.log('Keyword:', keyword);
|
||||
console.log('Location:', location);
|
||||
const where = {};
|
||||
if (keyword) {
|
||||
where.OR = [
|
||||
{ title: { contains: keyword, mode: 'insensitive' } },
|
||||
{ description: { contains: keyword, mode: 'insensitive' } },
|
||||
];
|
||||
}
|
||||
if (location) {
|
||||
where.AND = [
|
||||
...(where.AND || []),
|
||||
{
|
||||
OR: [
|
||||
{ locationLabel: { contains: location, mode: 'insensitive' } },
|
||||
{ postalCode: { contains: location, mode: 'insensitive' } },
|
||||
{ cityName: { contains: location, mode: 'insensitive' } },
|
||||
{ departmentCode: { contains: location, mode: 'insensitive' } },
|
||||
],
|
||||
},
|
||||
];
|
||||
}
|
||||
if (contractType) {
|
||||
where.AND = [
|
||||
...(where.AND || []),
|
||||
{ contractType: contractType },
|
||||
];
|
||||
}
|
||||
const orderBy = {};
|
||||
if (sortBy) {
|
||||
orderBy[sortBy] = sortOrder === 'asc' ? 'asc' : 'desc';
|
||||
}
|
||||
else {
|
||||
orderBy.publicationDate = 'desc'; // Tri par défaut
|
||||
}
|
||||
const jobs = await prisma.jobOffer.findMany({
|
||||
skip,
|
||||
take,
|
||||
where,
|
||||
orderBy,
|
||||
});
|
||||
const total = await prisma.jobOffer.count({ where });
|
||||
res.status(200).json({
|
||||
jobs,
|
||||
total,
|
||||
page,
|
||||
limit,
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
console.error('Error searching job offers:', error);
|
||||
res.status(500).json({ error: 'Failed to search job offers' });
|
||||
}
|
||||
};
|
||||
exports.searchLocalJobOffers = searchLocalJobOffers;
|
Loading…
Add table
Add a link
Reference in a new issue