diff --git a/famis_client.ts b/famis_client.ts index a9b7dc4..cd838ca 100644 --- a/famis_client.ts +++ b/famis_client.ts @@ -21,7 +21,7 @@ import { Company, CreateAssetAttachment, CreateAssetMake, - CreateAssetModel, + CreateAssetModel, CreateWatcher, Crew, CrewUserAssociation, DefaultPropertyAndSpace, @@ -94,14 +94,14 @@ import { SubSpace, Udf, UdfField, - UnitOfMeasure, + UnitOfMeasure, UpdateWatcher, UserActivityGroupAssociations, UserInspectionClassAssoc, UserPropertyAssociation, UserRegionAssociation, UserSecurity, UserType, - Warehouse, + Warehouse, Watcher, WorkOrder, WorkOrderComment, WorkType @@ -148,6 +148,7 @@ import axiosRetry from 'axios-retry'; import Bottleneck from 'bottleneck'; import { GeoLocation } from './model/geo_locations'; import moment = require('moment'); +import {watch} from "fs"; type ResultCallback = (results: FamisResponse) => void; @@ -409,6 +410,40 @@ export class FamisClient { // + //region Watchers + async getWatchers(context: QueryContext): Promise> { + return await this.getAll(context, 'watchers'); + } + + async getWatcher(watcherId: number): Promise { + const response = await this.getWatchers(new QueryContext().setFilter(`Id eq ${watcherId}`)); + + if (!response || response.results.length === 0) { + throw new Error('not found'); + } + return response.results[0]; + } + + async createWatcher(watcher: CreateWatcher): Promise { + return this.createObject(watcher, 'watchers'); + } + + async patchWatcher(watcher: UpdateWatcher): Promise { + let url = buildEntityUrl('watchers'); + url += `(${watcher.Id})`; + const resp = await this.http.patch(url, watcher); + + return this.getWatcher(watcher.Id); + } + + async deleteWatcher(watcherId: number): Promise { + let url = buildEntityUrl('watchers'); + url += `(${watcherId})`; + const resp = await this.http.delete(url); + this.throwResponseError(resp); + } + //end region + // crews async getCrews(context: QueryContext): Promise> { diff --git a/model/famis_models.ts b/model/famis_models.ts index d61ea6b..c915d76 100644 --- a/model/famis_models.ts +++ b/model/famis_models.ts @@ -1177,6 +1177,23 @@ export interface Watcher { Name?: string; } +export interface CreateWatcher { + RequestId: number; + EmployeeId: number; + NotificationFlag: boolean; + CreateDate?: string; + Name?: string; +} + +export interface UpdateWatcher { + Id: number; + RequestId?: number; + EmployeeId?: number; + NotificationFlag?: boolean; + CreateDate?: string; + Name?: string; +} + export interface AssetClass { Id: number; Description: string; diff --git a/package.json b/package.json index 76fa122..cea6676 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "facility360", - "version": "1.0.18", + "version": "1.0.19", "description": "A Node based 360Facility client SDK", "main": "dist/index.js", "scripts": {