Skip to content

Commit 767d016

Browse files
committed
add template to schemes and work order models
1 parent 75d694a commit 767d016

File tree

9 files changed

+54
-37
lines changed

9 files changed

+54
-37
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',
242+
credentials: 'include', // @todo only required for cookie based auth,
243243
headers: headers,
244244
});
245245
let json = await fetchResponse.json();

dist/index.js

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ class EquipmentExposure extends BaseModel {
250250
];
251251
constructor(data) {
252252
super(data);
253-
this.start_time = data?.attributes?.start_time?.id ?? data?.start_time ?? "";
253+
this.start_time = data?.attributes?.start_time ?? data?.start_time ?? "";
254254
this.end_time = data?.attributes?.end_time ?? data?.end_time ?? "";
255255
if (data?.attributes?.location) {
256256
const locationData = data.attributes.location;
@@ -266,20 +266,11 @@ class EquipmentExposure extends BaseModel {
266266
coordinates: locationData.coordinates ?? []
267267
};
268268
}
269-
if (data?.attributes?.ppe) {
270-
const ppeData = data.attributes?.ppe;
271-
this.ppe = {
272-
mask: ppeData.ppe?.mask ?? false,
273-
ear_defenders: ppeData.ppe?.ear_defenders ?? false
274-
};
275-
}
276-
if (data?.ppe) {
277-
const ppeData = data.ppe;
278-
this.ppe = {
279-
mask: ppeData.mask ?? false,
280-
ear_defenders: ppeData.ear_defenders ?? false
281-
};
282-
}
269+
const ppe = data?.ppe ?? data?.attributes?.ppe;
270+
this.ppe = {
271+
mask: ppe?.mask ?? false,
272+
ear_defenders: ppe?.ear_defenders ?? false
273+
};
283274
}
284275
}
285276

@@ -1058,6 +1049,11 @@ class Scheme extends BaseModel {
10581049
name: "work_orders",
10591050
type: "array",
10601051
modelType: "work-orders"
1052+
},
1053+
{
1054+
name: "template",
1055+
type: "single",
1056+
modelType: "scheme-templates"
10611057
}
10621058
];
10631059
constructor(data) {
@@ -1090,6 +1086,11 @@ class WorkOrder extends BaseModel {
10901086
name: "operations",
10911087
type: "array",
10921088
modelType: "operations"
1089+
},
1090+
{
1091+
name: "template",
1092+
type: "single",
1093+
modelType: "work-order-templates"
10931094
}
10941095
];
10951096
constructor(data) {
@@ -1561,13 +1562,15 @@ class BaseService extends RequestBuilder {
15611562
};
15621563
}
15631564
async create(model, params) {
1564-
if (params) {}
1565+
if (params) {
1566+
}
15651567
const jsonApiSerializer = new JsonApiSerializer(this.hydrator.getModelMap());
15661568
const payload = jsonApiSerializer.buildCreatePayload(model);
15671569
return await this.client.makePostRequest(this.endpoint, payload);
15681570
}
15691571
async update(id, model, params) {
1570-
if (params) {}
1572+
if (params) {
1573+
}
15711574
const jsonApiSerializer = new JsonApiSerializer(this.hydrator.getModelMap());
15721575
const payload = jsonApiSerializer.buildUpdatePayload(model);
15731576
return await this.client.makePatchRequest(`${this.endpoint}/${id}`, payload);
@@ -2251,6 +2254,9 @@ class ClientConfig {
22512254
}
22522255
// src/models/Organisation.ts
22532256
class Organisation extends BaseModel {
2257+
constructor() {
2258+
super(...arguments);
2259+
}
22542260
type = "organisations";
22552261
static relationships = [];
22562262
}

dist/models/EquipmentExposure.js

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class EquipmentExposure extends BaseModel {
3434
];
3535
constructor(data) {
3636
super(data);
37-
this.start_time = data?.attributes?.start_time?.id ?? data?.start_time ?? '';
37+
this.start_time = data?.attributes?.start_time ?? data?.start_time ?? '';
3838
this.end_time = data?.attributes?.end_time ?? data?.end_time ?? '';
3939
if (data?.attributes?.location) {
4040
const locationData = data.attributes.location;
@@ -50,19 +50,10 @@ export class EquipmentExposure extends BaseModel {
5050
coordinates: locationData.coordinates ?? []
5151
};
5252
}
53-
if (data?.attributes?.ppe) {
54-
const ppeData = data.attributes?.ppe;
55-
this.ppe = {
56-
mask: ppeData.ppe?.mask ?? false,
57-
ear_defenders: ppeData.ppe?.ear_defenders ?? false
58-
};
59-
}
60-
if (data?.ppe) {
61-
const ppeData = data.ppe;
62-
this.ppe = {
63-
mask: ppeData.mask ?? false,
64-
ear_defenders: ppeData.ear_defenders ?? false
65-
};
66-
}
53+
const ppe = data?.ppe ?? data?.attributes?.ppe;
54+
this.ppe = {
55+
mask: ppe?.mask ?? false,
56+
ear_defenders: ppe?.ear_defenders ?? false
57+
};
6758
}
6859
}

