cityssm/attendance-tracking

View on GitHub
database/getEmployeePropertyNames.ts

Summary

Maintainability
B
5 hrs
Test Coverage
import { connect as sqlPoolConnect } from '@cityssm/mssql-multi-pool'
import type { IResult } from 'mssql'

import { getConfigProperty } from '../helpers/functions.config.js'

export async function getEmployeePropertyNames(): Promise<string[]> {
  const pool = await sqlPoolConnect(getConfigProperty('mssql'))

  const propertyResult: IResult<{ propertyName: string }> = await pool.request()
    .query(`select
      distinct propertyName
      from MonTY.EmployeeProperties
      where recordDelete_dateTime is null
      and employeeNumber in (select employeeNumber from MonTY.Employees where recordDelete_dateTime is null)
      order by propertyName`)

  const propertyNames: string[] = []

  for (const record of propertyResult.recordset) {
    propertyNames.push(record.propertyName)
  }

  return propertyNames
}