-
-
Save DanyF-github/b418edd493c537ef670964ae9183802c to your computer and use it in GitHub Desktop.
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
// src/graphql/homework.js | |
... | |
const saveHomework = async (_, { description }, __, ___) => { | |
const uuid = uuidv4(); | |
try { | |
const homework = { | |
uuid, | |
description | |
} | |
homeworks.push(homework); | |
return homework; | |
} catch (err) { | |
console.error('Error while trying to create homework', err); | |
throw new Error(INTERNAL_ERROR); | |
} | |
}; | |
const getHomeworks = (_, __, ___, ____) => { | |
return homeworks; | |
}; | |
const getHomework = (_, { uuid }, __, ___) => { | |
const [homework] = homeworks.filter((homework) => homework.uuid === uuid); | |
return homework; | |
}; | |
const addHomeworkFile = async (_, { url, uuid, token }, __, ___) => { | |
// This token comes from the passwordless login | |
if (!token) { | |
throw new Error(NOT_AUTHENTICATED); | |
} | |
try { | |
const decodedToken = jwt.verify(token, accessTokenSecret); | |
const [student] = students.filter((student) => student.phoneNumber === decodedToken.phoneNumber) | |
const [homework] = homeworks.filter((homework) => homework.uuid === uuid); | |
const homeworkFile = { | |
url, | |
student, | |
homework, | |
}; | |
homeworkFiles.push(homeworkFile); | |
return homeworkFile; | |
} catch (err) { | |
console.log('An error occurredocurred when trying to save homework file', err); | |
throw new Error(INTERNAL_ERROR); | |
} | |
}; | |
const getHomeworkFiles = (_, { uuid }, __, ___) => { | |
return homeworkFiles.filter(homeworkFile => homeworkFile.homework.uuid === uuid); | |
}; | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment