-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
2,242 additions
and
127 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,30 @@ | ||
const candidatesData = require('../data-sources/candidates.json'); | ||
const { | ||
getAllCandidates, | ||
getCandidateById, | ||
getCandidateByEmail, | ||
} = require('../services/candidates'); | ||
|
||
const getCandidateById = (id) => { | ||
const candidate = candidatesData[id]; | ||
if (!candidate) return null; | ||
|
||
candidate.id = id; | ||
return candidate; | ||
}; | ||
|
||
const getCandidateByEmail = (email) => { | ||
const candidates = Object.keys(candidatesData).map(key => { | ||
const candidate = candidatesData[key]; | ||
|
||
return { | ||
id: key, | ||
...candidate, | ||
}; | ||
}); | ||
const resolver = { | ||
Query: { | ||
candidates: () => getAllCandidates(), | ||
|
||
return candidates.find( | ||
candidate => candidate.email === email, | ||
); | ||
}; | ||
candidate: (_, params, req, advancedDetails) => { | ||
const { id, email } = params; | ||
|
||
const resolver = { | ||
candidate: ({ id, email }) => { | ||
if (id) return getCandidateById(id); | ||
if (email) return getCandidateByEmail(email); | ||
throw new Error('Specify either an "id" or the "email"'); | ||
if (id) return getCandidateById(id); | ||
if (email) return getCandidateByEmail(email); | ||
throw new Error('Specify either an "id" or the "email"'); | ||
}, | ||
}, | ||
|
||
Candidate_id: (candidate) => candidate.id, | ||
Candidate_name: (candidate) => candidate.name, | ||
Candidate_email: (candidate) => candidate.email, | ||
Candidate_profession: (candidate) => candidate.profession, | ||
Candidate_photo: (candidate) => candidate.photo, | ||
Candidate_following: (candidate) => candidate.following, | ||
Candidate: { | ||
id: (candidate) => candidate.id, | ||
name: (candidate) => candidate.name, | ||
email: (candidate) => candidate.email, | ||
profession: (candidate) => candidate.profession, | ||
photo: (candidate) => candidate.photo, | ||
following: (candidate) => candidate.following.map(getCandidateById), | ||
}, | ||
}; | ||
|
||
module.exports = resolver; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,26 @@ | ||
const companiesData = require('../data-sources/companies.json'); | ||
const { | ||
getAllCompanies, | ||
getCompanyById, | ||
} = require('../services/companies'); | ||
|
||
const { getJobAdById } = require('../services/jobAds'); | ||
|
||
const resolver = { | ||
company: () => 'TODO', | ||
Query: { | ||
companies: () => getAllCompanies(), | ||
|
||
company: (_, params, req, advancedDetails) => { | ||
const { id } = params; | ||
return getCompanyById(id); | ||
}, | ||
}, | ||
|
||
Company: { | ||
id: (company) => company.id, | ||
name: (company) => company.name, | ||
photo: (company) => company.photo, | ||
openJobAds: (company) => company.openJobAds.map(getJobAdById), | ||
}, | ||
}; | ||
|
||
module.exports = resolver; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,28 @@ | ||
const jobAdsData = require('../data-sources/job-ads.json'); | ||
const { | ||
getAllJobAds, | ||
getJobAdById, | ||
} = require('../services/jobAds'); | ||
|
||
const { getCompanyById } = require('../services/companies'); | ||
|
||
const resolver = { | ||
jobAd: () => 'TODO', | ||
Query: { | ||
jobAds: () => getAllJobAds(), | ||
|
||
jobAd: (_, params, req, advancedDetails) => { | ||
const { id } = params; | ||
return getJobAdById(id); | ||
}, | ||
}, | ||
|
||
JobAd: { | ||
id: (jobAd) => jobAd.id, | ||
title: (jobAd) => jobAd.title, | ||
description: (jobAd) => jobAd.description, | ||
forCompany: (jobAd) => getCompanyById(jobAd.forCompany), | ||
requiredProfession: (jobAd) => jobAd.requiredProfession, | ||
remainingVacancies: (jobAd) => jobAd.remainingVacancies, | ||
}, | ||
}; | ||
|
||
module.exports = resolver; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
const resolver = { | ||
ping: () => 'pong', | ||
Query: { | ||
ping: () => 'pong', | ||
}, | ||
}; | ||
|
||
module.exports = resolver; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,16 @@ | ||
/** | ||
* @see: https://graphql.org/graphql-js/type/#graphqlschema | ||
* @see: https://github.com/Urigo/graphql-scalars | ||
*/ | ||
const { GraphQLScalarType } = require('graphql'); | ||
const { | ||
EmailAddress, | ||
URL, | ||
NonNegativeInt, | ||
} = require('graphql-scalars'); | ||
|
||
const resolver = { | ||
Email: new GraphQLScalarType({ | ||
name: 'Email', | ||
description: 'An email address', | ||
|
||
serialize: (value) => value, | ||
|
||
parseValue: (value) => { | ||
const isValid = value.match(/[a-zA-Z0-9._]@[a-z][.]com/g); | ||
if (!isValid) throw new Error('Invalid email format'); | ||
|
||
return value; | ||
}, | ||
|
||
parseLiteral: (ast) => ast.value, | ||
}), | ||
EmailAddress, | ||
URL, | ||
NonNegativeInt, | ||
}; | ||
|
||
module.exports = resolver; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const candidatesData = require('../data-sources/candidates.json'); | ||
|
||
const getAllCandidates = () => { | ||
const candidates = Object.keys(candidatesData).map(key => { | ||
const candidate = candidatesData[key]; | ||
|
||
return { | ||
id: key, | ||
...candidate, | ||
}; | ||
}); | ||
|
||
return candidates; | ||
}; | ||
|
||
const getCandidateById = (id) => { | ||
const candidate = candidatesData[id]; | ||
if (!candidate) return null; | ||
|
||
candidate.id = id; | ||
return candidate; | ||
}; | ||
|
||
const getCandidateByEmail = (email) => { | ||
const candidates = getAllCandidates(); | ||
|
||
return candidates.find( | ||
candidate => candidate.email === email, | ||
); | ||
}; | ||
|
||
module.exports = { | ||
getAllCandidates, | ||
getCandidateById, | ||
getCandidateByEmail, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const companiesData = require('../data-sources/companies.json'); | ||
|
||
const getAllCompanies = () => { | ||
return companiesData; | ||
}; | ||
|
||
const getCompanyById = (id) => { | ||
return companiesData.find( | ||
company => company.id == id, | ||
); | ||
}; | ||
|
||
module.exports = { | ||
getAllCompanies, | ||
getCompanyById, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const jobAdsData = require('../data-sources/job-ads.json'); | ||
|
||
const getAllJobAds = () => { | ||
const jobAds = Object.keys(jobAdsData).map(key => { | ||
const jobAd = jobAdsData[key]; | ||
|
||
return { | ||
id: key, | ||
...jobAd, | ||
}; | ||
}); | ||
|
||
return jobAds; | ||
}; | ||
|
||
const getJobAdById = (id) => { | ||
const jobAd = jobAdsData[id]; | ||
if (!jobAd) return null; | ||
|
||
jobAd.id = id; | ||
return jobAd; | ||
}; | ||
|
||
module.exports = { | ||
getAllJobAds, | ||
getJobAdById, | ||
}; |
Oops, something went wrong.