Also * reorder graphQl queries: Always a query constant + update function * use id instead of token (initials) to identify person in url * Remove any party logo related sections since currently not needed * Move "options" from data closer to actual code since it doesn't really belong to data (data may be deleted in the future, anyway) * add nodeId in gql queries wherever possible to avoid problems with the apollo cache * add note about graphql schema import to README.mdpull/6/head
parent
5512955af4
commit
64e6b861b6
11 changed files with 196 additions and 4035 deletions
@ -1,72 +1,115 @@ |
||||
import gql from 'graphql-tag' |
||||
import { options } from '@/data' |
||||
import possiblePositions from '@/app/euromat/possiblePositions' |
||||
|
||||
export const apolloTheses = { |
||||
query: gql`{
|
||||
allQuestions(orderBy: ID_ASC) { |
||||
nodes { |
||||
category: categoryByCategoryId { |
||||
title |
||||
} |
||||
text |
||||
id |
||||
export function getPositionById (id) { |
||||
return possiblePositions.find(option => option.id === id).position |
||||
} |
||||
|
||||
export const apolloThesesQuery = gql`{
|
||||
allQuestions(orderBy: ID_ASC) { |
||||
nodes { |
||||
category: categoryByCategoryId { |
||||
nodeId |
||||
title |
||||
} |
||||
text |
||||
id |
||||
nodeId |
||||
} |
||||
}`,
|
||||
update: data => data.allQuestions.nodes.map(node => ({ |
||||
id: node.id, |
||||
thesis: { |
||||
de: node.text |
||||
}, |
||||
category: { |
||||
de: node.category.title |
||||
} |
||||
})) |
||||
} |
||||
} |
||||
}` |
||||
|
||||
export const apolloThesesUpdate = data => data.allQuestions.nodes.map(node => ({ |
||||
id: node.id, |
||||
thesis: { |
||||
de: node.text |
||||
}, |
||||
category: { |
||||
de: node.category.title |
||||
} |
||||
})) |
||||
|
||||
export const apolloThesesCountQuery = gql`{
|
||||
allQuestions { |
||||
totalCount |
||||
} |
||||
}` |
||||
|
||||
export const apolloThesesCount = { |
||||
query: gql`{
|
||||
allQuestions { |
||||
totalCount |
||||
export const apolloThesesCountUpdate = data => data.allQuestions.totalCount |
||||
|
||||
export const apolloPersonsForResultsQuery = gql`{
|
||||
allPeople(condition: {role: CANDYMAT_CANDIDATE}) { |
||||
nodes { |
||||
nodeId |
||||
firstName |
||||
lastName |
||||
id |
||||
answersByPersonId { |
||||
nodes { |
||||
nodeId |
||||
position |
||||
questionId |
||||
text |
||||
} |
||||
} |
||||
} |
||||
}`,
|
||||
update: data => data.allQuestions.totalCount |
||||
} |
||||
} |
||||
}` |
||||
|
||||
function getPositionById (id) { |
||||
return options.find(option => option.id === id).position |
||||
} |
||||
export const apolloPersonsForResultsUpdate = data => data.allPeople.nodes.map(person => ({ |
||||
id: person.id, |
||||
name: `${person.firstName} ${person.lastName}`, |
||||
token: person.firstName.charAt(0) + person.lastName.charAt(0), |
||||
positions: person.answersByPersonId.nodes.map(answer => ({ |
||||
thesis: answer.questionId, |
||||
position: getPositionById(answer.position), |
||||
statement: { |
||||
de: answer.text |
||||
} |
||||
})) |
||||
})) |
||||
|
||||
export const apolloPersonsForResults = { |
||||
query: gql`{
|
||||
allPeople(condition: {role: CANDYMAT_CANDIDATE}) { |
||||
nodes { |
||||
firstName |
||||
lastName |
||||
id |
||||
answersByPersonId { |
||||
nodes { |
||||
position |
||||
questionId |
||||
export const apolloPersonPositionsQuery = gql` |
||||
query Person($partyId: Int!) { |
||||
personById(id: $partyId) { |
||||
nodeId |
||||
id |
||||
firstName |
||||
lastName |
||||
answersByPersonId { |
||||
nodes { |
||||
nodeId |
||||
position |
||||
personId |
||||
text |
||||
questionByQuestionId { |
||||
nodeId |
||||
categoryByCategoryId { |
||||
nodeId |
||||
title |
||||
} |
||||
text |
||||
id |
||||
description |
||||
} |
||||
} |
||||
} |
||||
} |
||||
}` |
||||
} |
||||
|
||||
export function parseApolloPersonForResults (data) { |
||||
return data.allPeople.nodes.map(person => ({ |
||||
id: person.id, |
||||
name: `${person.firstName} ${person.lastName}`, |
||||
token: person.firstName.charAt(0) + person.lastName.charAt(0), |
||||
positions: person.answersByPersonId.nodes.map(answer => ({ |
||||
thesis: answer.questionId, |
||||
export const apolloPersonPositionsUpdate = data => ({ |
||||
id: data.personById.id, |
||||
name: `${data.personById.firstName} ${data.personById.lastName}`, |
||||
token: data.personById.firstName.charAt(0) + data.personById.lastName.charAt(0), |
||||
theses: data.personById.answersByPersonId.nodes.map(answer => { |
||||
const question = answer.questionByQuestionId |
||||
return { |
||||
id: question.id, |
||||
thesis: question.text, |
||||
category: question.categoryByCategoryId.title, |
||||
position: getPositionById(answer.position), |
||||
statement: { |
||||
de: answer.text |
||||
} |
||||
})) |
||||
})) |
||||
} |
||||
statement: answer.text, |
||||
showStatement: false |
||||
} |
||||
}) |
||||
}) |
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,45 +0,0 @@ |
||||
const theses = [ |
||||
{ |
||||
'id': 0, |
||||
'category': { |
||||
'de': 'Politische Bildung', |
||||
'en': 'Civic Education', |
||||
'fr': 'Education civique', |
||||
'dk': 'Medborgerskab', |
||||
'si': 'Državljanska vzgoja', |
||||
'cz': 'Občanské vzdělávání', |
||||
'pl': 'Edukacja obywatelska' |
||||
}, |
||||
'thesis': { |
||||
'de': 'Europapolitische Bildung sollte Teil der Lehrpläne aller Mitgliedsländer sein.', |
||||
'en': 'European civic education should be part of the school curricula of all member countries.', |
||||
'fr': 'L’éducation civique européenne devrait faire partie des programmes scolaires de tous les Etats-membres.', |
||||
'dk': 'Europæisk medborgerskab skal være en del af skolepensum i alle medlemslande.', |
||||
'si': 'Evropska državljanska vzgoja bi morala biti del šolskega kurikuluma v vseh državah članicah.', |
||||
'cz': 'Evropské občanské vzdělávání by mělo být součástí školních osnov ve všech členských státech.', |
||||
'pl': 'Europejska edukacja obywatelska powinna być częścią programów nauczania we wszystkich państwach członkowskich.' |
||||
} |
||||
}, |
||||
{ |
||||
'id': 1, |
||||
'category': { |
||||
'de': 'Europäische Armee', |
||||
'en': 'European Army', |
||||
'fr': 'Forces armées', |
||||
'dk': 'Fælles forsvar', |
||||
'si': 'Evropska vojska', |
||||
'cz': 'Evropská armáda', |
||||
'pl': 'Armia europejska' |
||||
}, |
||||
'thesis': { |
||||
'de': 'Langfristig sollten die EU-Mitgliedstaaten ihre Streitkräfte zu einer europäischen Armee zusammenschließen.', |
||||
'en': 'In the long-term EU member states should merge their armed forces to a European army.', |
||||
'fr': "A terme, les forces armées des pays membres de l'UE devraient fusionner.", |
||||
'dk': 'På lang sigt skal EU-medlemslandenes forsvar samles i en fælles europæisk hær.', |
||||
'si': 'Države članice EU bi morale na dolgi rok združiti svoje oborožene sile v skupno evropsko vojsko.', |
||||
'cz': 'V dlouhodobém horizontu by měly být armády členských států sloučeny do Evropské armády.', |
||||
'pl': 'W perspektywie długoterminowej państwa członkowskie UE powinny połączyć swoje siły zbrojne w armię europejską.' |
||||
} |
||||
} |
||||
] |
||||
export default theses |
Loading…
Reference in new issue