@fabriktor/fx 0.0.73 → 0.0.75
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 +45 -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,28 @@ 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
|
+
current_members,
|
|
294
|
+
},
|
|
295
|
+
});
|
|
296
|
+
}
|
|
282
297
|
async setLocationMembers(opts) {
|
|
283
298
|
const id = requiredID(opts.location.id, "location", msgLocationIDRequired);
|
|
284
299
|
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
|
-
}
|
|
300
|
+
await this.validateLocationMemberRemoval({
|
|
301
|
+
location: opts.location,
|
|
302
|
+
current_members,
|
|
303
|
+
});
|
|
306
304
|
return await this.jobs.replaceOneLocation({
|
|
307
305
|
id,
|
|
308
306
|
in: {
|
|
@@ -335,6 +333,32 @@ export class JobsFX {
|
|
|
335
333
|
},
|
|
336
334
|
});
|
|
337
335
|
}
|
|
336
|
+
async validateLocationMemberRemoval(opts) {
|
|
337
|
+
const id = opts.location.id.trim();
|
|
338
|
+
const next = new Set(opts.current_members);
|
|
339
|
+
const removed = normalizeIDs(opts.location.current_members).filter((member_id) => !next.has(member_id));
|
|
340
|
+
if (removed.length === 0) {
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
const out = await this.jobs.queryJobs({
|
|
344
|
+
query: {
|
|
345
|
+
owner_id: opts.location.owner_id,
|
|
346
|
+
location_id: id,
|
|
347
|
+
},
|
|
348
|
+
});
|
|
349
|
+
const removed_set = new Set(removed);
|
|
350
|
+
for (const job of out.value ?? []) {
|
|
351
|
+
if (job.status === Terminated) {
|
|
352
|
+
continue;
|
|
353
|
+
}
|
|
354
|
+
if (normalizeIDs(job.current_members).some((member_id) => removed_set.has(member_id))) {
|
|
355
|
+
throw errValidation({
|
|
356
|
+
field: "current_members",
|
|
357
|
+
msg: msgLocationMemberAssigned,
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
}
|
|
338
362
|
jobLifecycleControls(opts) {
|
|
339
363
|
const actor_id = requiredID(opts.actor_id, "actor_id", msgMemberIDRequired);
|
|
340
364
|
const can_manage = opts.job.owner_id === actor_id ||
|