Skip to content

Commit

Permalink
Fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ShootingStar91 committed Jan 23, 2024
1 parent 8bdd123 commit 071de8d
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 77 deletions.
25 changes: 1 addition & 24 deletions importer-db-api/src/routes/palaute/palaute.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,12 @@
const { Op, QueryTypes } = require('sequelize')
const { Op } = require('sequelize')
const express = require('express')
const models = require('../../models')
const { sequelize } = require('../../config/db')
const { relevantAttributes, validRealisationTypes } = require('./config')
const { isRefreshingPersonStudyRightsView } = require('./personStudyRightsView')
const _ = require('lodash')

const defaultSince = new Date('2021-01-01')

const attributesToSql = (table, attributes) => {
return attributes.map(attribute => `${table}.${_.snakeCase(attribute)} "${attribute}"`).join(', ')
}

const getCourseRealisationsWithCourseUnits = async (limit, offset) => {
const sql = `
SELECT
${attributesToSql('cur', relevantAttributes.courseUnitRealisation)},
json_agg(ass) as "assessmentItems"
FROM course_unit_realisations cur
INNER JOIN assessment_items ass ON ass.id = ANY (cur.assessment_item_ids)
WHERE cur.course_unit_realisation_type_urn IN (:validRealisationTypes)
GROUP BY cur.id
LIMIT :limit OFFSET :offset
`

return await sequelize.query(sql, {
replacements: { limit, offset, validRealisationTypes },
queryType: QueryTypes.SELECT,
})
}

const addCourseUnitsToRealisations = async courseUnitRealisations => {
const assessmentItemIds = courseUnitRealisations.flatMap(c => c.assessmentItemIds)
const assessmentItemsWithCrap = await models.AssessmentItem.findAll({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const { BOOLEAN } = require('sequelize')

module.exports = {
up: async queryInterface => {
await queryInterface.removeColumn('attainments', 'misregistration_rationale')
Expand Down
23 changes: 7 additions & 16 deletions importer-mankeli/src/debug/customHandlers/attainmentDebug.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,13 @@ const { ORI_ATTAINMENT_CHANNEL } = require('../../utils/stan')

const matcher = attainment => attainment.personId === 'RETRACTED'

const format = ({
id,
personId,
state,
attainmentDate,
type,
credits,
documentState,
metadata
}) => ({
id,
personId,
state,
attainmentDate,
type,
credits,
const format = ({ id, personId, state, attainmentDate, type, credits, documentState, metadata }) => ({
id,
personId,
state,
attainmentDate,
type,
credits,
documentState,
lastModifiedOn: metadata.lastModifiedOn,
modificationOrdinal: metadata.modificationOrdinal
Expand Down
17 changes: 6 additions & 11 deletions importer-mankeli/src/debug/customHandlers/curEnrolmentsDebug.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
const { ILMO_ENROLMENT_CHANNEL } = require('../../utils/stan')

const matcher = enrolment => enrolment.courseUnitRealisationId === 'hy-opt-cur-2324-f0c0d370-0087-4bb9-93aa-387e76bd11f2'
const matcher = enrolment =>
enrolment.courseUnitRealisationId === 'hy-opt-cur-2324-f0c0d370-0087-4bb9-93aa-387e76bd11f2'

const format = ({
const format = ({ id, state, personId, documentState, metadata }) => ({
id,
state,
personId,
documentState,
metadata
}) => ({
id,
state,
personId,
documentState,
lastModifiedOn: metadata.lastModifiedOn,
modificationOrdinal: metadata.modificationOrdinal
})
lastModifiedOn: metadata.lastModifiedOn,
modificationOrdinal: metadata.modificationOrdinal
})

module.exports = {
channel: ILMO_ENROLMENT_CHANNEL,
Expand Down
36 changes: 19 additions & 17 deletions importer-mankeli/src/debug/debugHandlerBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,37 @@ let counter = 5
let interestingItems = []

const debugPrinter = (channel, object) => {
const string = `[DEBUGGER_${channel}] Item of interest found: \n${JSON.stringify({
object
}, null, 2)}\n`
logger.info(
string
)
const string = `[DEBUGGER_${channel}] Item of interest found: \n${JSON.stringify(
{
object
},
null,
2
)}\n`
logger.info(string)
interestingItems.push(string)
counter -= 1
if (counter === 0) {
counter = 5
logger.info("INTERESTING_ITEMS")
logger.info('INTERESTING_ITEMS')
interestingItems.forEach(item => logger.info(item))
}
}

const createDebugHandler = (channel, matcher, format) => {
return {
channel,
handler: msg => {
const entitiesOfInterest = msg.entities.filter(matcher)
if (entitiesOfInterest.length > 0) {
try {
entitiesOfInterest.forEach(obj => debugPrinter(channel, format(obj)))
/* eslint-disable-next-line no-empty */
} catch (e) {}
channel,
handler: msg => {
const entitiesOfInterest = msg.entities.filter(matcher)
if (entitiesOfInterest.length > 0) {
try {
entitiesOfInterest.forEach(obj => debugPrinter(channel, format(obj)))
/* eslint-disable-next-line no-empty */
} catch (e) {}
}
return msg
}
return msg
}
}
}

module.exports = { createDebugHandler }
4 changes: 3 additions & 1 deletion importer-mankeli/src/debug/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ const attainmentDebug = require('./customHandlers/attainmentDebug')
const { createDebugHandler } = require('./debugHandlerBuilder')

// Create handler in customhandler folder. Import it and add it in this array.
const debugHandlers = [attainmentDebug].map(({ channel, matcher, format }) => createDebugHandler(channel, matcher, format))
const debugHandlers = [attainmentDebug].map(({ channel, matcher, format }) =>
createDebugHandler(channel, matcher, format)
)

module.exports = {
debugHandlers
Expand Down
12 changes: 6 additions & 6 deletions importer-mankeli/src/utils/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ const getColumnsToUpdate = (model, keys) => Object.keys(model.rawAttributes).fil

const bulkCreate = async (model, entities, transaction, properties = ['id']) => {
try {
await model.bulkCreate(entities, {
updateOnDuplicate: getColumnsToUpdate(model, properties),
transaction
})
await model.bulkCreate(entities, {
updateOnDuplicate: getColumnsToUpdate(model, properties),
transaction
})
} catch (error) {
// If one fails on bulkCreate, re-do them individually and report the individual failures.
for (const entity of entities) {
Expand All @@ -18,8 +18,8 @@ const bulkCreate = async (model, entities, transaction, properties = ['id']) =>
transaction
})
} catch (e) {
console.log("Single-entity upsert failed: ", JSON.stringify(e, null, 2))
console.log("Entity:")
console.log('Single-entity upsert failed: ', JSON.stringify(e, null, 2))
console.log('Entity:')
console.log(JSON.stringify(entity, null, 2))
}
}
Expand Down

0 comments on commit 071de8d

Please sign in to comment.