Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Agenda won't do a 'Pull' and 'Push' Operation for an array of objects. #1535

Open
davvvvsss opened this issue May 22, 2023 · 1 comment
Open

Comments

@davvvvsss
Copy link

Agenda failed to perform a Pull and Push operation from an array of object.

const dotenv = require('dotenv');
const Agenda = require('agenda');

dotenv.config({ path: './config.env' });
const DB = process.env.DATABASE.replace(
  '<PASSWORD>',
  process.env.DATABASE_PASSWORD
);

const agenda = new Agenda({
  db: { address: DB, collection: 'autoSubmitting' },
});

const assessmentAutoSubmission = async function (assessment, questions, body) {
  const testing = await Testing.findOne({
    assessment: assessment._id,
    email: body.email,
    accessCode: body.accessCode,
  }).sort({ createdAt: -1 });

  if (testing.autoSubmit === false) {
    testing.autoSubmit = true;
    testing.submittedAt = testing.toEndAt; //emdAT shouldn't be like this
    await testing.save();

    for (const value of assessment.duringExam) {
      if (value.email === body.email || value.accessCode === body.accessCode) {
        assessment.duringExam.pull(value);
        assessment.afterExam.push(value);
        await assessment.save();
      }
    }
  }

  // score;
  await new Scoring(testing, assessment, questions).allIsObjective();
};

Every other operation works including the callback after the Pull and Push operation.

Mongo DB Log below

{
  "_id": {
    "$oid": "646bafd414b0464d279422fb"
  },
  "name": "autoSubmitting",
  "data": {
    "assessment": {
      "_id": "16480418-0b4b-4a6b-b5d3-3a258547ec87",
      "name": "pinia",
      "numberOfQuestions": 4,
      "instruction": "document",
      "duration": 1,
      "passmark": 23,
      "portalOpen": {
        "$date": "2023-04-29T07:39:35.807Z"
      },
      "portalClose": {
        "$date": "2023-05-29T07:50:35.807Z"
      },
      "randomizeQuestion": false,
      "beforeExam": [],
      "category": "1076be9c-21a2-4090-8aa1-1c46d9ca3cff",
      "user": "70d8ea3b-2c4f-40bc-a9e7-ff20840a224f",
      "duringExam": [
        {
          "email": "1@gipmfrica.com",
          "accessCode": "1"
        },
        {
          "email": "2@gipmfrica.com",
          "accessCode": "2"
        }
      ],
      "afterExam": [],
      "createdAt": {
        "$date": "2023-04-29T07:40:23.964Z"
      },
      "updatedAt": {
        "$date": "2023-05-22T18:09:24.265Z"
      },
      "__v": 156
    },
    "questions": [],
    "body": {
      "email": "2@gipmafrica.com",
      "accessCode": "2",
      "id": "",
      "questionNumber": "",
      "options": ""
    }
  },
  "priority": 0,
  "shouldSaveResult": false,
  "type": "normal",
  "nextRunAt": null,
  "lastModifiedBy": null,
  "lockedAt": null,
  "lastRunAt": {
    "$date": "2023-05-22T18:10:24.760Z"
  },
  "failCount": 1,
  "failReason": "assessment.duringExam.pull is not a function",
  "failedAt": {
    "$date": "2023-05-22T18:10:24.839Z"
  },
  "lastFinishedAt": {
    "$date": "2023-05-22T18:10:24.839Z"
  }
}
@davvvvsss
Copy link
Author

davvvvsss commented May 22, 2023

It loop correctly but won't perform the Pull and Push Operation.
"failReason": "assessment.duringExam.pull is not a function",

@davvvvsss davvvvsss changed the title Agenda can't do a 'Pull' Operation Agenda can't do a 'Pull' and 'Push' Operation for an array of objects. May 22, 2023
@davvvvsss davvvvsss changed the title Agenda can't do a 'Pull' and 'Push' Operation for an array of objects. Agenda won't do a 'Pull' and 'Push' Operation for an array of objects. May 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant