Compare commits

..

No commits in common. "18eec7bf661066d9b4a928bc20fc3ce9045d9800" and "bc392b0ff90dbb6623708e59ec7aedf2ebda687c" have entirely different histories.

4 changed files with 387 additions and 377 deletions

View File

@ -89,14 +89,14 @@
"event": [] "event": []
}, },
{ {
"name": "ChangeApplicationStatus", "name": "CreateApplication",
"event": [], "event": [],
"request": { "request": {
"method": "PATCH", "method": "POST",
"header": [], "header": [],
"description": "", "description": "",
"url": { "url": {
"raw": "http://localhost:3000/api/organizations/joboffers/applications/2", "raw": "http://localhost:3000/api/applications",
"host": [ "host": [
"localhost" "localhost"
], ],
@ -106,7 +106,7 @@
}, },
"body": { "body": {
"mode": "raw", "mode": "raw",
"raw": "{\n \"status\": \"ACCEPTED\"\n}", "raw": "{\n \"jobOfferId\": 1\n}",
"options": { "options": {
"raw": { "raw": {
"language": "json" "language": "json"
@ -115,24 +115,6 @@
} }
} }
}, },
{
"name": "CreateApplication",
"event": [],
"request": {
"method": "POST",
"header": [],
"description": "",
"url": {
"raw": "http://localhost:3000/api/organizations/joboffers/1",
"host": [
"localhost"
],
"path": [],
"query": [],
"variable": []
}
}
},
{ {
"name": "CreateJobOffer", "name": "CreateJobOffer",
"event": [], "event": [],
@ -213,33 +195,6 @@
} }
} }
}, },
{
"name": "DeleteApplication",
"event": [],
"request": {
"method": "DELETE",
"header": [],
"description": "",
"url": {
"raw": "http://localhost:3000/api/organizations/joboffers/applications/2",
"host": [
"localhost"
],
"path": [],
"query": [],
"variable": []
},
"body": {
"mode": "raw",
"raw": "{\n \"jobApplicationId\": 1\n}",
"options": {
"raw": {
"language": "json"
}
}
}
}
},
{ {
"name": "DeleteJobOffer", "name": "DeleteJobOffer",
"event": [], "event": [],
@ -355,33 +310,6 @@
} }
} }
}, },
{
"name": "GetApplicantsByOrganization",
"event": [],
"request": {
"method": "GET",
"header": [],
"description": "",
"url": {
"raw": "http://localhost:3000/api/organizations/1",
"host": [
"localhost"
],
"path": [],
"query": [],
"variable": []
},
"body": {
"mode": "raw",
"raw": "{\n \"organizationId\": 1\n}",
"options": {
"raw": {
"language": "json"
}
}
}
}
},
{ {
"name": "GetJobOffers", "name": "GetJobOffers",
"event": [], "event": [],
@ -407,24 +335,6 @@
} }
} }
}, },
{
"name": "GetMyApplications",
"event": [],
"request": {
"method": "GET",
"header": [],
"description": "",
"url": {
"raw": "http://localhost:3000/api/organizations/applications/mine",
"host": [
"localhost"
],
"path": [],
"query": [],
"variable": []
}
}
},
{ {
"name": "GetMyself", "name": "GetMyself",
"event": [], "event": [],
@ -540,45 +450,6 @@
} }
} }
}, },
{
"name": "RemoveOrganizationAdmin",
"event": [],
"request": {
"method": "DELETE",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"disabled": false,
"type": "default"
},
{
"key": "User-Agent",
"value": "insomnia/2023.5.8",
"disabled": false,
"type": "default"
}
],
"description": "",
"url": {
"raw": "http://localhost:3000/api/organizations/1/admins/me",
"host": [
"localhost"
],
"path": [],
"query": [],
"variable": []
},
"body": {
"mode": "raw",
"options": {
"raw": {
"language": "json"
}
}
}
}
},
{ {
"name": "Register", "name": "Register",
"event": [], "event": [],
@ -619,6 +490,45 @@
} }
} }
}, },
{
"name": "RemoveOrganizationAdmin",
"event": [],
"request": {
"method": "DELETE",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"disabled": false,
"type": "default"
},
{
"key": "User-Agent",
"value": "insomnia/2023.5.8",
"disabled": false,
"type": "default"
}
],
"description": "",
"url": {
"raw": "http://localhost:3000/api/organizations/1/admins/me",
"host": [
"localhost"
],
"path": [],
"query": [],
"variable": []
},
"body": {
"mode": "raw",
"options": {
"raw": {
"language": "json"
}
}
}
}
},
{ {
"name": "RequestNewPassword", "name": "RequestNewPassword",
"event": [], "event": [],
@ -659,46 +569,6 @@
} }
} }
}, },
{
"name": "UpdateOrganization",
"event": [],
"request": {
"method": "PATCH",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"disabled": false,
"type": "default"
},
{
"key": "User-Agent",
"value": "insomnia/2023.5.8",
"disabled": false,
"type": "default"
}
],
"description": "",
"url": {
"raw": "http://localhost:3000/api/organizations/1",
"host": [
"localhost"
],
"path": [],
"query": [],
"variable": []
},
"body": {
"mode": "raw",
"raw": "{\n \"name\": \"Blink Inc.\",\n \"location\": \"Naples (Campania), Italy\",\n \"description\": \"Blink is a privacy-respecting business-oriented social media platform focused on fostering connections between businesses and individuals, propelling careers and sparking innovation in the professional world. Think of it as an open-source alternative to LinkedIn.\"\n}",
"options": {
"raw": {
"language": "json"
}
}
}
}
},
{ {
"name": "ResetNewPassword", "name": "ResetNewPassword",
"event": [], "event": [],
@ -739,6 +609,46 @@
} }
} }
}, },
{
"name": "UpdateOrganization",
"event": [],
"request": {
"method": "PATCH",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"disabled": false,
"type": "default"
},
{
"key": "User-Agent",
"value": "insomnia/2023.5.8",
"disabled": false,
"type": "default"
}
],
"description": "",
"url": {
"raw": "http://localhost:3000/api/organizations/1",
"host": [
"localhost"
],
"path": [],
"query": [],
"variable": []
},
"body": {
"mode": "raw",
"raw": "{\n \"name\": \"Blink Inc.\",\n \"location\": \"Naples (Campania), Italy\",\n \"description\": \"Blink is a privacy-respecting business-oriented social media platform focused on fostering connections between businesses and individuals, propelling careers and sparking innovation in the professional world. Think of it as an open-source alternative to LinkedIn.\"\n}",
"options": {
"raw": {
"language": "json"
}
}
}
}
},
{ {
"name": "UpdatePerson", "name": "UpdatePerson",
"event": [], "event": [],
@ -778,6 +688,105 @@
} }
} }
} }
},
{
"name": "GetMyApplications",
"event": [],
"request": {
"method": "GET",
"header": [],
"description": "",
"url": {
"raw": "http://localhost:3000/api/applications/myapplications",
"host": [
"localhost"
],
"path": [],
"query": [],
"variable": []
}
}
},
{
"name": "DeleteApplication",
"event": [],
"request": {
"method": "DELETE",
"header": [],
"description": "",
"url": {
"raw": "http://localhost:3000/api/applications",
"host": [
"localhost"
],
"path": [],
"query": [],
"variable": []
},
"body": {
"mode": "raw",
"raw": "{\n \"jobApplicationId\": 1\n}",
"options": {
"raw": {
"language": "json"
}
}
}
}
},
{
"name": "GetApplicantsByOrganization",
"event": [],
"request": {
"method": "GET",
"header": [],
"description": "",
"url": {
"raw": "http://localhost:3000/api/applications/applicantsbyorganization",
"host": [
"localhost"
],
"path": [],
"query": [],
"variable": []
},
"body": {
"mode": "raw",
"raw": "{\n \"organizationId\": 1\n}",
"options": {
"raw": {
"language": "json"
}
}
}
}
},
{
"name": "ChangeApplicationStatus",
"event": [],
"request": {
"method": "POST",
"header": [],
"description": "",
"url": {
"raw": "http://localhost:3000/api/applications",
"host": [
"localhost"
],
"path": [],
"query": [],
"variable": []
},
"body": {
"mode": "raw",
"raw": "{\n \"jobOfferId\": 1\n}",
"options": {
"raw": {
"language": "json"
}
}
}
}
} }
], ],
"variable": [] "variable": []

