Skip to content

Commit b9bd8aa

Browse files
authored
32 getallactivities method (#33)
1 parent 787b429 commit b9bd8aa

File tree

5 files changed

+56
-4
lines changed

5 files changed

+56
-4
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ In order to use this library you need to have access to an Oracle Field Service
2626

2727
`getActivities()`: Get existing activities
2828

29+
`getAllActivities()`: Get ALL existing activities
30+
2931
`createActivity(activityData)`: Create activity
3032

3133
`deleteActivity(activityId)`: Delete activity

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
],
66
"name": "@ofs-users/proxy",
77
"type": "module",
8-
"version": "1.13.0",
8+
"version": "1.14.0",
99
"description": "A Javascript proxy to access Oracle Field Service via REST API",
1010
"main": "dist/ofs.es.js",
1111
"module": "dist/ofs.es.js",

src/OFS.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,40 @@ export class OFS {
580580
limit: limit,
581581
});
582582
}
583-
583+
/**
584+
* Retrieves all activities from the OFS API.
585+
* @returns An object containing all activities.
586+
*/
587+
async getAllActivities(params: OFSGetActivitiesParams) {
588+
const partialURL = "/rest/ofscCore/v1/activities";
589+
// Start with offset 0 and keep getting results until we get less than 100
590+
var offset = 0;
591+
var limit = 100;
592+
var result: any = undefined;
593+
var allResults: any = { status: 200, totalResults: 0, items: [] };
594+
do {
595+
result = await this._get(partialURL, {
596+
...params,
597+
offset: offset,
598+
limit: limit,
599+
});
600+
if (result.status < 400) {
601+
if (allResults.totalResults == 0) {
602+
allResults = result.data;
603+
allResults.status = 200;
604+
} else {
605+
allResults.items = allResults.items.concat(
606+
result.data.items
607+
);
608+
allResults.totalResults = allResults.items.length;
609+
}
610+
offset += limit;
611+
} else {
612+
return result;
613+
}
614+
} while (result.data.items.length == limit);
615+
return allResults;
616+
}
584617
// Metadata: Plugin Management
585618
async importPlugins(file?: PathLike, data?: string): Promise<OFSResponse> {
586619
const partialURL =

test/general/core.activities.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,3 +334,20 @@ test("Get Activities with all the parameters", async () => {
334334
expect(result.data.items.length).toBeGreaterThan(0);
335335
expect(result.data.items[0].activityId).toBeGreaterThan(0);
336336
});
337+
338+
test("Get All Activities with all the parameters", async () => {
339+
var result = await myProxy.getAllActivities({
340+
resources: "FLUSA",
341+
dateFrom: "2025-02-01",
342+
dateTo: "2025-02-01",
343+
includeChildren: "all",
344+
includeNonScheduled: true,
345+
});
346+
if (result.status !== 200) {
347+
console.log(result);
348+
}
349+
expect(result.status).toBe(200);
350+
expect(result.totalResults).toBeGreaterThan(0);
351+
expect(result.items.length).toBeGreaterThan(0);
352+
expect(result.items[0].activityId).toBeGreaterThan(0);
353+
});

0 commit comments

Comments
 (0)