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;
|
18
backend/dist/index.js
vendored
Normal file
18
backend/dist/index.js
vendored
Normal file
|
@ -0,0 +1,18 @@
|
|||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const express_1 = __importDefault(require("express"));
|
||||
const dotenv_1 = __importDefault(require("dotenv"));
|
||||
const jobIngestionRoutes_1 = __importDefault(require("./routes/jobIngestionRoutes"));
|
||||
const jobSearchRoutes_1 = __importDefault(require("./routes/jobSearchRoutes"));
|
||||
dotenv_1.default.config();
|
||||
const app = (0, express_1.default)();
|
||||
const PORT = process.env.PORT || 3000;
|
||||
app.use(express_1.default.json());
|
||||
app.use(jobIngestionRoutes_1.default);
|
||||
app.use(jobSearchRoutes_1.default);
|
||||
app.listen(PORT, () => {
|
||||
console.log(`Server is running on port ${PORT}`);
|
||||
});
|
10
backend/dist/routes/jobIngestionRoutes.js
vendored
Normal file
10
backend/dist/routes/jobIngestionRoutes.js
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const express_1 = __importDefault(require("express"));
|
||||
const jobIngestionController_1 = require("../controllers/jobIngestionController");
|
||||
const router = express_1.default.Router();
|
||||
router.post('/api/ingest-jobs', jobIngestionController_1.ingestJobOffers);
|
||||
exports.default = router;
|
10
backend/dist/routes/jobSearchRoutes.js
vendored
Normal file
10
backend/dist/routes/jobSearchRoutes.js
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const express_1 = __importDefault(require("express"));
|
||||
const jobSearchController_1 = require("../controllers/jobSearchController");
|
||||
const router = express_1.default.Router();
|
||||
router.get('/api/jobs', jobSearchController_1.searchLocalJobOffers);
|
||||
exports.default = router;
|
67
backend/dist/services/FranceTravailService.js
vendored
Normal file
67
backend/dist/services/FranceTravailService.js
vendored
Normal file
|
@ -0,0 +1,67 @@
|
|||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const axios_1 = __importDefault(require("axios"));
|
||||
class FranceTravailService {
|
||||
constructor() {
|
||||
this.accessToken = null;
|
||||
this.tokenExpiration = null;
|
||||
this.realm = '/partenaire';
|
||||
this.clientId = process.env.FRANCE_TRAVAIL_CLIENT_ID || '';
|
||||
this.clientSecret = process.env.FRANCE_TRAVAIL_CLIENT_SECRET || '';
|
||||
this.tokenUrl = process.env.FRANCE_TRAVAIL_TOKEN_URL || '';
|
||||
this.apiUrl = process.env.FRANCE_TRAVAIL_API_URL || '';
|
||||
this.scope = process.env.FRANCE_TRAVAIL_SCOPE || '';
|
||||
}
|
||||
async authenticate() {
|
||||
try {
|
||||
const response = await axios_1.default.post(this.tokenUrl, null, {
|
||||
params: {
|
||||
realm: this.realm,
|
||||
grant_type: 'client_credentials',
|
||||
client_id: this.clientId,
|
||||
client_secret: this.clientSecret,
|
||||
scope: this.scope,
|
||||
},
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
});
|
||||
this.accessToken = response.data.access_token;
|
||||
this.tokenExpiration = Date.now() + response.data.expires_in * 1000;
|
||||
}
|
||||
catch (error) {
|
||||
const axiosError = error;
|
||||
console.error('Authentication failed:', axiosError.response?.data || axiosError.message);
|
||||
throw new Error('Failed to authenticate with France Travail API');
|
||||
}
|
||||
}
|
||||
async ensureValidToken() {
|
||||
if (!this.accessToken || (this.tokenExpiration && Date.now() >= this.tokenExpiration)) {
|
||||
await this.authenticate();
|
||||
}
|
||||
}
|
||||
async getJobOffers(params) {
|
||||
await this.ensureValidToken();
|
||||
try {
|
||||
const response = await axios_1.default.get(this.apiUrl, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${this.accessToken}`,
|
||||
},
|
||||
params: {
|
||||
...params,
|
||||
range: params?.range || '0-9', // Default range for pagination
|
||||
},
|
||||
});
|
||||
return response.data;
|
||||
}
|
||||
catch (error) {
|
||||
const axiosError = error;
|
||||
console.error('Failed to fetch job offers:', axiosError.response?.data || axiosError.message);
|
||||
throw new Error('Failed to fetch job offers from France Travail API');
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.default = new FranceTravailService();
|
Loading…
Add table
Add a link
Reference in a new issue