<commit_before>import {getValues, batchGetValues, batchUpdateValues} from './sheets.js'
import {formatAsHyperlink, formatDate} from './utils'
import {sheets} from './constants'

export async function storeOrder(order, items) {
  const sheet = order.isCompany ? sheets.companyOrders : sheets.personalOrders

  const newRowIndex = await getNextEmptyRowIndex(sheet)

  const user = order.user
  const userJiraId = await getUserJiraId(user.id, user.name)

  const date = new Date()

  const itemToSheetData = order.isCompany
    ? mapCompanyOrderItemToSheetData
    : mapPersonalOrderItemToSheetData

  const data = items.map((item, index) => {
    return itemToSheetData(
      item,
      newRowIndex + index,
      order,
      sheet.name,
      userJiraId,
      date,
    )
  })

  await batchUpdateValues(sheet, {data, valueInputOption: 'USER_ENTERED'})
}

async function getNextEmptyRowIndex(sheet) {
  const values = await getValues(sheet.idRange)
  let firstEmpty = values.findIndex((v) => v.every((c) => !c))
<commit_msg>Store products with quantity > 1 as separate rows<commit_after>import {getValues, batchGetValues, batchUpdateValues} from './sheets.js'
import {formatAsHyperlink, formatDate} from './utils'
import {sheets} from './constants'

export async function storeOrder(order, items) {
  const sheet = order.isCompany ? sheets.companyOrders : sheets.personalOrders

  const newRowIndex = await getNextEmptyRowIndex(sheet)

  const user = order.user
  const userJiraId = await getUserJiraId(user.id, user.name)

  const date = new Date()

  const itemToSheetData = order.isCompany
    ? mapCompanyOrderItemToSheetData
    : mapPersonalOrderItemToSheetData

  const data = []

  for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
    const item = items[itemIndex]

    for (let i = 0; i < item.count; i++) {
      data.push(itemToSheetData(
        item,
        newRowIndex + itemIndex + i,
        order,
        sheet.name,
        userJiraId,
        date,
      ))
    }
  }

  await batchUpdateValues(sheet, {data, valueInputOption: 'USER_ENTERED'})
}

async function getNextEmptyRowIndex(sheet) {
  const values = await getValues(sheet.idRange)
  let firstEmpty = values.findIndex((v) => v.every((c) => !c))

{'fraction_non_alphanumeric': 0.10521622826571556, 'fraction_numerical': 0.0013374944271065537, 'mean_word_length': 3.815450643776824, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '2099370', 'n_tokens_mistral': 705, 'n_tokens_neox': 687, 'n_words': 174}