Skip to content

Commit

Permalink
Merge pull request #83 from apptreesoftware/adding_watcher_functionality
Browse files Browse the repository at this point in the history
Adding watcher functionality
  • Loading branch information
alexisandreason committed Nov 2, 2023
2 parents 9a966a7 + 17edab0 commit dc20985
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 4 deletions.
41 changes: 38 additions & 3 deletions famis_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
Company,
CreateAssetAttachment,
CreateAssetMake,
CreateAssetModel,
CreateAssetModel, CreateWatcher,
Crew,
CrewUserAssociation,
DefaultPropertyAndSpace,
Expand Down Expand Up @@ -94,14 +94,14 @@ import {
SubSpace,
Udf,
UdfField,
UnitOfMeasure,
UnitOfMeasure, UpdateWatcher,
UserActivityGroupAssociations,
UserInspectionClassAssoc,
UserPropertyAssociation,
UserRegionAssociation,
UserSecurity,
UserType,
Warehouse,
Warehouse, Watcher,
WorkOrder,
WorkOrderComment,
WorkType
Expand Down Expand Up @@ -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<T> = (results: FamisResponse<T>) => void;

Expand Down Expand Up @@ -409,6 +410,40 @@ export class FamisClient {

//

//region Watchers
async getWatchers(context: QueryContext): Promise<Result<Watcher>> {
return await this.getAll<Watcher>(context, 'watchers');
}

async getWatcher(watcherId: number): Promise<Watcher> {
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<Watcher> {
return this.createObject<CreateWatcher, Watcher>(watcher, 'watchers');
}

async patchWatcher(watcher: UpdateWatcher): Promise<Watcher> {
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<void> {
let url = buildEntityUrl('watchers');
url += `(${watcherId})`;
const resp = await this.http.delete(url);
this.throwResponseError(resp);
}
//end region

// crews

async getCrews(context: QueryContext): Promise<Result<Crew>> {
Expand Down
17 changes: 17 additions & 0 deletions model/famis_models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "facility360",
"version": "1.0.17",
"version": "1.0.19",
"description": "A Node based 360Facility client SDK",
"main": "dist/index.js",
"scripts": {
Expand Down

0 comments on commit dc20985

Please sign in to comment.