copied the code from the working repo
This commit is contained in:
55
mtucijobsbot/dist/modules/scenes/savevacansy.js
vendored
Normal file
55
mtucijobsbot/dist/modules/scenes/savevacansy.js
vendored
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.saveVacansy = void 0;
|
||||
const axios_1 = __importDefault(require("axios"));
|
||||
require("dotenv/config");
|
||||
function saveVacansy(bot) {
|
||||
bot.on('callback_query', (ctx) => __awaiter(this, void 0, void 0, function* () {
|
||||
var _a;
|
||||
if (ctx.callbackQuery && 'data' in ctx.callbackQuery) {
|
||||
const callbackData = ctx.callbackQuery.data;
|
||||
if (callbackData.startsWith('savevacancy+')) {
|
||||
const jobID = callbackData.split('+')[1];
|
||||
try {
|
||||
const data = yield axios_1.default.post(`${process.env.API}students/favourites/`, { StudentID: ctx.from.id, JobID: jobID }, {
|
||||
headers: {
|
||||
'X-API-KEY': 'SbRHOVoK97GKCx3Lqx6hKXLbZZJEd0GTGbeglXdpK9PhSB9kpr4eWCsuIIwnD6F2mgpTDlVHFCRbeFmuSfqBVsb12lNwF3P1tmdxiktl7zH9sDS2YK7Pyj2DecCWAZ3n',
|
||||
},
|
||||
});
|
||||
console.log(data);
|
||||
ctx.answerCbQuery('Вакансия была сохранена');
|
||||
}
|
||||
catch (error) {
|
||||
if (axios_1.default.isAxiosError(error)) {
|
||||
// Обработка ошибок Axios
|
||||
if (error.response && error.response.status === 409) {
|
||||
ctx.answerCbQuery('Вакансия уже добавлена в избранное');
|
||||
}
|
||||
else {
|
||||
ctx.answerCbQuery('Произошла ошибка при сохранении вакансии');
|
||||
console.error(((_a = error.response) === null || _a === void 0 ? void 0 : _a.data) || error.message);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Обработка других типов ошибок
|
||||
ctx.answerCbQuery('Произошла неизвестная ошибка');
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
exports.saveVacansy = saveVacansy;
|
||||
Reference in New Issue
Block a user