Skip to content

Commit 0a9ed70

Browse files
committed
adding getEmployeeTimeCodes()
1 parent 41bd539 commit 0a9ed70

8 files changed

Lines changed: 153 additions & 0 deletions

File tree

index.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,18 @@ export declare class WorkTechAPI {
171171
* @returns The available time codes.
172172
*/
173173
getTimeCodes(): Promise<TimeCode[]>;
174+
/**
175+
* Retrieves time codes for a specific employee.
176+
* @param employeeNumber - The employee number.
177+
* @param timesheetMaxAgeDays - The maximum timesheet age.
178+
* @returns The time codes for the specified employee.
179+
*/
180+
getEmployeeTimeCodes(employeeNumber: string, timesheetMaxAgeDays: number): Promise<TimeCode[]>;
174181
getTimesheetBatchEntries(filters: GetTimesheetBatchEntriesFilters): Promise<TimesheetBatchEntry[]>;
175182
}
176183
export { getAccountNumberByWorkOrderNumberAndObjectCode } from './helpers/getAccountNumber.js';
177184
export { getEmployeePayCodes } from './queries/employees/getEmployeePayCodes.js';
185+
export { getEmployeeTimeCodes } from './queries/employees/getEmployeeTimeCodes.js';
178186
export { getTimeCodes } from './queries/employees/getTimeCodes.js';
179187
export { type GetTimesheetBatchEntriesFilters, getTimesheetBatchEntries } from './queries/employees/getTimesheetBatchEntries.js';
180188
export { addEquipment } from './queries/equipment/addEquipment.js';

index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { minutesToMillis } from '@cityssm/to-millis';
22
import { getAccountNumberByWorkOrderNumberAndObjectCode } from './helpers/getAccountNumber.js';
33
import { getEmployeePayCodes } from './queries/employees/getEmployeePayCodes.js';
4+
import { getEmployeeTimeCodes } from './queries/employees/getEmployeeTimeCodes.js';
45
import { getTimeCodes } from './queries/employees/getTimeCodes.js';
56
import { getTimesheetBatchEntries } from './queries/employees/getTimesheetBatchEntries.js';
67
import { addEquipment } from './queries/equipment/addEquipment.js';
@@ -224,12 +225,23 @@ export class WorkTechAPI {
224225
const timeCodes = await getTimeCodes(this.#mssqlConfig);
225226
return timeCodes;
226227
}
228+
/**
229+
* Retrieves time codes for a specific employee.
230+
* @param employeeNumber - The employee number.
231+
* @param timesheetMaxAgeDays - The maximum timesheet age.
232+
* @returns The time codes for the specified employee.
233+
*/
234+
async getEmployeeTimeCodes(employeeNumber, timesheetMaxAgeDays) {
235+
const timeCodes = await getEmployeeTimeCodes(this.#mssqlConfig, employeeNumber, timesheetMaxAgeDays);
236+
return timeCodes;
237+
}
227238
async getTimesheetBatchEntries(filters) {
228239
return await getTimesheetBatchEntries(this.#mssqlConfig, filters);
229240
}
230241
}
231242
export { getAccountNumberByWorkOrderNumberAndObjectCode } from './helpers/getAccountNumber.js';
232243
export { getEmployeePayCodes } from './queries/employees/getEmployeePayCodes.js';
244+
export { getEmployeeTimeCodes } from './queries/employees/getEmployeeTimeCodes.js';
233245
export { getTimeCodes } from './queries/employees/getTimeCodes.js';
234246
export { getTimesheetBatchEntries } from './queries/employees/getTimesheetBatchEntries.js';
235247
export { addEquipment } from './queries/equipment/addEquipment.js';

index.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
getAccountNumberByWorkOrderNumberAndObjectCode
88
} from './helpers/getAccountNumber.js'
99
import { getEmployeePayCodes } from './queries/employees/getEmployeePayCodes.js'
10+
import { getEmployeeTimeCodes } from './queries/employees/getEmployeeTimeCodes.js'
1011
import { getTimeCodes } from './queries/employees/getTimeCodes.js'
1112
import {
1213
type GetTimesheetBatchEntriesFilters,
@@ -403,6 +404,25 @@ export class WorkTechAPI {
403404
return timeCodes
404405
}
405406

407+
/**
408+
* Retrieves time codes for a specific employee.
409+
* @param employeeNumber - The employee number.
410+
* @param timesheetMaxAgeDays - The maximum timesheet age.
411+
* @returns The time codes for the specified employee.
412+
*/
413+
async getEmployeeTimeCodes(
414+
employeeNumber: string,
415+
timesheetMaxAgeDays: number
416+
): Promise<TimeCode[]> {
417+
const timeCodes = await getEmployeeTimeCodes(
418+
this.#mssqlConfig,
419+
employeeNumber,
420+
timesheetMaxAgeDays
421+
)
422+
423+
return timeCodes
424+
}
425+
406426
async getTimesheetBatchEntries(
407427
filters: GetTimesheetBatchEntriesFilters
408428
): Promise<TimesheetBatchEntry[]> {
@@ -413,6 +433,7 @@ export class WorkTechAPI {
413433
export { getAccountNumberByWorkOrderNumberAndObjectCode } from './helpers/getAccountNumber.js'
414434

415435
export { getEmployeePayCodes } from './queries/employees/getEmployeePayCodes.js'
436+
export { getEmployeeTimeCodes } from './queries/employees/getEmployeeTimeCodes.js'
416437
export { getTimeCodes } from './queries/employees/getTimeCodes.js'
417438
export {
418439
type GetTimesheetBatchEntriesFilters,
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { type mssql } from '@cityssm/mssql-multi-pool';
2+
import type { TimeCode } from './types.js';
3+
/**
4+
* Retrieves time codes for a specific employee.
5+
* @param mssqlConfig - SQL Server configuration.
6+
* @param employeeNumber - The employee number.
7+
* @param timesheetMaxAgeDays - The maximum age of timesheets to consider.
8+
* @returns The time codes for the specified employee.
9+
*/
10+
export declare function getEmployeeTimeCodes(mssqlConfig: mssql.config, employeeNumber: string, timesheetMaxAgeDays: number): Promise<TimeCode[]>;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { connect } from '@cityssm/mssql-multi-pool';
2+
/**
3+
* Retrieves time codes for a specific employee.
4+
* @param mssqlConfig - SQL Server configuration.
5+
* @param employeeNumber - The employee number.
6+
* @param timesheetMaxAgeDays - The maximum age of timesheets to consider.
7+
* @returns The time codes for the specified employee.
8+
*/
9+
export async function getEmployeeTimeCodes(mssqlConfig, employeeNumber, timesheetMaxAgeDays) {
10+
const pool = await connect(mssqlConfig);
11+
const result = (await pool
12+
.request()
13+
.input('employeeNumber', employeeNumber)
14+
.input('timesheetMaxAgeDays', timesheetMaxAgeDays).query(/* sql */ `
15+
SELECT
16+
TC_ID as timeCode,
17+
DESCRIPTION as timeCodeDescription,
18+
EXTCODE as externalCode
19+
FROM WMTCD WITH (NOLOCK)
20+
WHERE
21+
Inactive = 0
22+
and AdminOnly = 0
23+
and TC_ID in (
24+
select TC_ID
25+
from WMTSI with (nolock)
26+
where transType = 'Time Sheets'
27+
and type = 'Employee'
28+
and Item_ID = @employeeNumber
29+
and DateTime >= dateadd(day, -1 * @timesheetMaxAgeDays, getdate())
30+
)
31+
ORDER BY TC_ID`));
32+
return result.recordset;
33+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { type mssql, connect } from '@cityssm/mssql-multi-pool'
2+
3+
import type { TimeCode } from './types.js'
4+
5+
/**
6+
* Retrieves time codes for a specific employee.
7+
* @param mssqlConfig - SQL Server configuration.
8+
* @param employeeNumber - The employee number.
9+
* @param timesheetMaxAgeDays - The maximum age of timesheets to consider.
10+
* @returns The time codes for the specified employee.
11+
*/
12+
export async function getEmployeeTimeCodes(
13+
mssqlConfig: mssql.config,
14+
employeeNumber: string,
15+
timesheetMaxAgeDays: number
16+
): Promise<TimeCode[]> {
17+
const pool = await connect(mssqlConfig)
18+
19+
const result = (await pool
20+
.request()
21+
.input('employeeNumber', employeeNumber)
22+
.input('timesheetMaxAgeDays', timesheetMaxAgeDays).query(/* sql */ `
23+
SELECT
24+
TC_ID as timeCode,
25+
DESCRIPTION as timeCodeDescription,
26+
EXTCODE as externalCode
27+
FROM WMTCD WITH (NOLOCK)
28+
WHERE
29+
Inactive = 0
30+
and AdminOnly = 0
31+
and TC_ID in (
32+
select TC_ID
33+
from WMTSI with (nolock)
34+
where transType = 'Time Sheets'
35+
and type = 'Employee'
36+
and Item_ID = @employeeNumber
37+
and DateTime >= dateadd(day, -1 * @timesheetMaxAgeDays, getdate())
38+
)
39+
ORDER BY TC_ID`)) as mssql.IResult<TimeCode>
40+
41+
return result.recordset
42+
}

test/employees.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { releaseAll } from '@cityssm/mssql-multi-pool';
66
import Debug from 'debug';
77
import { DEBUG_ENABLE_NAMESPACES } from '../debug.config.js';
88
import { getEmployeePayCodes } from '../queries/employees/getEmployeePayCodes.js';
9+
import { getEmployeeTimeCodes } from '../queries/employees/getEmployeeTimeCodes.js';
910
import { getTimeCodes } from '../queries/employees/getTimeCodes.js';
1011
import { getTimesheetBatchEntries } from '../queries/employees/getTimesheetBatchEntries.js';
1112
import { mssqlConfig, validActivityId, validEmployeeNumber, validJobId } from './config.js';
@@ -35,6 +36,15 @@ await describe('queries/employees', async () => {
3536
}
3637
});
3738
});
39+
await describe('getEmployeeTimeCodes()', async () => {
40+
await it('Retrieves employee time codes', async () => {
41+
const timeCodes = await getEmployeeTimeCodes(mssqlConfig, validEmployeeNumber, 180);
42+
console.log(timeCodes);
43+
if (timeCodes.length === 0) {
44+
throw new Error('No time codes retrieved');
45+
}
46+
});
47+
});
3848
await describe('getTimesheetBatchEntries()', async () => {
3949
await it('Retrieves timesheet batch entries by employee number and hours', async () => {
4050
const timesheetHours = 8;

test/employees.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Debug from 'debug'
99

1010
import { DEBUG_ENABLE_NAMESPACES } from '../debug.config.js'
1111
import { getEmployeePayCodes } from '../queries/employees/getEmployeePayCodes.js'
12+
import { getEmployeeTimeCodes } from '../queries/employees/getEmployeeTimeCodes.js'
1213
import { getTimeCodes } from '../queries/employees/getTimeCodes.js'
1314
import { getTimesheetBatchEntries } from '../queries/employees/getTimesheetBatchEntries.js'
1415

@@ -57,6 +58,22 @@ await describe('queries/employees', async () => {
5758
})
5859
})
5960

61+
await describe('getEmployeeTimeCodes()', async () => {
62+
63+
await it('Retrieves employee time codes', async () => {
64+
const timeCodes = await getEmployeeTimeCodes(
65+
mssqlConfig,
66+
validEmployeeNumber,
67+
180
68+
)
69+
console.log(timeCodes)
70+
71+
if (timeCodes.length === 0) {
72+
throw new Error('No time codes retrieved')
73+
}
74+
})
75+
})
76+
6077
await describe('getTimesheetBatchEntries()', async () => {
6178
await it('Retrieves timesheet batch entries by employee number and hours', async () => {
6279
const timesheetHours = 8

0 commit comments

Comments
 (0)