phase 1 backend
This commit is contained in:
parent
a0897c2d38
commit
9653e55453
26 changed files with 3225 additions and 0 deletions
45
backend/dist/controllers/jobIngestionController.js
vendored
Normal file
45
backend/dist/controllers/jobIngestionController.js
vendored
Normal file
|
@ -0,0 +1,45 @@
|
|||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ingestJobOffers = void 0;
|
||||
const client_1 = require("@prisma/client");
|
||||
const FranceTravailService_1 = __importDefault(require("../services/FranceTravailService"));
|
||||
const prisma = new client_1.PrismaClient();
|
||||
const ingestJobOffers = async (req, res) => {
|
||||
try {
|
||||
const jobOffers = await FranceTravailService_1.default.getJobOffers({ range: '0-149' });
|
||||
for (const offre of jobOffers.resultats) {
|
||||
const mappedOffer = {
|
||||
id: offre.id,
|
||||
title: offre.intitule,
|
||||
description: offre.description,
|
||||
publicationDate: new Date(offre.dateCreation),
|
||||
romeCode: offre.romeCode,
|
||||
romeLabel: offre.romeLibelle,
|
||||
locationLabel: offre.lieuTravail?.libelle || null,
|
||||
postalCode: offre.lieuTravail?.codePostal || null,
|
||||
departmentCode: offre.lieuTravail?.codeDepartement || null,
|
||||
cityName: offre.lieuTravail?.ville || null,
|
||||
companyName: offre.entreprise?.nom || null,
|
||||
contractType: offre.typeContrat,
|
||||
contractLabel: offre.libelleTypeContrat,
|
||||
};
|
||||
await prisma.jobOffer.upsert({
|
||||
where: { id: mappedOffer.id },
|
||||
update: mappedOffer,
|
||||
create: mappedOffer,
|
||||
});
|
||||
}
|
||||
res.status(200).json({
|
||||
message: 'Job offers ingested successfully',
|
||||
count: jobOffers.resultats.length,
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
console.error('Error ingesting job offers:', error);
|
||||
res.status(500).json({ error: 'Failed to ingest job offers' });
|
||||
}
|
||||
};
|
||||
exports.ingestJobOffers = ingestJobOffers;
|
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