@fabriktor/fx 0.0.73 → 0.0.76
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/jobs/jobs.d.ts +7 -0
- package/dist/src/jobs/jobs.js +61 -21
- package/package.json +1 -1
package/dist/src/jobs/jobs.d.ts
CHANGED
|
@@ -74,6 +74,10 @@ export type RemoveJobMemberOptions = {
|
|
|
74
74
|
job: Job;
|
|
75
75
|
member_id: string;
|
|
76
76
|
};
|
|
77
|
+
export type UpdateOperationalLocationOptions = {
|
|
78
|
+
location: Location;
|
|
79
|
+
in: CreateOperationalLocationInput;
|
|
80
|
+
};
|
|
77
81
|
export type SetLocationMembersOptions = {
|
|
78
82
|
location: Location;
|
|
79
83
|
current_members: string[];
|
|
@@ -110,6 +114,7 @@ export interface JobsFXOperator {
|
|
|
110
114
|
createJobProgram(opts: CreateJobProgramOptions): Promise<CreateJobProgramResult>;
|
|
111
115
|
createLocationJobProgram(opts: CreateJobProgramOptions): Promise<CreateLocationJobProgramResult>;
|
|
112
116
|
findLocationOverlaps(opts: FindLocationOverlapsOptions): Promise<OperationResultOf<RPJobsFindOverlaps>>;
|
|
117
|
+
updateOperationalLocation(opts: UpdateOperationalLocationOptions): Promise<Location>;
|
|
113
118
|
addJobForeman(opts: AddJobForemanOptions): Promise<OperationResult>;
|
|
114
119
|
removeJobMember(opts: RemoveJobMemberOptions): Promise<OperationResult>;
|
|
115
120
|
setLocationMembers(opts: SetLocationMembersOptions): Promise<OperationResult>;
|
|
@@ -139,8 +144,10 @@ export declare class JobsFX implements JobsFXOperator {
|
|
|
139
144
|
findLocationOverlaps(opts: FindLocationOverlapsOptions): Promise<OperationResultOf<RPJobsFindOverlaps>>;
|
|
140
145
|
addJobForeman(opts: AddJobForemanOptions): Promise<OperationResult>;
|
|
141
146
|
removeJobMember(opts: RemoveJobMemberOptions): Promise<OperationResult>;
|
|
147
|
+
updateOperationalLocation(opts: UpdateOperationalLocationOptions): Promise<Location>;
|
|
142
148
|
setLocationMembers(opts: SetLocationMembersOptions): Promise<OperationResult>;
|
|
143
149
|
setJobMembers(opts: SetJobMembersOptions): Promise<OperationResult>;
|
|
150
|
+
private validateLocationMemberRemoval;
|
|
144
151
|
jobLifecycleControls(opts: JobLifecycleControlsOptions): JobLifecycleControls;
|
|
145
152
|
startJob(opts: JobLifecycleOptions): Promise<Job>;
|
|
146
153
|
terminateJob(opts: JobLifecycleOptions): Promise<Job>;
|
package/dist/src/jobs/jobs.js
CHANGED
|
@@ -279,30 +279,29 @@ export class JobsFX {
|
|
|
279
279
|
},
|
|
280
280
|
});
|
|
281
281
|
}
|
|
282
|
+
async updateOperationalLocation(opts) {
|
|
283
|
+
const id = requiredID(opts.location.id, "location", msgLocationIDRequired);
|
|
284
|
+
const current_members = normalizeIDs(opts.in.current_members);
|
|
285
|
+
await this.validateLocationMemberRemoval({
|
|
286
|
+
location: opts.location,
|
|
287
|
+
current_members,
|
|
288
|
+
});
|
|
289
|
+
return await this.replaceLocation({
|
|
290
|
+
id,
|
|
291
|
+
in: {
|
|
292
|
+
...opts.in,
|
|
293
|
+
...locationAddressInput(opts.location),
|
|
294
|
+
current_members,
|
|
295
|
+
},
|
|
296
|
+
});
|
|
297
|
+
}
|
|
282
298
|
async setLocationMembers(opts) {
|
|
283
299
|
const id = requiredID(opts.location.id, "location", msgLocationIDRequired);
|
|
284
300
|
const current_members = normalizeIDs(opts.current_members);
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
query: {
|
|
290
|
-
location_id: id,
|
|
291
|
-
},
|
|
292
|
-
});
|
|
293
|
-
const removed_set = new Set(removed);
|
|
294
|
-
for (const job of out.value ?? []) {
|
|
295
|
-
if (job.status === Terminated) {
|
|
296
|
-
continue;
|
|
297
|
-
}
|
|
298
|
-
if (normalizeIDs(job.current_members).some((member_id) => removed_set.has(member_id))) {
|
|
299
|
-
throw errValidation({
|
|
300
|
-
field: "current_members",
|
|
301
|
-
msg: msgLocationMemberAssigned,
|
|
302
|
-
});
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
}
|
|
301
|
+
await this.validateLocationMemberRemoval({
|
|
302
|
+
location: opts.location,
|
|
303
|
+
current_members,
|
|
304
|
+
});
|
|
306
305
|
return await this.jobs.replaceOneLocation({
|
|
307
306
|
id,
|
|
308
307
|
in: {
|
|
@@ -335,6 +334,32 @@ export class JobsFX {
|
|
|
335
334
|
},
|
|
336
335
|
});
|
|
337
336
|
}
|
|
337
|
+
async validateLocationMemberRemoval(opts) {
|
|
338
|
+
const id = opts.location.id.trim();
|
|
339
|
+
const next = new Set(opts.current_members);
|
|
340
|
+
const removed = normalizeIDs(opts.location.current_members).filter((member_id) => !next.has(member_id));
|
|
341
|
+
if (removed.length === 0) {
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
const out = await this.jobs.queryJobs({
|
|
345
|
+
query: {
|
|
346
|
+
owner_id: opts.location.owner_id,
|
|
347
|
+
location_id: id,
|
|
348
|
+
},
|
|
349
|
+
});
|
|
350
|
+
const removed_set = new Set(removed);
|
|
351
|
+
for (const job of out.value ?? []) {
|
|
352
|
+
if (job.status === Terminated) {
|
|
353
|
+
continue;
|
|
354
|
+
}
|
|
355
|
+
if (normalizeIDs(job.current_members).some((member_id) => removed_set.has(member_id))) {
|
|
356
|
+
throw errValidation({
|
|
357
|
+
field: "current_members",
|
|
358
|
+
msg: msgLocationMemberAssigned,
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
338
363
|
jobLifecycleControls(opts) {
|
|
339
364
|
const actor_id = requiredID(opts.actor_id, "actor_id", msgMemberIDRequired);
|
|
340
365
|
const can_manage = opts.job.owner_id === actor_id ||
|
|
@@ -601,6 +626,21 @@ function datePart(parts, type) {
|
|
|
601
626
|
}
|
|
602
627
|
return out;
|
|
603
628
|
}
|
|
629
|
+
function locationAddressInput(location) {
|
|
630
|
+
return {
|
|
631
|
+
address_timezone: location.address_timezone,
|
|
632
|
+
lat: location.lat,
|
|
633
|
+
lon: location.lon,
|
|
634
|
+
street: location.street,
|
|
635
|
+
city: location.city,
|
|
636
|
+
state: location.state,
|
|
637
|
+
postal_code: location.postal_code,
|
|
638
|
+
country: location.country,
|
|
639
|
+
formatted_address: location.formatted_address,
|
|
640
|
+
place_name: location.place_name,
|
|
641
|
+
place_id: location.place_id,
|
|
642
|
+
};
|
|
643
|
+
}
|
|
604
644
|
function requiredID(v, field, msg) {
|
|
605
645
|
const out = resolvedID(v);
|
|
606
646
|
if (out === undefined) {
|