cityssm/corporate-records-manager

View on GitHub
helpers/recordsDB/getRecordUsers.ts

Summary

Maintainability
C
7 hrs
Test Coverage
import * as sqlPool from "@cityssm/mssql-multi-pool";
import * as configFns from "../configFns.js";

import type * as recordTypes from "../../types/recordTypes";
import type * as sqlTypes from "mssql";

import debug from "debug";
const debugSQL = debug("corporate-records-manager:recordsDB:getRecordUsers");


export const getRecordUsers = async (recordID: number | string): Promise<recordTypes.RecordUser[]> => {

  try {
    const pool: sqlTypes.ConnectionPool =
      await sqlPool.connect(configFns.getProperty("mssqlConfig"));

    const result = await pool.request()
      .input("recordID", recordID)
      .query("select recordUserID, recordID, userName, recordUserTypeKey" +
        " from CR.RecordUsers" +
        " where recordID = @recordID" +
        " and recordDelete_datetime is null" +
        " order by userName");

    if (result.recordset && result.recordset.length > 0) {
      return result.recordset;
    }

  } catch (error) {
    debugSQL(error);
  }

  return [];
};


export default getRecordUsers;