dist/models/Scheme.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ export class Scheme extends BaseModel {
1313
type: 'array',
1414
modelType: 'work-orders',
1515
},
16+
{
17+
name: 'template',
18+
type: 'single',
19+
modelType: 'scheme-templates',
20+
}
1621
];
1722
constructor(data) {
1823
super(data);

dist/models/WorkOrder.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ export class WorkOrder extends BaseModel {
1313
type: 'array',
1414
modelType: 'operations',
1515
},
16+
{
17+
name: 'template',
18+
type: 'single',
19+
modelType: 'work-order-templates',
20+
}
1621
];
1722
constructor(data) {
1823
super(data);

dist/services/BaseService.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ export declare class BaseService<T extends Model> extends RequestBuilder {
1313
constructor(client: Client, endpoint: string);
1414
convertToJsonApi(model: Model): {
1515
data: {
16-
id?: string | undefined;
16+
id?: string;
1717
type: string;
1818
attributes: Record<string, any>;
1919
relationships?: Record<string, {
2020
data: {
2121
type: string;
2222
id: string;
2323
};
24-
}> | undefined;
24+
}>;
2525
};
2626
};
2727
get(): Promise<InternalResponse<T[]>>;

dist/utils/Requests.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export class Requests {
1212
}
1313
static buildInternalResponse(fetchResponse, json) {
1414
return {
15-
ok: fetchResponse.ok,
15+
ok: fetchResponse.ok, // @todo convert to own version
1616
statusCode: fetchResponse.status,
1717
headers: fetchResponse.headers,
1818
meta: json?.meta || null,
@@ -29,7 +29,7 @@ export class Requests {
2929
static buildInternalErrorResponse(error) {
3030
return {
3131
ok: false,
32-
statusCode: error.statusCode || 0,
32+
statusCode: error.statusCode || 0, // If there's no response, status code is 0
3333
headers: error.headers,
3434
data: null,
3535
errors: {

src/models/Scheme.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ export class Scheme extends BaseModel {
1818
type: 'array',
1919
modelType: 'work-orders',
2020
},
21+
{
22+
name: 'template',
23+
type: 'single',
24+
modelType: 'scheme-templates',
25+
}
2126
];
2227

2328
constructor(data?: any) {

src/models/WorkOrder.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ export class WorkOrder extends BaseModel {
1818
type: 'array',
1919
modelType: 'operations',
2020
},
21+
{
22+
name: 'template',
23+
type: 'single',
24+
modelType: 'work-order-templates',
25+
}
2126
];
2227

2328
constructor(data?: any) {

0 commit comments

Comments
 (0)