Skip to content

Commit

Permalink
Try filtering more duplicate entries
Browse files Browse the repository at this point in the history
  • Loading branch information
Keskimaki committed Nov 23, 2023
1 parent 7c60e5a commit fe89893
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
5 changes: 4 additions & 1 deletion server/scripts/automatedAddToDb.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ const { sendSentryMessage } = require('@utils/sentry')
const db = require('../models/index')
const { processEntries } = require('./processEntries')
const attainmentsToSisu = require('../utils/sendToSisu')
const { filterDuplicateMatches } = require('../utils/earlierCompletions')

const automatedAddToDb = async (allMatches, course, batchId, sendToSisu = false) => {
const matches = filterDuplicateMatches(allMatches)

const automatedAddToDb = async (matches, course, batchId, sendToSisu = false) => {
const transaction = await db.sequelize.transaction()

if (!matches.length) {
Expand Down
13 changes: 12 additions & 1 deletion server/utils/earlierCompletions.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,15 @@ const advancedFound = (advancedAttainments, oldBaiAttainments, studentNumber, co
return false
}

module.exports = { isImprovedGrade, identicalCompletionFound, earlierBaiCompletionFound, advancedFound }
const filterDuplicateMatches = (matches) => {
const uniqueMatches = []
matches.forEach((match) => {
if (!uniqueMatches.some((m) => m.studentNumber === match.studentNumber && m.courseId === match.courseId)) {
uniqueMatches.push(match)
}
})

return uniqueMatches
}

module.exports = { isImprovedGrade, identicalCompletionFound, earlierBaiCompletionFound, advancedFound, filterDuplicateMatches }

0 comments on commit fe89893

Please sign in to comment.