@fabriktor/fx 0.0.82 → 0.0.83
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/core/search.d.ts +1 -0
- package/dist/src/core/search.js +7 -4
- package/dist/src/jobs/jobs.d.ts +3 -0
- package/dist/src/jobs/jobs.js +15 -11
- package/package.json +1 -1
|
@@ -32,6 +32,7 @@ export type SearchPage<T> = {
|
|
|
32
32
|
next_page: number;
|
|
33
33
|
done: boolean;
|
|
34
34
|
};
|
|
35
|
+
export declare function withOwnerQuery(owner_id: string, query?: SearchQuery): SearchQuery;
|
|
35
36
|
export declare function runOwnerSearch<T>(opts: RunOwnerSearchOptions<T>): Promise<SearchPage<T>>;
|
|
36
37
|
export declare function runSearch<T>(opts: RunSearchOptions<T>): Promise<SearchPage<T>>;
|
|
37
38
|
export declare function normalizeSearchPage(value?: number): number;
|
package/dist/src/core/search.js
CHANGED
|
@@ -6,14 +6,17 @@
|
|
|
6
6
|
import { OwnerIDKey, SearchPageKey, SearchPerPageKey, SearchQueryKey, SearchResultResultsKey, } from "@fabriktor/schema";
|
|
7
7
|
const firstSearchPage = 1;
|
|
8
8
|
const defaultSearchPerPage = 30;
|
|
9
|
+
export function withOwnerQuery(owner_id, query) {
|
|
10
|
+
return {
|
|
11
|
+
...query,
|
|
12
|
+
[OwnerIDKey]: owner_id,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
9
15
|
export async function runOwnerSearch(opts) {
|
|
10
16
|
const { owner_id, query, ...searchOpts } = opts;
|
|
11
17
|
return await runSearch({
|
|
12
18
|
...searchOpts,
|
|
13
|
-
query:
|
|
14
|
-
...query,
|
|
15
|
-
[OwnerIDKey]: owner_id,
|
|
16
|
-
},
|
|
19
|
+
query: withOwnerQuery(owner_id, query),
|
|
17
20
|
});
|
|
18
21
|
}
|
|
19
22
|
export async function runSearch(opts) {
|
package/dist/src/jobs/jobs.d.ts
CHANGED
|
@@ -18,10 +18,12 @@ export declare const JobsPreActionReason: {
|
|
|
18
18
|
export type JobsPreActionReason = (typeof JobsPreActionReason)[keyof typeof JobsPreActionReason];
|
|
19
19
|
export type CreateLocationOptions = LocationInsertOptions;
|
|
20
20
|
export type UpdateLocationOptions = {
|
|
21
|
+
owner_id: string;
|
|
21
22
|
location: Location;
|
|
22
23
|
in: LocationReplaceInput;
|
|
23
24
|
};
|
|
24
25
|
export type ArchiveLocationOptions = {
|
|
26
|
+
owner_id: string;
|
|
25
27
|
location: Location;
|
|
26
28
|
};
|
|
27
29
|
export type SearchLocationsOptions = OwnerSearchOptions & {
|
|
@@ -69,6 +71,7 @@ export type RemoveJobMemberOptions = {
|
|
|
69
71
|
member_id: string;
|
|
70
72
|
};
|
|
71
73
|
export type SetLocationMembersOptions = {
|
|
74
|
+
owner_id: string;
|
|
72
75
|
location: Location;
|
|
73
76
|
current_members: string[];
|
|
74
77
|
};
|
package/dist/src/jobs/jobs.js
CHANGED
|
@@ -9,9 +9,10 @@ import { isZeroDate, normalizeInputDate, zeroInputDate, } from "../core/date.js"
|
|
|
9
9
|
import { errRequired, errResolveFailed, errValidation, } from "../core/err.js";
|
|
10
10
|
import { requiredOperationID, resolvedID } from "../core/id.js";
|
|
11
11
|
import { runPreActionCheck } from "../core/pre-action.js";
|
|
12
|
-
import { runOwnerSearch, runSearch, } from "../core/search.js";
|
|
12
|
+
import { runOwnerSearch, runSearch, withOwnerQuery, } from "../core/search.js";
|
|
13
13
|
const msgJobIDRequired = "Job ID is required.";
|
|
14
14
|
const msgLocationIDRequired = "Location ID is required.";
|
|
15
|
+
const msgOwnerIDRequired = "Owner ID is required.";
|
|
15
16
|
const msgMemberIDRequired = "Member ID is required.";
|
|
16
17
|
const msgJobLocationMismatch = "Job location does not match the provided parent location.";
|
|
17
18
|
const msgProgramLocationMismatch = "Job program location does not match the provided parent location.";
|
|
@@ -69,6 +70,7 @@ export class JobsFX {
|
|
|
69
70
|
return await this.findLocation(id);
|
|
70
71
|
}
|
|
71
72
|
async updateLocation(opts) {
|
|
73
|
+
const owner_id = requiredID(opts.owner_id, "owner_id", msgOwnerIDRequired);
|
|
72
74
|
const id = requiredID(opts.location.id, "location", msgLocationIDRequired);
|
|
73
75
|
const input = {
|
|
74
76
|
...opts.in,
|
|
@@ -78,7 +80,7 @@ export class JobsFX {
|
|
|
78
80
|
const current_members = normalizeIDs(opts.in.current_members);
|
|
79
81
|
const removed_members = removedIDs(opts.location.current_members, current_members);
|
|
80
82
|
if (removed_members.length > 0) {
|
|
81
|
-
await this.checkLocationMemberRemoval(id, removed_members);
|
|
83
|
+
await this.checkLocationMemberRemoval(owner_id, id, removed_members);
|
|
82
84
|
}
|
|
83
85
|
input.current_members = current_members;
|
|
84
86
|
}
|
|
@@ -86,11 +88,12 @@ export class JobsFX {
|
|
|
86
88
|
return await this.findLocation(id);
|
|
87
89
|
}
|
|
88
90
|
async archiveLocation(opts) {
|
|
91
|
+
const owner_id = requiredID(opts.owner_id, "owner_id", msgOwnerIDRequired);
|
|
89
92
|
const id = requiredID(opts.location.id, "location", msgLocationIDRequired);
|
|
90
93
|
if (opts.location.is_archived) {
|
|
91
94
|
return opts.location;
|
|
92
95
|
}
|
|
93
|
-
await this.checkLocationArchive(id);
|
|
96
|
+
await this.checkLocationArchive(owner_id, id);
|
|
94
97
|
await this.jobs.replaceOneLocation({ id, in: { is_archived: true } });
|
|
95
98
|
return await this.findLocation(id);
|
|
96
99
|
}
|
|
@@ -271,6 +274,7 @@ export class JobsFX {
|
|
|
271
274
|
}
|
|
272
275
|
async setLocationMembers(opts) {
|
|
273
276
|
return await this.updateLocation({
|
|
277
|
+
owner_id: opts.owner_id,
|
|
274
278
|
location: opts.location,
|
|
275
279
|
in: {
|
|
276
280
|
current_members: normalizeIDs(opts.current_members),
|
|
@@ -348,30 +352,30 @@ export class JobsFX {
|
|
|
348
352
|
}
|
|
349
353
|
return await this.setJobStatus(opts.job, Cancelled);
|
|
350
354
|
}
|
|
351
|
-
async checkLocationMemberRemoval(location_id, removed_members) {
|
|
355
|
+
async checkLocationMemberRemoval(owner_id, location_id, removed_members) {
|
|
352
356
|
await runPreActionCheck({
|
|
353
357
|
reason: JobsPreActionReason.LocationMemberAssignedOpenJob,
|
|
354
358
|
allowed: async () => {
|
|
355
359
|
const out = await this.jobs.queryJobs({
|
|
356
|
-
query: queryParams({
|
|
360
|
+
query: withOwnerQuery(owner_id, queryParams({
|
|
357
361
|
location_id,
|
|
358
362
|
status: [Pending, Started],
|
|
359
363
|
current_members: removed_members,
|
|
360
|
-
}),
|
|
364
|
+
})),
|
|
361
365
|
});
|
|
362
366
|
return (out.value?.length ?? 0) === 0;
|
|
363
367
|
},
|
|
364
368
|
});
|
|
365
369
|
}
|
|
366
|
-
async checkLocationArchive(location_id) {
|
|
370
|
+
async checkLocationArchive(owner_id, location_id) {
|
|
367
371
|
await runPreActionCheck({
|
|
368
372
|
reason: JobsPreActionReason.LocationHasOpenJobs,
|
|
369
373
|
allowed: async () => {
|
|
370
374
|
const out = await this.jobs.queryJobs({
|
|
371
|
-
query: queryParams({
|
|
375
|
+
query: withOwnerQuery(owner_id, queryParams({
|
|
372
376
|
location_id,
|
|
373
377
|
status: [Pending, Started],
|
|
374
|
-
}),
|
|
378
|
+
})),
|
|
375
379
|
});
|
|
376
380
|
return (out.value?.length ?? 0) === 0;
|
|
377
381
|
},
|
|
@@ -380,10 +384,10 @@ export class JobsFX {
|
|
|
380
384
|
reason: JobsPreActionReason.LocationHasActivePrograms,
|
|
381
385
|
allowed: async () => {
|
|
382
386
|
const out = await this.jobs.queryJobPrograms({
|
|
383
|
-
query: queryParams({
|
|
387
|
+
query: withOwnerQuery(owner_id, queryParams({
|
|
384
388
|
job_location_id: location_id,
|
|
385
389
|
finished: false,
|
|
386
|
-
}),
|
|
390
|
+
})),
|
|
387
391
|
});
|
|
388
392
|
return (out.value?.length ?? 0) === 0;
|
|
389
393
|
},
|