cityssm/attendance-tracking

View on GitHub
database/deleteEmployeeProperties.ts

Summary

Maintainability
A
0 mins
Test Coverage
import { connect as sqlPoolConnect } from '@cityssm/mssql-multi-pool'

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

export async function deleteEmployeeProperties(
  employeeNumber: string,
  isSyncUpdate: boolean,
  sessionUser: AttendUser
): Promise<number> {
  const pool = await sqlPoolConnect(getConfigProperty('mssql'))

  const result = await pool
    .request()
    .input('employeeNumber', employeeNumber)
    .input('record_userName', sessionUser.userName)
    .input('record_dateTime', new Date()).query(`update MonTY.EmployeeProperties
      set recordDelete_userName = @record_userName,
        recordDelete_dateTime = @record_dateTime
      where employeeNumber = @employeeNumber
        and recordDelete_dateTime is not null
        ${isSyncUpdate ? ' and isSynced = 1' : ''}`)

  clearCacheByTableName('EmployeeProperties')

  return result.rowsAffected[0]
}