Skip to content

Commit

Permalink
add resource items
Browse files Browse the repository at this point in the history
  • Loading branch information
dangowans committed Jul 16, 2024
1 parent 0dcbeed commit f8df967
Show file tree
Hide file tree
Showing 25 changed files with 462 additions and 109 deletions.
5 changes: 4 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { config } from '@cityssm/mssql-multi-pool';
import { type DateString } from '@cityssm/utils-datetime';
import { type AccountNumberSource } from './helpers/getAccountNumber.js';
import { type AddResourceItem } from './queries/items/addResourceItem.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 @@ -22,6 +23,7 @@ export declare class WorkTechAPI {
* @returns - The item, if available.
*/
getItemByItemId(itemId: string): Promise<ResourceItem | undefined>;
addResourceItem(resourceItem: AddResourceItem): Promise<BigIntString>;
/**
* Retrieves a work order.
* @param workOrderNumber - The work order number.
Expand Down Expand Up @@ -136,12 +138,13 @@ export declare class WorkTechAPI {
}
export { getAccountNumberByWorkOrderNumberAndObjectCode } from './helpers/getAccountNumber.js';
export { getItemByItemId } from './queries/items/getItems.js';
export { type AddResourceItem, addResourceItem } from './queries/items/addResourceItem.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';
export { getJobActivityObjectCodeByKeys } from './queries/jobs/getJobActivityObjectCodes.js';
export { addWorkOrderResource } from './queries/workOrders/addWorkOrderResource.js';
export { getWorkOrderByWorkOrderNumber } from './queries/workOrders/getWorkOrders.js';
export { addWorkOrderResource } from './queries/workOrders/addWorkOrderResource.js';
export { getWorkOrderResourcesByStartDate, getWorkOrderResourcesByStartDateTimeRange, getWorkOrderResourcesByWorkOrderNumber } from './queries/workOrders/getWorkOrderResources.js';
export { updateWorkOrderResource } from './queries/workOrders/updateWorkOrderResource.js';
export { deleteWorkOrderResource } from './queries/workOrders/deleteWorkOrderResource.js';
7 changes: 6 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getAccountNumberByWorkOrderNumberAndObjectCode } from './helpers/getAccountNumber.js';
import { addResourceItem } from './queries/items/addResourceItem.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 @@ -28,6 +29,9 @@ export class WorkTechAPI {
async getItemByItemId(itemId) {
return await getItemByItemId(this.#mssqlConfig, itemId);
}
async addResourceItem(resourceItem) {
return await addResourceItem(this.#mssqlConfig, resourceItem);
}
/**
* Retrieves a work order.
* @param workOrderNumber - The work order number.
Expand Down Expand Up @@ -167,12 +171,13 @@ export class WorkTechAPI {
}
export { getAccountNumberByWorkOrderNumberAndObjectCode } from './helpers/getAccountNumber.js';
export { getItemByItemId } from './queries/items/getItems.js';
export { addResourceItem } from './queries/items/addResourceItem.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';
export { getJobActivityObjectCodeByKeys } from './queries/jobs/getJobActivityObjectCodes.js';
export { addWorkOrderResource } from './queries/workOrders/addWorkOrderResource.js';
export { getWorkOrderByWorkOrderNumber } from './queries/workOrders/getWorkOrders.js';
export { addWorkOrderResource } from './queries/workOrders/addWorkOrderResource.js';
export { getWorkOrderResourcesByStartDate, getWorkOrderResourcesByStartDateTimeRange, getWorkOrderResourcesByWorkOrderNumber } from './queries/workOrders/getWorkOrderResources.js';
export { updateWorkOrderResource } from './queries/workOrders/updateWorkOrderResource.js';
export { deleteWorkOrderResource } from './queries/workOrders/deleteWorkOrderResource.js';
9 changes: 8 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
type AccountNumberSource,
getAccountNumberByWorkOrderNumberAndObjectCode
} from './helpers/getAccountNumber.js'
import { type AddResourceItem, addResourceItem } from './queries/items/addResourceItem.js'
import { getItemByItemId } from './queries/items/getItems.js'
import type { ResourceItem } from './queries/items/types.js'
import {
Expand Down Expand Up @@ -68,6 +69,10 @@ export class WorkTechAPI {
return await getItemByItemId(this.#mssqlConfig, itemId)
}

async addResourceItem(resourceItem: AddResourceItem): Promise<BigIntString> {
return await addResourceItem(this.#mssqlConfig, resourceItem)
}

/**
* Retrieves a work order.
* @param workOrderNumber - The work order number.
Expand Down Expand Up @@ -293,6 +298,7 @@ export class WorkTechAPI {
export { getAccountNumberByWorkOrderNumberAndObjectCode } from './helpers/getAccountNumber.js'

export { getItemByItemId } from './queries/items/getItems.js'
export { type AddResourceItem, addResourceItem } from './queries/items/addResourceItem.js'

export {
getActivityByActivityId,
Expand All @@ -306,8 +312,9 @@ export {
} from './queries/jobs/getObjectCodes.js'
export { getJobActivityObjectCodeByKeys } from './queries/jobs/getJobActivityObjectCodes.js'

export { addWorkOrderResource } from './queries/workOrders/addWorkOrderResource.js'
export { getWorkOrderByWorkOrderNumber } from './queries/workOrders/getWorkOrders.js'

export { addWorkOrderResource } from './queries/workOrders/addWorkOrderResource.js'
export {
getWorkOrderResourcesByStartDate,
getWorkOrderResourcesByStartDateTimeRange,
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"name": "@cityssm/worktech-api",
"version": "0.2.1",
"version": "0.3.0",
"description": "Integrations with the WorkTech work order management system.",
"type": "module",
"exports": "./index.js",
"scripts": {
"test": "node --test",
"test:items": "node --test --test-name-pattern=\"queries/items\"",
"test:workOrders": "node --test --test-name-pattern=\"queries/workOrders\"",
"coverage": "c8 --reporter=lcov --reporter=text --reporter=text-summary node --test"
},
Expand Down
16 changes: 16 additions & 0 deletions queries/items/addResourceItem.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { type config as MSSQLConfig } from '@cityssm/mssql-multi-pool';
import type { BigIntString } from '../types.js';
import type { ResourceItem } from './types.js';
export interface AddResourceItem extends Partial<ResourceItem> {
itemId: string;
itemClass: string;
itemType: string;
unit: string;
}
/**
* Creates a new resource item.
* @param mssqlConfig - SQL Server configuration.
* @param resourceItem - The resource item fields.
* @returns - The system id for the new resource item.
*/
export declare function addResourceItem(mssqlConfig: MSSQLConfig, resourceItem: AddResourceItem): Promise<BigIntString>;
129 changes: 129 additions & 0 deletions queries/items/addResourceItem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import { connect } from '@cityssm/mssql-multi-pool';
import { getLastSystemId, incrementLastSystemId } from '../systemId.js';
/**
* Creates a new resource item.
* @param mssqlConfig - SQL Server configuration.
* @param resourceItem - The resource item fields.
* @returns - The system id for the new resource item.
*/
export async function addResourceItem(mssqlConfig, resourceItem) {
if (resourceItem.itemId.length > 15) {
throw new Error('itemId exceeds 15 characters');
}
const pool = await connect(mssqlConfig);
const transaction = pool.transaction();
try {
await transaction.begin();
const lastSystemId = await getLastSystemId(transaction);
if (lastSystemId === undefined) {
throw new Error('Last used system id is unavailable.');
}
const itemSystemId = (Number.parseInt(lastSystemId, 10) + 1).toString();
// eslint-disable-next-line no-secrets/no-secrets
await transaction
.request()
.input('itemSystemId', itemSystemId)
.input('itemId', resourceItem.itemId)
.input('itemDescription', resourceItem.itemDescription ?? '')
.input('externalItemId', resourceItem.externalItemId ?? '')
.input('itemClass', resourceItem.itemClass)
.input('itemType', resourceItem.itemType)
.input('department', resourceItem.department ?? '')
.input('division', resourceItem.division ?? '')
.input('company', resourceItem.company ?? '')
.input('comments', resourceItem.comments ?? '')
.input('stock', resourceItem.stock ?? 0)
.input('unit', resourceItem.unit)
.input('unitCost', resourceItem.unitCost ?? 0)
.input('quantityOnHand', resourceItem.quantityOnHand ?? 0)
.input('location', resourceItem.location ?? '')
.input('itemModel', resourceItem.itemModel ?? '')
.query(`INSERT INTO WMITM (
ITMSYSID, ITEM_ID, "DESC", RESLIST, EXTITEM_ID,
ITEMCLASS, CLASSITEM, TYPE, STATUS,
DEPT, DIVISION, COMPANY, FLTYPE, COMMENTS,
EXJOB_ID, EXJOBSYSID, EXACTV_ID, EXOBJCODE, EXOCSYSID,
REVJOBSYSID, REVJOB_ID, REVACTV_ID, REVOBJCODE, REVOCSYSID,
VEHSYS, STOCK, UNITS, UNITCOST, UNITS2, UNITS3, UNITS4,
QTYHAND, MINLEVEL, ORDERQTY,
ORDVEND_ID, VEND_ID, VENDSYSID,
IREMPURGE, VREMPURGED, VARIANCE, "VALUE",
VARWARN, VARDOWN, VARUP,
TAXCODE,
PAYGROUP, PGSYSID,
INSTALLVENDOR, DATEINST,
MEAS_UNITS, SHAPE, LENGTH, DIAMETER, HEIGHT, WIDTH,
CAPACITY, TANK, QTYHANDCHECK, TANKUSAGECHOICE, CAPACITYFLAG, BRAND,
DATEIN, CREW, HOURS, HRCOST, INITVAL,
LOCATION, MODEL,
ODOM, RUNHRS, ORGODOM, ORGHOURS, PLATE, SERIAL,
PURCHDATE, PURCHFRM, REPLCOST, REPLYR, RESVAL, REVTD,
TOTCOST, PURCHPRICE, USELIFE, "YEAR", TRADEIN,
ODOMUPDATECHECK, HRMETERUPDATECHECK,
CARDNUMBER,
ADDRESS, ADDRESS2, ADDRESS3, ADDRESS4,
BIRTHD, EMAIL,
PHONE1, PHONE2, PHONE3, PHONEDESC1, PHONEDESC2, PHONEDESC3,
"POSITION",
HRSPERPP, PAYOT, BANKOT,
EBCHOICE, EBPERCENT, EBDOBJCODE, EBDOCSYSID, EBRJOBSYSID, EBRJOB_ID, EBROBJCODE, EBROCSYSID, EBRACTV_ID,
DEFVEH_ID, EBGROUP, STOCKPILE, PROCESSCOST, ROYALTYCOST, ROYALTYTO, HAULER, DAYS2REORDER,
FUELCONRATE, FUELOVERLAST, OILCONRATE, OILOVERLAST,
PAYMETHOD, FIXEDRECRATE, ESTRATE, ESTITEM,
CVOR, PATROL, UNITP, HASODOMETER, CHARGEOUT, DAILYHRS,
REVCAPJOB_ID, REVCAPJOBSYSID, REVCAPACTV_ID, REVCAPOBJCODE, REVCAPOCSYSID, OTCHECKTYPE,
EXTITMSYSID, DEFTC_ID, EMPLSTATUS, EXTARITEM_ID,
EXTRA1, EXTRA2, DATE1, DATE2, DATE3, PIL,
ASSET_ID, ASSETSYSID, EXTRAD1, EXTRAC1, STK_MKUP, ORGPOS_ID,
FEATURE_ID, ACISYSID, SYSTEM, MOD_USER, ROOM_ID, PITEM_ID,
MEASURE1, MEASURE2, MEASURE3, MEASURE4,
EXTRAC2, PORT, DIALS, CELLPHONE, FIR_ID, EXTRA3)
VALUES (
@itemSystemId, @itemId, @itemDescription, 1, @externalItemId,
@itemClass, 0, @itemType, 'EstOnly',
@department, @division, @company, NULL, @comments,
NULL, 0, NULL, '', 0,
0, '', NULL, '', 0,
NULL, @stock, @unit, @unitCost, NULL, '', '',
@quantityOnHand, 0.00, 0.00,
NULL, NULL, 0,
0, 0, 0.00, 0.00,
0, 0.00, 0.00,
NULL,
NULL, 0,
NULL, NULL,
'Metres', 'Rectangle', 0.00, 0.00, 0.00, 0.00,
0.00, 0, 0, 'Vehicle ID', 0, NULL,
NULL, NULL, 0.0, 0.00, 0.00,
@location, @itemModel,
0.0, 0.00, 0.0, 0.0, NULL, NULL,
NULL, NULL, 0.00, 0, 0.00, 0.00,
0.00, 0.00, 0, ${new Date().getFullYear()}, 0.00,
0, 0,
NULL,
NULL, NULL, NULL, NULL,
NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL,
NULL,
80.00, 0, 0,
0, 0.000, NULL, 0, 0, NULL, NULL, 0, NULL,
NULL, NULL, 0, 0.0000, 0.0000, NULL, 0, 0,
0.00, 0, 0.00, 0,
'Hourly', 0.00, 0.00, 0,
0, '', 0.00, 0, 0, 0.00,
NULL, 0, NULL, NULL, 0, NULL,
0, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL,
NULL, 0, 0.00, 0, 0.00, NULL,
NULL, 0, NULL, '', NULL, NULL,
0.00, 0.00, 0.00, 0.00,
0, 0, 0, NULL, NULL, NULL)`);
await incrementLastSystemId(transaction);
await transaction.commit();
return itemSystemId;
}
catch (error) {
await transaction.rollback();
throw error;
}
}
Loading

0 comments on commit f8df967

Please sign in to comment.