nettoyage
This commit is contained in:
parent
7878062edc
commit
72f3fd82c8
4 changed files with 0 additions and 119 deletions
|
@ -1,18 +0,0 @@
|
||||||
"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}`);
|
|
||||||
});
|
|
|
@ -1,10 +0,0 @@
|
||||||
"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;
|
|
|
@ -1,10 +0,0 @@
|
||||||
"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;
|
|
|
@ -1,81 +0,0 @@
|
||||||
"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 });
|
|
||||||
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 || '';
|
|
||||||
}
|
|
||||||
authenticate() {
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
var _a;
|
|
||||||
try {
|
|
||||||
const response = yield 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:', ((_a = axiosError.response) === null || _a === void 0 ? void 0 : _a.data) || axiosError.message);
|
|
||||||
throw new Error('Failed to authenticate with France Travail API');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
ensureValidToken() {
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
if (!this.accessToken || (this.tokenExpiration && Date.now() >= this.tokenExpiration)) {
|
|
||||||
yield this.authenticate();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
getJobOffers(params) {
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
var _a;
|
|
||||||
yield this.ensureValidToken();
|
|
||||||
try {
|
|
||||||
const response = yield axios_1.default.get(this.apiUrl, {
|
|
||||||
headers: {
|
|
||||||
Authorization: `Bearer ${this.accessToken}`,
|
|
||||||
},
|
|
||||||
params: Object.assign(Object.assign({}, params), { range: (params === null || params === void 0 ? void 0 : params.range) || '0-9' }),
|
|
||||||
});
|
|
||||||
return response.data;
|
|
||||||
}
|
|
||||||
catch (error) {
|
|
||||||
const axiosError = error;
|
|
||||||
console.error('Failed to fetch job offers:', ((_a = axiosError.response) === null || _a === void 0 ? void 0 : _a.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