View File

@ -75,44 +75,18 @@
} }
} }
}, },
{
"type": "http",
"name": "ChangeApplicationStatus",
"seq": 1,
"request": {
"url": "http://localhost:3000/api/organizations/joboffers/applications/2",
"method": "PATCH",
"headers": [],
"params": [],
"body": {
"mode": "json",
"json": "{\n \"status\": \"ACCEPTED\"\n}",
"formUrlEncoded": [],
"multipartForm": []
},
"script": {},
"vars": {},
"assertions": [],
"tests": "",
"auth": {
"mode": "bearer",
"bearer": {
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwZXJzb25faWQiOjEsImlhdCI6MTczMDEyNTUzNywiZXhwIjoxNzMwMTU0MzM3fQ.X216UkLuDL6-Qs6EUbIRL_YKQKKcxyzQFmAKzJNWEzI"
}
}
}
},
{ {
"type": "http", "type": "http",
"name": "CreateApplication", "name": "CreateApplication",
"seq": 4, "seq": 4,
"request": { "request": {
"url": "http://localhost:3000/api/organizations/joboffers/1", "url": "http://localhost:3000/api/applications",
"method": "POST", "method": "POST",
"headers": [], "headers": [],
"params": [], "params": [],
"body": { "body": {
"mode": "none", "mode": "json",
"json": "{\n \"jobOfferId\": 1\n}",
"formUrlEncoded": [], "formUrlEncoded": [],
"multipartForm": [] "multipartForm": []
}, },
@ -123,7 +97,7 @@
"auth": { "auth": {
"mode": "bearer", "mode": "bearer",
"bearer": { "bearer": {
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwZXJzb25faWQiOjEsImlhdCI6MTczMDEyNTUzNywiZXhwIjoxNzMwMTU0MzM3fQ.X216UkLuDL6-Qs6EUbIRL_YKQKKcxyzQFmAKzJNWEzI" "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwZXJzb25faWQiOjEsImlhdCI6MTcyOTc3NDc4NywiZXhwIjoxNzI5ODAzNTg3fQ.Li0NeQH6e4ykQ8tpY3KYkS_bQhv7cIFmjz96U-E9S0c"
} }
} }
} }
@ -204,33 +178,6 @@
} }
} }
}, },
{
"type": "http",
"name": "DeleteApplication",
"seq": 2,
"request": {
"url": "http://localhost:3000/api/organizations/joboffers/applications/2",
"method": "DELETE",
"headers": [],
"params": [],
"body": {
"mode": "json",
"json": "{\n \"jobApplicationId\": 1\n}",
"formUrlEncoded": [],
"multipartForm": []
},
"script": {},
"vars": {},
"assertions": [],
"tests": "",
"auth": {
"mode": "bearer",
"bearer": {
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwZXJzb25faWQiOjEsImlhdCI6MTczMDEyODc2NSwiZXhwIjoxNzMwMTU3NTY1fQ.puQ4gw9K_fL4FhXs7UlvyZwq98XZEIuXwnZ0JBIXzaw"
}
}
}
},
{ {
"type": "http", "type": "http",
"name": "DeleteJobOffer", "name": "DeleteJobOffer",
@ -362,33 +309,6 @@
} }
} }
}, },
{
"type": "http",
"name": "GetApplicantsByOrganization",
"seq": 3,
"request": {
"url": "http://localhost:3000/api/organizations/1",
"method": "GET",
"headers": [],
"params": [],
"body": {
"mode": "json",
"json": "{\n \"organizationId\": 1\n}",
"formUrlEncoded": [],
"multipartForm": []
},
"script": {},
"vars": {},
"assertions": [],
"tests": "",
"auth": {
"mode": "bearer",
"bearer": {
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwZXJzb25faWQiOjEsImlhdCI6MTczMDEyNTUzNywiZXhwIjoxNzMwMTU0MzM3fQ.X216UkLuDL6-Qs6EUbIRL_YKQKKcxyzQFmAKzJNWEzI"
}
}
}
},
{ {
"type": "http", "type": "http",
"name": "GetJobOffers", "name": "GetJobOffers",
@ -418,32 +338,6 @@
} }
} }
}, },
{
"type": "http",
"name": "GetMyApplications",
"seq": 5,
"request": {
"url": "http://localhost:3000/api/organizations/applications/mine",
"method": "GET",
"headers": [],
"params": [],
"body": {
"mode": "none",
"formUrlEncoded": [],
"multipartForm": []
},
"script": {},
"vars": {},
"assertions": [],
"tests": "",
"auth": {
"mode": "bearer",
"bearer": {
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwZXJzb25faWQiOjEsImlhdCI6MTczMDEyNTUzNywiZXhwIjoxNzMwMTU0MzM3fQ.X216UkLuDL6-Qs6EUbIRL_YKQKKcxyzQFmAKzJNWEzI"
}
}
}
},
{ {
"type": "http", "type": "http",
"name": "GetMyself", "name": "GetMyself",
@ -569,44 +463,6 @@
} }
} }
}, },
{
"type": "http",
"name": "RemoveOrganizationAdmin",
"seq": 9,
"request": {
"url": "http://localhost:3000/api/organizations/1/admins/me",
"method": "DELETE",
"headers": [
{
"name": "Content-Type",
"value": "application/json",
"enabled": true
},
{
"name": "User-Agent",
"value": "insomnia/2023.5.8",
"enabled": true
}
],
"params": [],
"body": {
"mode": "json",
"json": "",
"formUrlEncoded": [],
"multipartForm": []
},
"script": {},
"vars": {},
"assertions": [],
"tests": "",
"auth": {
"mode": "bearer",
"bearer": {
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwZXJzb25faWQiOjIsImlhdCI6MTcyOTUxNjM0NywiZXhwIjoxNzI5NTQ1MTQ3fQ.W09-xjGYSVI2EftoI9lSJAkzlo3V1NADcv4RbhE414I"
}
}
}
},
{ {
"type": "http", "type": "http",
"name": "Register", "name": "Register",
@ -645,6 +501,44 @@
} }
} }
}, },
{
"type": "http",
"name": "RemoveOrganizationAdmin",
"seq": 9,
"request": {
"url": "http://localhost:3000/api/organizations/1/admins/me",
"method": "DELETE",
"headers": [
{
"name": "Content-Type",
"value": "application/json",
"enabled": true
},
{
"name": "User-Agent",
"value": "insomnia/2023.5.8",
"enabled": true
}
],
"params": [],
"body": {
"mode": "json",
"json": "",
"formUrlEncoded": [],
"multipartForm": []
},
"script": {},
"vars": {},
"assertions": [],
"tests": "",
"auth": {
"mode": "bearer",
"bearer": {
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwZXJzb25faWQiOjIsImlhdCI6MTcyOTUxNjM0NywiZXhwIjoxNzI5NTQ1MTQ3fQ.W09-xjGYSVI2EftoI9lSJAkzlo3V1NADcv4RbhE414I"
}
}
}
},
{ {
"type": "http", "type": "http",
"name": "RequestNewPassword", "name": "RequestNewPassword",
@ -680,6 +574,41 @@
} }
} }
}, },
{
"type": "http",
"name": "ResetNewPassword",
"seq": 16,
"request": {
"url": "http://localhost:3000/api/resetpassword/reset",
"method": "POST",
"headers": [
{
"name": "Content-Type",
"value": "application/json",
"enabled": true
},
{
"name": "User-Agent",
"value": "insomnia/2023.5.8",
"enabled": true
}
],
"params": [],
"body": {
"mode": "json",
"json": "{\n \"secret\": \"360837853e2d3cf799c709b44720b4e3\",\n \"password\": \"password\"\n}",
"formUrlEncoded": [],
"multipartForm": []
},
"script": {},
"vars": {},
"assertions": [],
"tests": "",
"auth": {
"mode": "none"
}
}
},
{ {
"type": "http", "type": "http",
"name": "UpdateOrganization", "name": "UpdateOrganization",
@ -718,41 +647,6 @@
} }
} }
}, },
{
"type": "http",
"name": "ResetNewPassword",
"seq": 16,
"request": {
"url": "http://localhost:3000/api/resetpassword/reset",
"method": "POST",
"headers": [
{
"name": "Content-Type",
"value": "application/json",
"enabled": true
},
{
"name": "User-Agent",
"value": "insomnia/2023.5.8",
"enabled": true
}
],
"params": [],
"body": {
"mode": "json",
"json": "{\n \"secret\": \"360837853e2d3cf799c709b44720b4e3\",\n \"password\": \"password\"\n}",
"formUrlEncoded": [],
"multipartForm": []
},
"script": {},
"vars": {},
"assertions": [],
"tests": "",
"auth": {
"mode": "none"
}
}
},
{ {
"type": "http", "type": "http",
"name": "UpdatePerson", "name": "UpdatePerson",
@ -790,6 +684,113 @@
} }
} }
} }
},
{
"type": "http",
"name": "GetMyApplications",
"seq": 5,
"request": {
"url": "http://localhost:3000/api/applications/myapplications",
"method": "GET",
"headers": [],
"params": [],
"body": {
"mode": "none",
"formUrlEncoded": [],
"multipartForm": []
},
"script": {},
"vars": {},
"assertions": [],
"tests": "",
"auth": {
"mode": "bearer",
"bearer": {
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwZXJzb25faWQiOjEsImlhdCI6MTcyOTc3NDc4NywiZXhwIjoxNzI5ODAzNTg3fQ.Li0NeQH6e4ykQ8tpY3KYkS_bQhv7cIFmjz96U-E9S0c"
}
}
}
},
{
"type": "http",
"name": "DeleteApplication",
"seq": 2,
"request": {
"url": "http://localhost:3000/api/applications",
"method": "DELETE",
"headers": [],
"params": [],
"body": {
"mode": "json",
"json": "{\n \"jobApplicationId\": 1\n}",
"formUrlEncoded": [],
"multipartForm": []
},
"script": {},
"vars": {},
"assertions": [],
"tests": "",
"auth": {
"mode": "bearer",
"bearer": {
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwZXJzb25faWQiOjEsImlhdCI6MTcyOTc1NTMyNCwiZXhwIjoxNzI5Nzg0MTI0fQ.U2leC3wu51iSOeItTk02TZCDttTYBWBcLahCdoXiIR8"
}
}
}
},
{
"type": "http",
"name": "GetApplicantsByOrganization",
"seq": 3,
"request": {
"url": "http://localhost:3000/api/applications/applicantsbyorganization",
"method": "GET",
"headers": [],
"params": [],
"body": {
"mode": "json",
"json": "{\n \"organizationId\": 1\n}",
"formUrlEncoded": [],
"multipartForm": []
},
"script": {},
"vars": {},
"assertions": [],
"tests": "",
"auth": {
"mode": "bearer",
"bearer": {
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwZXJzb25faWQiOjEsImlhdCI6MTcyOTc3NDc4NywiZXhwIjoxNzI5ODAzNTg3fQ.Li0NeQH6e4ykQ8tpY3KYkS_bQhv7cIFmjz96U-E9S0c"
}
}
}
},
{
"type": "http",
"name": "ChangeApplicationStatus",
"seq": 1,
"request": {
"url": "http://localhost:3000/api/applications",
"method": "POST",
"headers": [],
"params": [],
"body": {
"mode": "json",
"json": "{\n \"jobOfferId\": 1\n}",
"formUrlEncoded": [],
"multipartForm": []
},
"script": {},
"vars": {},
"assertions": [],
"tests": "",
"auth": {
"mode": "bearer",
"bearer": {
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwZXJzb25faWQiOjEsImlhdCI6MTcyOTc3NDc4NywiZXhwIjoxNzI5ODAzNTg3fQ.Li0NeQH6e4ykQ8tpY3KYkS_bQhv7cIFmjz96U-E9S0c"
}
}
}
} }
], ],
"environments": [], "environments": [],

