Skip to content

Commit 85f8b1d

Browse files
authored
Merge pull request #65 from ctrl-hub/add-members-stats
Add stats to BaseService
2 parents 5d47575 + 43baf57 commit 85f8b1d

15 files changed

+135
-10
lines changed

dist/Client.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ export class Client {
239239
try {
240240
// @todo switch on cookie, "X-Session-Token" or client_credentials
241241
const fetchResponse = await fetch(url, {
242-
credentials: 'include', // @todo only required for cookie based auth,
242+
credentials: 'include',
243243
headers: headers,
244244
});
245245
let json = await fetchResponse.json();

dist/index.js

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,6 +1275,22 @@ class SchemeTemplate extends BaseModel {
12751275
}
12761276
}
12771277

1278+
// src/models/OrganisationMemberStats.ts
1279+
class OrganisationMemberStats extends BaseModel {
1280+
type = "members-stats";
1281+
members = {
1282+
users: 0,
1283+
service_accounts: 0
1284+
};
1285+
constructor(data) {
1286+
super(data);
1287+
this.members = data?.attributes?.members || {
1288+
users: 0,
1289+
members: 0
1290+
};
1291+
}
1292+
}
1293+
12781294
// src/utils/Hydrator.ts
12791295
class Hydrator {
12801296
modelMap = {
@@ -1293,6 +1309,7 @@ class Hydrator {
12931309
groups: Group,
12941310
"operation-templates": OperationTemplate,
12951311
operations: Operation,
1312+
"members-stats": OrganisationMemberStats,
12961313
permissions: Permission,
12971314
properties: Property,
12981315
roles: Role,
@@ -1562,19 +1579,26 @@ class BaseService extends RequestBuilder {
15621579
};
15631580
}
15641581
async create(model, params) {
1565-
if (params) {
1566-
}
1582+
if (params) {}
15671583
const jsonApiSerializer = new JsonApiSerializer(this.hydrator.getModelMap());
15681584
const payload = jsonApiSerializer.buildCreatePayload(model);
15691585
return await this.client.makePostRequest(this.endpoint, payload);
15701586
}
15711587
async update(id, model, params) {
1572-
if (params) {
1573-
}
1588+
if (params) {}
15741589
const jsonApiSerializer = new JsonApiSerializer(this.hydrator.getModelMap());
15751590
const payload = jsonApiSerializer.buildUpdatePayload(model);
15761591
return await this.client.makePatchRequest(`${this.endpoint}/${id}`, payload);
15771592
}
1593+
async stats(options) {
1594+
const statsEndpoint = `${this.endpoint}/stats`;
1595+
const { requestOptions } = this.buildRequestParams("", options);
1596+
const resp = await this.client.makeGetRequest(statsEndpoint, requestOptions);
1597+
if (resp.data && typeof resp.data === "object") {
1598+
resp.data = this.hydrator.hydrateResponse(resp.data, resp.included || []);
1599+
}
1600+
return resp;
1601+
}
15781602
}
15791603

15801604
// src/services/FormCategoriesService.ts
@@ -1985,6 +2009,9 @@ class OrganisationMembersService extends BaseService {
19852009
constructor(client) {
19862010
super(client, "/v3/orgs/:orgId/iam/members");
19872011
}
2012+
stats(options) {
2013+
return super.stats(options);
2014+
}
19882015
}
19892016

19902017
// src/services/SchemeTemplatesService.ts
@@ -2254,9 +2281,6 @@ class ClientConfig {
22542281
}
22552282
// src/models/Organisation.ts
22562283
class Organisation extends BaseModel {
2257-
constructor() {
2258-
super(...arguments);
2259-
}
22602284
type = "organisations";
22612285
static relationships = [];
22622286
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { BaseModel } from './BaseModel';
2+
type MembersStats = {
3+
users: number;
4+
service_accounts: number;
5+
};
6+
export declare class OrganisationMemberStats extends BaseModel {
7+
type: string;
8+
members: MembersStats;
9+
constructor(data?: any);
10+
}
11+
export {};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { BaseModel } from './BaseModel';
2+
export class OrganisationMemberStats extends BaseModel {
3+
type = 'members-stats';
4+
members = {
5+
users: 0,
6+
service_accounts: 0
7+
};
8+
constructor(data) {
9+
super(data);
10+
this.members = data?.attributes?.members || {
11+
users: 0,
12+
members: 0
13+
};
14+
}
15+
}

dist/services/BaseService.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@ export declare class BaseService<T extends Model> extends RequestBuilder {
3030
get(param: RequestOptionsType): Promise<InternalResponse<T[]>>;
3131
create(model: T, params?: unknown): Promise<InternalResponse<T>>;
3232
update(id: string, model: Model, params?: unknown): Promise<InternalResponse<T>>;
33+
stats<R = any>(options?: RequestOptionsType): Promise<InternalResponse<R>>;
3334
}

dist/services/BaseService.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,13 @@ export class BaseService extends RequestBuilder {
4040
const payload = jsonApiSerializer.buildUpdatePayload(model);
4141
return await this.client.makePatchRequest(`${this.endpoint}/${id}`, payload);
4242
}
43+
async stats(options) {
44+
const statsEndpoint = `${this.endpoint}/stats`;
45+
const { requestOptions } = this.buildRequestParams('', options);
46+
const resp = await this.client.makeGetRequest(statsEndpoint, requestOptions);
47+
if (resp.data && typeof resp.data === 'object') {
48+
resp.data = this.hydrator.hydrateResponse(resp.data, resp.included || []);
49+
}
50+
return resp;
51+
}
4352
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
import { BaseService } from '../services/BaseService';
22
import { Client } from '../Client';
33
import type { User } from '../models/User';
4+
import type { InternalResponse } from '../types/Response';
5+
import type { RequestOptionsType } from '../utils/RequestOptions';
6+
type OrganisationMembersStats = {
7+
members: {
8+
users: number;
9+
service_accounts: number;
10+
};
11+
};
412
export declare class OrganisationMembersService extends BaseService<User> {
513
constructor(client: Client);
14+
stats<R = OrganisationMembersStats>(options?: RequestOptionsType): Promise<InternalResponse<R>>;
615
}
16+
export {};

dist/services/OrganisationMembersService.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@ export class OrganisationMembersService extends BaseService {
44
constructor(client) {
55
super(client, "/v3/orgs/:orgId/iam/members");
66
}
7+
stats(options) {
8+
return super.stats(options);
9+
}
710
}

dist/utils/Hydrator.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import { Street } from '../models/Street';
3434
import { Appointment } from '../models/Appointment';
3535
import { WorkOrderTemplate } from '../models/WorkOrderTemplate';
3636
import { SchemeTemplate } from '../models/SchemeTemplate';
37+
import { OrganisationMemberStats } from '../models/OrganisationMemberStats';
3738
export class Hydrator {
3839
modelMap = {
3940
appointments: Appointment,
@@ -51,6 +52,7 @@ export class Hydrator {
5152
groups: Group,
5253
"operation-templates": OperationTemplate,
5354
operations: Operation,
55+
"members-stats": OrganisationMemberStats,
5456
permissions: Permission,
5557
properties: Property,
5658
roles: Role,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"type": "git",
55
"url": "https://github.com/ctrl-hub/sdk.ts"
66
},
7-
"version": "0.1.140",
7+
"version": "0.1.141",
88
"main": "dist/index.js",
99
"types": "dist/index.d.ts",
1010
"type": "module",

0 commit comments

Comments
 (0)