{"size": 1032, "ext": "js", "max_stars_repo_path": "importer-mankeli/src/messageHandlers/organisation.js", "max_stars_repo_name": "UniversityOfHelsinkiCS/sis-updater", "max_stars_repo_stars_event_min_datetime": "2021-03-22T10:34:14.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-22T10:34:14.000Z", "max_issues_repo_path": "importer-mankeli/src/messageHandlers/organisation.js", "max_issues_repo_name": "UniversityOfHelsinkiCS/sis-importer", "max_issues_repo_issues_event_min_datetime": "2020-02-11T09:47:06.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-13T22:17:06.000Z", "max_forks_repo_path": "importer-mankeli/src/messageHandlers/organisation.js", "max_forks_repo_name": "UniversityOfHelsinkiCS/sis-importer", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": 56, "max_forks_count": null, "avg_line_length": 38.2222222222, "max_line_length": 107, "alphanum_fraction": 0.7548449612}
const { Organisation } = require('../db/models')
const { bulkCreate } = require('../utils/db')

const parseOrganisation = organisation => {
  return {
    id: organisation.id,
    documentState: organisation.documentState,
    snapshotDateTime: organisation.snapshotDateTime,
    universityOrgId: organisation.universityOrgId,
    parentId: organisation.parentId,
    predecessorIds: organisation.predecessorIds,
    code: organisation.code,
    name: organisation.name,
    abbreviation: organisation.abbreviation,
    status: organisation.status,
    educationalInstitutionUrn: organisation.educationalInstitutionUrn,
    modificationOrdinal: organisation.metadata.modificationOrdinal
  }
}

// Organisations need to be written into
// the db in a similar fashion as studyrights.
module.exports = async ({ active, deleted }, transaction) => {
  const parsedOrganisations = [...active, ...deleted].map(parseOrganisation)
  await bulkCreate(Organisation, parsedOrganisations, transaction, ['id', 'modificationOrdinal', 'autoId'])
}