View File

@ -56,7 +56,7 @@ app.use('/api/organizations', organizationRoutes.routes);
app.use('/api/organizations', jobOffersRoutes.routes); app.use('/api/organizations', jobOffersRoutes.routes);
app.use('/api/organizations', organizationAdminRoutes.routes); app.use('/api/organizations', organizationAdminRoutes.routes);
app.use('/api/resetpassword', resetPasswordRoutes.routes); app.use('/api/resetpassword', resetPasswordRoutes.routes);
app.use('/api/organizations', applicationRoutes.routes); app.use('/api/applications', applicationRoutes.routes);
/* /*
===== END ROUTE HANDLING ===== ===== END ROUTE HANDLING =====

View File

@ -1,3 +1,4 @@
// TODO: I don't like the routes. It should be /api/organizations/idOrganization/joboffers/idJobOffer/
// TODO: Create a validator // TODO: Create a validator
/* /*
This code is part of Blink This code is part of Blink
@ -26,20 +27,20 @@ const jwtUtils = require('../utils/jwt_utils');
async function insert(req, res) { async function insert(req, res) {
try { try {
// Check if the job offer exists // Check if the job offer exists
if (await JobOffer.findById(req.params.idJobOffer) == null) { if (await JobOffer.findById(req.body.jobOfferId) == null) {
return res.status(404).json({ return res.status(404).json({
error: 'This job offer does not exist' error: 'This job offer does not exist'
}); });
} }
// Check if the user has already applied for this position // Check if the user has already applied for this position
if (await Application.userAlreadyApplicated(req.jwt.person_id, req.params.idJobOffer)) { if (await Application.userAlreadyApplicated(req.jwt.person_id, req.body.jobOfferId)) {
return res.status(400).json({ return res.status(400).json({
error: 'User has already applied to this job' error: 'User has already applied to this job'
}); });
} }
const application = await Application.insert(req.jwt.person_id, req.params.idJobOffer); const application = await Application.insert(req.jwt.person_id, req.body.jobOfferId);
res.set('Location', `/api/applications/${application.id}`); res.set('Location', `/api/applications/${application.id}`);
return res.status(201).json(application); return res.status(201).json(application);
} catch (error) { } catch (error) {
@ -75,13 +76,13 @@ async function myApplications(req, res) {
*/ */
async function getApplicantsByJobOffer(req, res) { async function getApplicantsByJobOffer(req, res) {
try { try {
const isAdmin = await OrganizationAdmin.isAdmin(req.jwt.person_id, req.params.idJobOffer); const isAdmin = await OrganizationAdmin.isAdmin(req.jwt.person_id, req.body.organizationId);
if (!isAdmin) { if (!isAdmin) {
return res.status(401).json({ return res.status(401).json({
error: 'Forbidden' error: 'Forbidden'
}); });
} }
const applicants = await Application.getApplicantsByJobOffer(req.params.idJobOffer); const applicants = await Application.getApplicantsByJobOffer(req.body.jobOfferId);
return res.status(200).json(applicants); return res.status(200).json(applicants);
} catch (error) { } catch (error) {
console.error(`Error in function ${getApplicantsByJobOffer.name}: ${error}`); console.error(`Error in function ${getApplicantsByJobOffer.name}: ${error}`);
@ -100,13 +101,13 @@ async function getApplicantsByJobOffer(req, res) {
*/ */
async function getApplicantsByOrganization(req, res) { async function getApplicantsByOrganization(req, res) {
try { try {
const isAdmin = await OrganizationAdmin.isAdmin(req.jwt.person_id, req.params.idOrganization); const isAdmin = await OrganizationAdmin.isAdmin(req.jwt.person_id, req.body.organizationId);
if (!isAdmin) { if (!isAdmin) {
return res.status(401).json({ return res.status(401).json({
error: 'Forbidden' error: 'Forbidden'
}); });
} }
const applicants = await Application.getApplicansByOrganization(req.params.idOrganization); const applicants = await Application.getApplicansByOrganization(req.body.organizationId);
return res.status(200).json(applicants); return res.status(200).json(applicants);
} catch (error) { } catch (error) {
console.error(`Error in function ${getApplicantsByOrganization.name}: ${error}`); console.error(`Error in function ${getApplicantsByOrganization.name}: ${error}`);
@ -123,7 +124,7 @@ async function getApplicantsByOrganization(req, res) {
*/ */
async function remove(req, res) { async function remove(req, res) {
try { try {
const jobApplication = await Application.find(req.params.idApplication); const jobApplication = await Application.find(req.body.jobApplicationId);
if (jobApplication == null) { if (jobApplication == null) {
return res.status(404).send(); return res.status(404).send();
} }
@ -132,7 +133,7 @@ async function remove(req, res) {
error: 'Forbidden' error: 'Forbidden'
}); });
} }
await Application.remove(req.params.idApplication); await Application.remove(req.body.jobApplicationId);
return res.status(200).send(); return res.status(200).send();
} catch (error) { } catch (error) {
console.error(`Error in function ${remove.name}: ${error}`); console.error(`Error in function ${remove.name}: ${error}`);
@ -150,16 +151,16 @@ async function remove(req, res) {
*/ */
async function setStatus(req, res) { async function setStatus(req, res) {
try { try {
const canPersonSetStatus = Application.canPersonSetStatus(req.params.idApplication, req.jwt.person_id); const canPersonSetStatus = Application.canPersonSetStatus(req.body.jobApplication, req.jwt.person_id);
if (!canPersonSetStatus) { if (!canPersonSetStatus) {
return res.status(401).json({ return res.status(401).json({
error: 'Forbidden' error: 'Forbidden'
}); });
} }
await Application.setStatus(req.params.idApplication, req.body.status); await Application.setStatus(req.body.jobApplication, req.body.status);
return res.status(204).send(); return res.status(204).send();
} catch (error) { } catch (error) {
console.error(`Error in function ${setStatus.name}: ${error}`); console.error(`Error in function ${remove.name}: ${error}`);
res.status(500).json({ res.status(500).json({
error: 'Internal server error' error: 'Internal server error'
}); });
@ -167,14 +168,13 @@ async function setStatus(req, res) {
} }
const routes = express.Router(); const routes = express.Router();
routes.post('/joboffers/:idJobOffer', jwtUtils.extractToken, insert); routes.post('/', jwtUtils.extractToken, insert);
routes.get('/applications/mine', jwtUtils.extractToken, myApplications); // TODO: filter by organization as well routes.get('/myapplications', jwtUtils.extractToken, myApplications);
routes.get('/:idOrganization/joboffers/:idJobOffer', jwtUtils.extractToken, getApplicantsByJobOffer); routes.get('/applicantsbyjoboffer', jwtUtils.extractToken, getApplicantsByJobOffer);
routes.get('/:idOrganization/', jwtUtils.extractToken, getApplicantsByOrganization); routes.get('/applicantsbyorganization', jwtUtils.extractToken, getApplicantsByOrganization);
routes.delete('/joboffers/applications/:idApplication', jwtUtils.extractToken, remove); routes.delete('/', jwtUtils.extractToken, remove);
routes.patch('/joboffers/applications/:idApplication', jwtUtils.extractToken, setStatus); routes.patch('/', jwtUtils.extractToken, setStatus);
// TODO: Get by single application
// TODO: Change routes (see if practical)
module.exports = { module.exports = {
routes routes
}; };