<commit_before>const {writeLine} = require('../csvFile')
const canvasApi = require('../canvasApi')
const fileName = 'staff_enroll.csv'

async function handleStaffMessage (msg) {
  console.log('Handle STAFF')
  // TODO: delete before create
  await writeLine(['section_id', 'user_id', 'role', 'status'], fileName)
  for (let i of [1, 2, 3, 4, 5]) {
    const sisSectionId = `${msg.ug1Name}.section_${i}`
    for (let member of msg.member) {
      await writeLine([sisSectionId, member, msg._desc.userType, 'active'], fileName)
    }
  }
  const canvasReturnValue = await canvasApi.sendCsvFile(fileName, true)
  return {msg, resp: canvasReturnValue}
}

module.exports = {handleStaffMessage}
<commit_msg>delete the file before appending staff<commit_after>const {writeLine} = require('../csvFile')
const canvasApi = require('../canvasApi')
const config = require('../config')
const fileName = `${config.localFile.csvDir}/staff_enroll.csv`
const {promisify} = require('util')
const unlink = promisify(require('fs').unlink)
const logging = require('../server/logging')

async function handleStaffMessage (msg) {
  // TODO: delete before create
  try {
    await fs.unlink(fileName)

  } catch (e) {
      logging.info('Couldnt delete file. This is fine.')
  }

  await writeLine(['section_id', 'user_id', 'role', 'status'], fileName)
  for (let i of [1, 2, 3, 4, 5]) {
    const sisSectionId = `${msg.ug1Name}.section_${i}`
    for (let member of msg.member) {
      await writeLine([sisSectionId, member, msg._desc.userType, 'active'], fileName)
    }
  }
  const canvasReturnValue = await canvasApi.sendCsvFile(fileName, true)
  return {msg, resp: canvasReturnValue}
}

module.exports = {handleStaffMessage}

{'fraction_non_alphanumeric': 0.15073313782991202, 'fraction_numerical': 0.007038123167155425, 'mean_word_length': 4.485530546623794, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2110828', 'n_tokens_mistral': 553, 'n_tokens_neox': 555, 'n_words': 144}