Skip to content

Commit

Permalink
fixed an undefined error
Browse files Browse the repository at this point in the history
  • Loading branch information
25DanielG committed Jan 7, 2023
1 parent 77ff7f8 commit 7e9b6a6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Binary file added .DS_Store
Binary file not shown.
9 changes: 6 additions & 3 deletions app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ app.get('/', async(req, res) => {
});

app.post('/', async(req, res) => {
let essay = (await UserEssay.find({ name: req.body.name }).limit(1)).at(0);
let essays = await UserEssay.find({ name: req.body.name });
let essay = essays ? essays[0] : undefined;
if(essay) {
if(!essay.inProgress) {
res.redirect(url.format({
Expand Down Expand Up @@ -85,7 +86,8 @@ app.post('/teacher', async(req, res) => {
});

app.get('/student', async(req, res) => {
let doc = (await UserEssay.find({ name: req.query.name }).limit(1)).at(0);
let docs = await UserEssay.find({ name: req.query.name });
let doc = docs ? docs[0] : undefined;
if(doc)
res.render('student', { API_KEY: process.env.API_KEY, CLIENT_ID: process.env.CLIENT_ID, CLIENT_SECRET: process.env.CLIENT_SECRET, essay: doc });
else
Expand All @@ -112,7 +114,8 @@ app.get('/teacher/view/:id', async(req, res) => {

app.post('/student', async(req, res) => {
let grade = gradeEssay(req.body.content);
let essay = (await UserEssay.find({ name: req.body.name }).limit(1)).at(0);
let essays = await UserEssay.find({ name: req.body.name });
let essay = essays ? essays[0] : undefined;
await UserEssay.updateOne({ name: req.body.name },
{
$set: {
Expand Down

0 comments on commit 7e9b6a6

Please sign in to comment.