phase 1 backend
This commit is contained in:
parent
a0897c2d38
commit
9653e55453
26 changed files with 3225 additions and 0 deletions
55
backend/src/controllers/jobIngestionController.js
Normal file
55
backend/src/controllers/jobIngestionController.js
Normal file
|
@ -0,0 +1,55 @@
|
|||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
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 = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
var _a, _b, _c, _d, _e;
|
||||
try {
|
||||
const jobOffers = yield 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: ((_a = offre.lieuTravail) === null || _a === void 0 ? void 0 : _a.libelle) || null,
|
||||
postalCode: ((_b = offre.lieuTravail) === null || _b === void 0 ? void 0 : _b.codePostal) || null,
|
||||
departmentCode: ((_c = offre.lieuTravail) === null || _c === void 0 ? void 0 : _c.codeDepartement) || null,
|
||||
cityName: ((_d = offre.lieuTravail) === null || _d === void 0 ? void 0 : _d.ville) || null,
|
||||
companyName: ((_e = offre.entreprise) === null || _e === void 0 ? void 0 : _e.nom) || null,
|
||||
contractType: offre.typeContrat,
|
||||
contractLabel: offre.libelleTypeContrat,
|
||||
};
|
||||
yield 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;
|
43
backend/src/controllers/jobIngestionController.ts
Normal file
43
backend/src/controllers/jobIngestionController.ts
Normal file
|
@ -0,0 +1,43 @@
|
|||
import { Request, Response } from 'express';
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import FranceTravailService from '../services/FranceTravailService';
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
export const ingestJobOffers = async (req: Request, res: Response) => {
|
||||
try {
|
||||
const jobOffers = await FranceTravailService.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' });
|
||||
}
|
||||
};
|
78
backend/src/controllers/jobSearchController.js
Normal file
78
backend/src/controllers/jobSearchController.js
Normal file
|
@ -0,0 +1,78 @@
|
|||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.searchLocalJobOffers = void 0;
|
||||
const client_1 = require("@prisma/client");
|
||||
const prisma = new client_1.PrismaClient();
|
||||
const searchLocalJobOffers = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
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;
|
||||
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 = yield prisma.jobOffer.findMany({
|
||||
skip,
|
||||
take,
|
||||
where,
|
||||
orderBy,
|
||||
});
|
||||
const total = yield 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;
|
74
backend/src/controllers/jobSearchController.ts
Normal file
74
backend/src/controllers/jobSearchController.ts
Normal file
|
@ -0,0 +1,74 @@
|
|||
import { Request, Response } from 'express';
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
export const searchLocalJobOffers = async (req: Request, res: Response) => {
|
||||
try {
|
||||
const page = parseInt(req.query.page as string) || 1;
|
||||
const limit = parseInt(req.query.limit as string) || 10;
|
||||
const skip = (page - 1) * limit;
|
||||
const take = limit;
|
||||
const sortBy = req.query.sortBy as string || 'publicationDate';
|
||||
const sortOrder = req.query.sortOrder as string || 'desc';
|
||||
const keyword = req.query.keyword as string;
|
||||
const location = req.query.location as string;
|
||||
const contractType = req.query.contractType as string;
|
||||
|
||||
console.log('Keyword:', keyword);
|
||||
console.log('Location:', location);
|
||||
|
||||
const where: any = {};
|
||||
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: any = {};
|
||||
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' });
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue