Skip to content

Commit

Permalink
add createStockTransactionBatch()
Browse files Browse the repository at this point in the history
  • Loading branch information
dangowans committed Dec 6, 2024
1 parent ff9041d commit cfcbee9
Show file tree
Hide file tree
Showing 48 changed files with 483 additions and 144 deletions.
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import tseslint from 'typescript-eslint';
export const config = tseslint.config(...configCityssm, {
rules: {
'@typescript-eslint/no-unsafe-argument': 'warn',
'@typescript-eslint/no-unsafe-assignment': 'warn',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-call': 'warn',
'@typescript-eslint/no-unsafe-member-access': 'warn',
'@typescript-eslint/no-unsafe-return': 'warn',
Expand Down
2 changes: 1 addition & 1 deletion eslint.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import tseslint from 'typescript-eslint'
export const config = tseslint.config(...configCityssm, {
rules: {
'@typescript-eslint/no-unsafe-argument': 'warn',
'@typescript-eslint/no-unsafe-assignment': 'warn',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-call': 'warn',
'@typescript-eslint/no-unsafe-member-access': 'warn',
'@typescript-eslint/no-unsafe-return': 'warn',
Expand Down
4 changes: 2 additions & 2 deletions helpers/getAccountNumber.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { mssqlTypes } from '@cityssm/mssql-multi-pool';
import type { mssql } from '@cityssm/mssql-multi-pool';
export interface AccountNumberSource {
accountNumber: string;
accountNumberSource: // eslint-disable-next-line no-secrets/no-secrets
Expand All @@ -11,4 +11,4 @@ export interface AccountNumberSource {
* @param optionalObjectCode - An optional object code.
* @returns - The account number and its source, if available.
*/
export declare function getAccountNumberByWorkOrderNumberAndObjectCode(mssqlConfig: mssqlTypes.config, workOrderNumber: string, optionalObjectCode?: string): Promise<AccountNumberSource | undefined>;
export declare function getAccountNumberByWorkOrderNumberAndObjectCode(mssqlConfig: mssql.config, workOrderNumber: string, optionalObjectCode?: string): Promise<AccountNumberSource | undefined>;
4 changes: 2 additions & 2 deletions helpers/getAccountNumber.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { mssqlTypes } from '@cityssm/mssql-multi-pool'
import type { mssql } from '@cityssm/mssql-multi-pool'

import { accountSegmentSeparator } from '../apiConfig.js'
import { getJobActivityObjectCodeByKeys } from '../queries/jobs/getJobActivityObjectCodes.js'
Expand All @@ -23,7 +23,7 @@ export interface AccountNumberSource {
* @returns - The account number and its source, if available.
*/
export async function getAccountNumberByWorkOrderNumberAndObjectCode(
mssqlConfig: mssqlTypes.config,
mssqlConfig: mssql.config,
workOrderNumber: string,
optionalObjectCode?: string
): Promise<AccountNumberSource | undefined> {
Expand Down
12 changes: 10 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import type { mssqlTypes } from '@cityssm/mssql-multi-pool';
import type { mssql } from '@cityssm/mssql-multi-pool';
import type { DateString } from '@cityssm/utils-datetime';
import { type AccountNumberSource } from './helpers/getAccountNumber.js';
import { type AddEquipment } from './queries/equipment/addEquipment.js';
import type { EquipmentItem } from './queries/equipment/types.js';
import { type AddResourceItem } from './queries/items/addResourceItem.js';
import { type CreateStockTransactionBatch } from './queries/items/createStockTransactionBatch.js';
import type { ResourceItem } from './queries/items/types.js';
import type { Activity, Job, JobActivityObjectCode, JobAssignedObjectCode, ObjectCode } from './queries/jobs/types.js';
import type { BigIntString } from './queries/types.js';
Expand All @@ -18,7 +19,7 @@ export declare class WorkTechAPI {
/**
* @param mssqlConfig - SQL Server configuration.
*/
constructor(mssqlConfig: mssqlTypes.config);
constructor(mssqlConfig: mssql.config);
/**
* Retrieves a piece of equipment.
* @param equipmentId - The equipment id.
Expand All @@ -33,6 +34,12 @@ export declare class WorkTechAPI {
*/
getItemByItemId(itemId: string): Promise<ResourceItem | undefined>;
addResourceItem(resourceItem: AddResourceItem): Promise<BigIntString>;
/**
* Creates a new stock transaction batch.
* @param batch - The batch details
* @returns - The batch id.
*/
createStockTransactionBatch(batch: CreateStockTransactionBatch): Promise<number>;
/**
* Retrieves a work order.
* @param workOrderNumber - The work order number.
Expand Down Expand Up @@ -150,6 +157,7 @@ export { getEquipmentByEquipmentId } from './queries/equipment/getEquipment.js';
export { addEquipment } from './queries/equipment/addEquipment.js';
export { getItemByItemId } from './queries/items/getItems.js';
export { type AddResourceItem, addResourceItem } from './queries/items/addResourceItem.js';
export { type CreateStockTransactionBatch, type CreateStockTransactionBatchEntry, createStockTransactionBatch } from './queries/items/createStockTransactionBatch.js';
export { getActivityByActivityId, getActivitiesAssignedToJobByFiscalYear } from './queries/jobs/getActivities.js';
export { getJobByJobId } from './queries/jobs/getJobs.js';
export { getObjectCodeByObjectCode, getObjectCodesAssignedToJobByFiscalYear, getObjectCodeAssignedToJobByObjectCodeAndFiscalYear } from './queries/jobs/getObjectCodes.js';
Expand Down
10 changes: 10 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { getAccountNumberByWorkOrderNumberAndObjectCode } from './helpers/getAcc
import { addEquipment } from './queries/equipment/addEquipment.js';
import { getEquipmentByEquipmentId } from './queries/equipment/getEquipment.js';
import { addResourceItem } from './queries/items/addResourceItem.js';
import { createStockTransactionBatch } from './queries/items/createStockTransactionBatch.js';
import { getItemByItemId } from './queries/items/getItems.js';
import { getActivitiesAssignedToJobByFiscalYear, getActivityByActivityId } from './queries/jobs/getActivities.js';
import { getJobActivityObjectCodeByKeys } from './queries/jobs/getJobActivityObjectCodes.js';
Expand Down Expand Up @@ -45,6 +46,14 @@ export class WorkTechAPI {
async addResourceItem(resourceItem) {
return await addResourceItem(this.#mssqlConfig, resourceItem);
}
/**
* Creates a new stock transaction batch.
* @param batch - The batch details
* @returns - The batch id.
*/
async createStockTransactionBatch(batch) {
return await createStockTransactionBatch(this.#mssqlConfig, batch);
}
/**
* Retrieves a work order.
* @param workOrderNumber - The work order number.
Expand Down Expand Up @@ -187,6 +196,7 @@ export { getEquipmentByEquipmentId } from './queries/equipment/getEquipment.js';
export { addEquipment } from './queries/equipment/addEquipment.js';
export { getItemByItemId } from './queries/items/getItems.js';
export { addResourceItem } from './queries/items/addResourceItem.js';
export { createStockTransactionBatch } from './queries/items/createStockTransactionBatch.js';
export { getActivityByActivityId, getActivitiesAssignedToJobByFiscalYear } from './queries/jobs/getActivities.js';
export { getJobByJobId } from './queries/jobs/getJobs.js';
export { getObjectCodeByObjectCode, getObjectCodesAssignedToJobByFiscalYear, getObjectCodeAssignedToJobByObjectCodeAndFiscalYear } from './queries/jobs/getObjectCodes.js';
Expand Down
27 changes: 24 additions & 3 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { mssqlTypes } from '@cityssm/mssql-multi-pool'
import type { mssql } from '@cityssm/mssql-multi-pool'
import type { DateString } from '@cityssm/utils-datetime'

import {
Expand All @@ -15,6 +15,10 @@ import {
type AddResourceItem,
addResourceItem
} from './queries/items/addResourceItem.js'
import {
type CreateStockTransactionBatch,
createStockTransactionBatch
} from './queries/items/createStockTransactionBatch.js'
import { getItemByItemId } from './queries/items/getItems.js'
import type { ResourceItem } from './queries/items/types.js'
import {
Expand Down Expand Up @@ -60,12 +64,12 @@ import {
* WorkTech API
*/
export class WorkTechAPI {
readonly #mssqlConfig: mssqlTypes.config
readonly #mssqlConfig: mssql.config

/**
* @param mssqlConfig - SQL Server configuration.
*/
constructor(mssqlConfig: mssqlTypes.config) {
constructor(mssqlConfig: mssql.config) {
this.#mssqlConfig = mssqlConfig
}

Expand Down Expand Up @@ -97,6 +101,17 @@ export class WorkTechAPI {
return await addResourceItem(this.#mssqlConfig, resourceItem)
}

/**
* Creates a new stock transaction batch.
* @param batch - The batch details
* @returns - The batch id.
*/
async createStockTransactionBatch(
batch: CreateStockTransactionBatch
): Promise<number> {
return await createStockTransactionBatch(this.#mssqlConfig, batch)
}

/**
* Retrieves a work order.
* @param workOrderNumber - The work order number.
Expand Down Expand Up @@ -330,6 +345,12 @@ export {
addResourceItem
} from './queries/items/addResourceItem.js'

export {
type CreateStockTransactionBatch,
type CreateStockTransactionBatchEntry,
createStockTransactionBatch
} from './queries/items/createStockTransactionBatch.js'

export {
getActivityByActivityId,
getActivitiesAssignedToJobByFiscalYear
Expand Down
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cityssm/worktech-api",
"version": "0.4.0",
"version": "0.5.0",
"description": "Integrations with the WorkTech work order management system.",
"type": "module",
"exports": "./index.js",
Expand Down Expand Up @@ -31,7 +31,7 @@
"prettier-config-cityssm": "^1.0.0"
},
"dependencies": {
"@cityssm/mssql-multi-pool": "^4.0.0",
"@cityssm/mssql-multi-pool": "^4.1.0",
"@cityssm/utils-datetime": "^1.3.0",
"node-cache": "^5.1.2"
}
Expand Down
4 changes: 2 additions & 2 deletions queries/equipment/addEquipment.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { mssqlTypes } from '@cityssm/mssql-multi-pool';
import type { mssql } from '@cityssm/mssql-multi-pool';
import type { BigIntString } from '../types.js';
import type { EquipmentItem } from './types.js';
export interface AddEquipment extends Partial<EquipmentItem> {
equipmentId: string;
equipmentClass: string;
equipmentDescription: string;
}
export declare function addEquipment(mssqlConfig: mssqlTypes.config, equipment: AddEquipment): Promise<BigIntString>;
export declare function addEquipment(mssqlConfig: mssql.config, equipment: AddEquipment): Promise<BigIntString>;
4 changes: 2 additions & 2 deletions queries/equipment/addEquipment.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { mssqlTypes } from '@cityssm/mssql-multi-pool'
import type { mssql } from '@cityssm/mssql-multi-pool'

import { addResourceItem } from '../items/addResourceItem.js'
import type { BigIntString } from '../types.js'
Expand All @@ -12,7 +12,7 @@ export interface AddEquipment extends Partial<EquipmentItem> {
}

export async function addEquipment(
mssqlConfig: mssqlTypes.config,
mssqlConfig: mssql.config,
equipment: AddEquipment
): Promise<BigIntString> {
return await addResourceItem(mssqlConfig, {
Expand Down
4 changes: 2 additions & 2 deletions queries/equipment/getEquipment.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { type mssqlTypes } from '@cityssm/mssql-multi-pool';
import { type mssql } from '@cityssm/mssql-multi-pool';
import type { EquipmentItem } from './types.js';
/**
* Retrieves a piece of equipment.
* @param mssqlConfig - SQL Server configuration.
* @param equipmentId - The equipment id.
* @returns - The equipment record, if available.
*/
export declare function getEquipmentByEquipmentId(mssqlConfig: mssqlTypes.config, equipmentId: string): Promise<EquipmentItem | undefined>;
export declare function getEquipmentByEquipmentId(mssqlConfig: mssql.config, equipmentId: string): Promise<EquipmentItem | undefined>;
6 changes: 3 additions & 3 deletions queries/equipment/getEquipment.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
connect,
type mssqlTypes
type mssql
} from '@cityssm/mssql-multi-pool'
import NodeCache from 'node-cache'

Expand Down Expand Up @@ -53,7 +53,7 @@ const cache = new NodeCache({
* @returns - The equipment record, if available.
*/
export async function getEquipmentByEquipmentId(
mssqlConfig: mssqlTypes.config,
mssqlConfig: mssql.config,
equipmentId: string
): Promise<EquipmentItem | undefined> {
let equipment: EquipmentItem | undefined = cache.get(equipmentId)
Expand All @@ -67,7 +67,7 @@ export async function getEquipmentByEquipmentId(
const equipmentResult = (await pool
.request()
.input('equipmentId', equipmentId)
.query(`${sql} and Item_ID = @equipmentId`)) as mssqlTypes.IResult<EquipmentItem>
.query(`${sql} and Item_ID = @equipmentId`)) as mssql.IResult<EquipmentItem>

if (equipmentResult.recordset.length === 0) {
return undefined
Expand Down
4 changes: 2 additions & 2 deletions queries/items/addResourceItem.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type mssqlTypes } from '@cityssm/mssql-multi-pool';
import { type mssql } from '@cityssm/mssql-multi-pool';
import type { BigIntString } from '../types.js';
import type { ResourceItem } from './types.js';
export interface AddResourceItem extends Partial<ResourceItem> {
Expand All @@ -13,4 +13,4 @@ export interface AddResourceItem extends Partial<ResourceItem> {
* @param resourceItem - The resource item fields.
* @returns - The system id for the new resource item.
*/
export declare function addResourceItem(mssqlConfig: mssqlTypes.config, resourceItem: AddResourceItem): Promise<BigIntString>;
export declare function addResourceItem(mssqlConfig: mssql.config, resourceItem: AddResourceItem): Promise<BigIntString>;
4 changes: 2 additions & 2 deletions queries/items/addResourceItem.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { connect, type mssqlTypes } from '@cityssm/mssql-multi-pool'
import { connect, type mssql } from '@cityssm/mssql-multi-pool'

import { getLastSystemId, incrementLastSystemId } from '../systemId.js'
import type { BigIntString } from '../types.js'
Expand All @@ -20,7 +20,7 @@ export interface AddResourceItem extends Partial<ResourceItem> {
* @returns - The system id for the new resource item.
*/
export async function addResourceItem(
mssqlConfig: mssqlTypes.config,
mssqlConfig: mssql.config,
resourceItem: AddResourceItem
): Promise<BigIntString> {
if (resourceItem.itemId.length > 15) {
Expand Down
25 changes: 25 additions & 0 deletions queries/items/createStockTransactionBatch.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { type mssql } from '@cityssm/mssql-multi-pool';
import { type DateString } from '@cityssm/utils-datetime';
export interface CreateStockTransactionBatch {
batchDescription?: string;
batchDate?: DateString;
userId?: string;
entries: CreateStockTransactionBatchEntry[];
}
export interface CreateStockTransactionBatchEntry {
entryDate?: DateString;
workOrderNumber: string;
jobId?: string;
activityId?: string;
objectCode?: string;
itemNumber: string;
locationCode?: string;
quantity: number;
}
/**
* Creates a new stock transaction batch.
* @param mssqlConfig - SQL Server configuration.
* @param batch - The batch details
* @returns - The batch id.
*/
export declare function createStockTransactionBatch(mssqlConfig: mssql.config, batch: CreateStockTransactionBatch): Promise<number>;
Loading

0 comments on commit cfcbee9

Please sign in to comment.