@fabriktor/fx 0.0.75 → 0.0.77

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.
@@ -0,0 +1,5 @@
1
+ import type { Date as SchemaDate } from "@fabriktor/schema";
2
+ export type LocalDateParts = Pick<SchemaDate, "y" | "m" | "d" | "h" | "min">;
3
+ export declare function normalizeBackendDate(v: LocalDateParts): SchemaDate;
4
+ export declare function zeroDate(): SchemaDate;
5
+ export declare function isZeroDate(v: LocalDateParts): boolean;
@@ -0,0 +1,39 @@
1
+ // Copyright (C) Fabriktor, Inc. 2025-present.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License"); you may
4
+ // not use this file except in compliance with the License. You may obtain
5
+ // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ const zeroUTC = "0001-01-01T00:00:00Z";
7
+ const utcTimezone = "UTC";
8
+ export function normalizeBackendDate(v) {
9
+ if (isZeroDate(v)) {
10
+ return zeroDate();
11
+ }
12
+ return {
13
+ utc: zeroUTC,
14
+ y: v.y,
15
+ m: v.m,
16
+ d: v.d,
17
+ h: v.h,
18
+ min: v.min,
19
+ tz: utcTimezone,
20
+ };
21
+ }
22
+ export function zeroDate() {
23
+ return {
24
+ utc: zeroUTC,
25
+ y: 1,
26
+ m: 1,
27
+ d: 1,
28
+ h: 0,
29
+ min: 0,
30
+ tz: utcTimezone,
31
+ };
32
+ }
33
+ export function isZeroDate(v) {
34
+ if (v.h !== 0 || v.min !== 0) {
35
+ return false;
36
+ }
37
+ return ((v.y === 0 && v.m === 0 && v.d === 0) ||
38
+ (v.y === 1 && v.m === 1 && v.d === 1));
39
+ }
@@ -3,6 +3,7 @@ export * from "./billable/billable.js";
3
3
  export * from "./calls/calls.js";
4
4
  export * from "./chat/chat.js";
5
5
  export * from "./contacts/contacts.js";
6
+ export * from "./core/date.js";
6
7
  export * from "./core/err.js";
7
8
  export * from "./core/id.js";
8
9
  export * from "./core/pull.js";
package/dist/src/index.js CHANGED
@@ -3,6 +3,7 @@ export * from "./billable/billable.js";
3
3
  export * from "./calls/calls.js";
4
4
  export * from "./chat/chat.js";
5
5
  export * from "./contacts/contacts.js";
6
+ export * from "./core/date.js";
6
7
  export * from "./core/err.js";
7
8
  export * from "./core/id.js";
8
9
  export * from "./core/pull.js";
@@ -1,31 +1,33 @@
1
- import { type Job, type JobProgram, type Location, type OperationResult, type RPJobsFindOverlaps } from "@fabriktor/schema";
2
- import type { JobsOperator, OperationResultOf } from "@fabriktor/client";
1
+ import { type Job, type JobProgram, type Location } from "@fabriktor/schema";
2
+ import { type JobsOperator } from "@fabriktor/client";
3
3
  import { type OwnerSearchOptions, type SearchOptions, type SearchPage } from "../core/search.js";
4
4
  type JobInsert = Parameters<JobsOperator["insertOneJob"]>[0]["in"];
5
5
  type JobProgramInsert = Parameters<JobsOperator["insertOneJobProgram"]>[0]["in"];
6
- type LocationInsert = Parameters<JobsOperator["insertOneLocation"]>[0]["in"];
7
6
  type LocationInsertOptions = Parameters<JobsOperator["insertOneLocation"]>[0];
8
- type LocationReplaceOptions = Parameters<JobsOperator["replaceOneLocation"]>[0];
9
- type JobProgramReplaceOptions = Parameters<JobsOperator["replaceOneJobProgram"]>[0];
10
- type JobReplaceOptions = Parameters<JobsOperator["replaceOneJob"]>[0];
7
+ type LocationReplaceInput = Parameters<JobsOperator["replaceOneLocation"]>[0]["in"];
11
8
  export declare const JobProgramCreateMode: {
12
9
  readonly Scheduled: "scheduled";
13
10
  readonly Immediate: "immediate";
14
11
  };
15
12
  export type JobProgramCreateMode = (typeof JobProgramCreateMode)[keyof typeof JobProgramCreateMode];
16
13
  export type CreateLocationOptions = LocationInsertOptions;
17
- export type CreateOperationalLocationInput = Omit<LocationInsert, "status" | "is_active" | "all_members">;
18
- export type CreateOperationalLocationOptions = {
19
- in: CreateOperationalLocationInput;
20
- };
21
- export type ReplaceLocationOptions = LocationReplaceOptions;
22
- export type ReplaceJobProgramOptions = JobProgramReplaceOptions;
23
- export type ReplaceJobOptions = JobReplaceOptions;
24
- export type SearchLocationsOptions = OwnerSearchOptions;
25
- export type SearchAccessibleLocationsOptions = SearchOptions;
14
+ export type UpdateLocationOptions = {
15
+ location: Location;
16
+ in: LocationReplaceInput;
17
+ };
18
+ export type SearchLocationsOptions = OwnerSearchOptions & {
19
+ is_archived?: boolean;
20
+ };
21
+ export type SearchAccessibleLocationsOptions = SearchOptions & {
22
+ is_archived?: boolean;
23
+ };
26
24
  export type SearchJobProgramsOptions = OwnerSearchOptions;
27
- export type SearchJobsOptions = OwnerSearchOptions;
28
- export type SearchAccessibleJobsOptions = SearchOptions;
25
+ export type SearchJobsOptions = OwnerSearchOptions & {
26
+ location_id?: string;
27
+ };
28
+ export type SearchAccessibleJobsOptions = SearchOptions & {
29
+ location_id?: string;
30
+ };
29
31
  export type SearchLocationsPage = SearchPage<Location>;
30
32
  export type SearchJobProgramsPage = SearchPage<JobProgram>;
31
33
  export type SearchJobsPage = SearchPage<Job>;
@@ -33,38 +35,20 @@ export type JobsFXOptions = {
33
35
  jobs: JobsOperator;
34
36
  now?: () => globalThis.Date;
35
37
  };
36
- export type CreateJobInput = Omit<JobInsert, "status" | "is_active" | "auto_start" | "all_members" | "location_id" | "recurrent">;
37
38
  export type CreateJobOptions = {
38
- in: CreateJobInput;
39
+ in: JobInsert;
39
40
  location: Location;
40
- auto_start: boolean;
41
- start_immediately: boolean;
42
41
  };
43
- export type CreateJobProgramInput = Omit<JobProgramInsert, "job_location_id" | "current_occurrences">;
44
42
  export type CreateJobProgramOptions = {
45
- in: CreateJobProgramInput;
43
+ in: JobProgramInsert;
46
44
  location: Location;
47
45
  };
48
- export type CreateLocationJobProgramResult = {
49
- mode: typeof JobProgramCreateMode.Scheduled;
50
- create: OperationResult;
51
- } | {
52
- mode: typeof JobProgramCreateMode.Immediate;
53
- };
54
46
  export type CreateJobProgramResult = {
55
47
  mode: typeof JobProgramCreateMode.Scheduled;
56
48
  job_program: JobProgram;
57
49
  } | {
58
50
  mode: typeof JobProgramCreateMode.Immediate;
59
51
  };
60
- export type FindLocationOverlapsInput = Pick<LocationInsert, "y" | "m" | "d" | "h" | "min" | "tz" | "end_date" | "lat" | "lon">;
61
- export type FindLocationOverlapsOptions = {
62
- in: FindLocationOverlapsInput;
63
- source_id?: string;
64
- exclude_pending?: boolean;
65
- exclude_started?: boolean;
66
- exclude_terminated?: boolean;
67
- };
68
52
  export type AddJobForemanOptions = {
69
53
  job: Job;
70
54
  location: Location;
@@ -72,11 +56,8 @@ export type AddJobForemanOptions = {
72
56
  };
73
57
  export type RemoveJobMemberOptions = {
74
58
  job: Job;
75
- member_id: string;
76
- };
77
- export type UpdateOperationalLocationOptions = {
78
59
  location: Location;
79
- in: CreateOperationalLocationInput;
60
+ member_id: string;
80
61
  };
81
62
  export type SetLocationMembersOptions = {
82
63
  location: Location;
@@ -96,61 +77,50 @@ export type JobLifecycleControlsOptions = JobLifecycleOptions & {
96
77
  };
97
78
  export type JobLifecycleControls = {
98
79
  can_start: boolean;
99
- can_terminate: boolean;
80
+ can_complete: boolean;
81
+ can_cancel: boolean;
100
82
  };
101
83
  export interface JobsFXOperator {
102
84
  createLocation(opts: CreateLocationOptions): Promise<Location>;
103
- createOperationalLocation(opts: CreateOperationalLocationOptions): Promise<Location>;
104
- replaceLocation(opts: ReplaceLocationOptions): Promise<Location>;
85
+ updateLocation(opts: UpdateLocationOptions): Promise<Location>;
105
86
  searchLocations(opts: SearchLocationsOptions): Promise<SearchLocationsPage>;
106
87
  searchAccessibleLocations(opts?: SearchAccessibleLocationsOptions): Promise<SearchLocationsPage>;
107
- replaceJobProgram(opts: ReplaceJobProgramOptions): Promise<JobProgram>;
88
+ createJobProgram(opts: CreateJobProgramOptions): Promise<CreateJobProgramResult>;
108
89
  searchJobPrograms(opts: SearchJobProgramsOptions): Promise<SearchJobProgramsPage>;
109
- replaceJob(opts: ReplaceJobOptions): Promise<Job>;
90
+ createJob(opts: CreateJobOptions): Promise<Job>;
110
91
  searchJobs(opts: SearchJobsOptions): Promise<SearchJobsPage>;
111
92
  searchAccessibleJobs(opts?: SearchAccessibleJobsOptions): Promise<SearchJobsPage>;
112
- createJob(opts: CreateJobOptions): Promise<Job>;
113
- createLocationJob(opts: CreateJobOptions): Promise<OperationResult>;
114
- createJobProgram(opts: CreateJobProgramOptions): Promise<CreateJobProgramResult>;
115
- createLocationJobProgram(opts: CreateJobProgramOptions): Promise<CreateLocationJobProgramResult>;
116
- findLocationOverlaps(opts: FindLocationOverlapsOptions): Promise<OperationResultOf<RPJobsFindOverlaps>>;
117
- updateOperationalLocation(opts: UpdateOperationalLocationOptions): Promise<Location>;
118
- addJobForeman(opts: AddJobForemanOptions): Promise<OperationResult>;
119
- removeJobMember(opts: RemoveJobMemberOptions): Promise<OperationResult>;
120
- setLocationMembers(opts: SetLocationMembersOptions): Promise<OperationResult>;
121
- setJobMembers(opts: SetJobMembersOptions): Promise<OperationResult>;
93
+ addJobForeman(opts: AddJobForemanOptions): Promise<Job>;
94
+ removeJobMember(opts: RemoveJobMemberOptions): Promise<Job>;
95
+ setLocationMembers(opts: SetLocationMembersOptions): Promise<Location>;
96
+ setJobMembers(opts: SetJobMembersOptions): Promise<Job>;
122
97
  jobLifecycleControls(opts: JobLifecycleControlsOptions): JobLifecycleControls;
123
98
  startJob(opts: JobLifecycleOptions): Promise<Job>;
124
- terminateJob(opts: JobLifecycleOptions): Promise<Job>;
99
+ completeJob(opts: JobLifecycleOptions): Promise<Job>;
100
+ cancelJob(opts: JobLifecycleOptions): Promise<Job>;
125
101
  }
126
102
  export declare class JobsFX implements JobsFXOperator {
127
103
  private jobs;
128
104
  private now;
129
105
  constructor(opts: JobsFXOptions);
130
106
  createLocation(opts: CreateLocationOptions): Promise<Location>;
131
- createOperationalLocation(opts: CreateOperationalLocationOptions): Promise<Location>;
132
- replaceLocation(opts: ReplaceLocationOptions): Promise<Location>;
107
+ updateLocation(opts: UpdateLocationOptions): Promise<Location>;
133
108
  searchLocations(opts: SearchLocationsOptions): Promise<SearchLocationsPage>;
134
109
  searchAccessibleLocations(opts?: SearchAccessibleLocationsOptions): Promise<SearchLocationsPage>;
135
- replaceJobProgram(opts: ReplaceJobProgramOptions): Promise<JobProgram>;
110
+ createJobProgram(opts: CreateJobProgramOptions): Promise<CreateJobProgramResult>;
136
111
  searchJobPrograms(opts: SearchJobProgramsOptions): Promise<SearchJobProgramsPage>;
137
- replaceJob(opts: ReplaceJobOptions): Promise<Job>;
112
+ createJob(opts: CreateJobOptions): Promise<Job>;
138
113
  searchJobs(opts: SearchJobsOptions): Promise<SearchJobsPage>;
139
114
  searchAccessibleJobs(opts?: SearchAccessibleJobsOptions): Promise<SearchJobsPage>;
140
- createJob(opts: CreateJobOptions): Promise<Job>;
141
- createLocationJob(opts: CreateJobOptions): Promise<OperationResult>;
142
- createJobProgram(opts: CreateJobProgramOptions): Promise<CreateJobProgramResult>;
143
- createLocationJobProgram(opts: CreateJobProgramOptions): Promise<CreateLocationJobProgramResult>;
144
- findLocationOverlaps(opts: FindLocationOverlapsOptions): Promise<OperationResultOf<RPJobsFindOverlaps>>;
145
- addJobForeman(opts: AddJobForemanOptions): Promise<OperationResult>;
146
- removeJobMember(opts: RemoveJobMemberOptions): Promise<OperationResult>;
147
- updateOperationalLocation(opts: UpdateOperationalLocationOptions): Promise<Location>;
148
- setLocationMembers(opts: SetLocationMembersOptions): Promise<OperationResult>;
149
- setJobMembers(opts: SetJobMembersOptions): Promise<OperationResult>;
150
- private validateLocationMemberRemoval;
115
+ addJobForeman(opts: AddJobForemanOptions): Promise<Job>;
116
+ removeJobMember(opts: RemoveJobMemberOptions): Promise<Job>;
117
+ setLocationMembers(opts: SetLocationMembersOptions): Promise<Location>;
118
+ setJobMembers(opts: SetJobMembersOptions): Promise<Job>;
151
119
  jobLifecycleControls(opts: JobLifecycleControlsOptions): JobLifecycleControls;
152
120
  startJob(opts: JobLifecycleOptions): Promise<Job>;
153
- terminateJob(opts: JobLifecycleOptions): Promise<Job>;
121
+ completeJob(opts: JobLifecycleOptions): Promise<Job>;
122
+ cancelJob(opts: JobLifecycleOptions): Promise<Job>;
123
+ private setJobStatus;
154
124
  private findLocation;
155
125
  private findJobProgram;
156
126
  private findJob;
@@ -3,7 +3,9 @@
3
3
  // Licensed under the Apache License, Version 2.0 (the "License"); you may
4
4
  // not use this file except in compliance with the License. You may obtain
5
5
  // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- import { LocationTypePersistent, Pending, Started, Terminated, ZeroID, } from "@fabriktor/schema";
6
+ import { Cancelled, Completed, Pending, RecurrenceEndTypeAfterDate, RecurrenceEndTypeAfterOccurrences, RecurrenceEndTypeIndefinite, Started, } from "@fabriktor/schema";
7
+ import { queryParams } from "@fabriktor/client";
8
+ import { isZeroDate, normalizeBackendDate, zeroDate, } from "../core/date.js";
7
9
  import { errRequired, errResolveFailed, errValidation, } from "../core/err.js";
8
10
  import { requiredOperationID, resolvedID } from "../core/id.js";
9
11
  import { runOwnerSearch, runSearch, } from "../core/search.js";
@@ -11,16 +13,24 @@ const msgJobIDRequired = "Job ID is required.";
11
13
  const msgLocationIDRequired = "Location ID is required.";
12
14
  const msgMemberIDRequired = "Member ID is required.";
13
15
  const msgJobLocationMismatch = "Job location does not match the provided parent location.";
16
+ const msgProgramLocationMismatch = "Job program location does not match the provided parent location.";
14
17
  const msgJobMembersOutsideLocation = "All job members must belong to the parent location.";
15
18
  const msgProgramMembersOutsideLocation = "All program job members must belong to the parent location.";
16
- const msgForemanOutsideLocation = "Foreman must belong to the parent location.";
17
- const msgJobStartPast = "A past-dated job must be explicitly created as an immediate job.";
19
+ const msgForemenOutsideJob = "Foremen must belong to the job members.";
20
+ const msgProgramForemenOutsideJob = "Program foremen must belong to the program job members.";
21
+ const msgArchivedLocation = "Archived locations cannot receive new work.";
22
+ const msgExpectedEndBeforeStart = "Expected end date must not be before the planned start date.";
18
23
  const msgProgramStartPast = "Program start date must not be in the past.";
19
- const msgJobStartOutsideLocation = "Job start date must fall within the parent location time span.";
20
- const msgProgramStartOutsideLocation = "Program job start date must fall within the parent location time span.";
21
- const msgLocationMemberAssigned = "Cannot remove a location member while they are assigned to a non-terminated job in that location.";
22
- const msgLocationRangeInvalid = "Location contains an invalid scheduled time span.";
23
24
  const msgTimezoneInvalid = "Location timezone is invalid.";
25
+ const msgInitialJobStatusInvalid = "A new job must be created as pending or started.";
26
+ const msgJobStartInvalid = "Only pending jobs can be started.";
27
+ const msgJobCompleteInvalid = "Only started jobs can be completed.";
28
+ const msgJobCancelInvalid = "Only pending or started jobs can be cancelled.";
29
+ const msgProgramDurationInvalid = "Expected job duration must be a non-negative whole number of minutes.";
30
+ const msgRecurrenceRateInvalid = "Recurrence rate must be a positive whole number.";
31
+ const msgRecurrenceEndTypeInvalid = "Recurrence end type is invalid.";
32
+ const msgOccurrencesInvalid = "Occurrences to end must be a positive whole number.";
33
+ const msgRecurrenceEndDateRequired = "Recurrence end date is required.";
24
34
  const resourceLocation = "location";
25
35
  const resourceJobProgram = "job_program";
26
36
  const resourceJob = "job";
@@ -30,8 +40,6 @@ const msgCreatedJobIDMissing = "Created job response did not contain an ID.";
30
40
  const msgLocationMissing = "Location could not be resolved after the mutation.";
31
41
  const msgJobProgramMissing = "Job program could not be resolved after the mutation.";
32
42
  const msgJobMissing = "Job could not be resolved after the mutation.";
33
- const msgJobNotActive = "Job must be active before it can be started.";
34
- const msgJobTerminated = "Terminated jobs cannot be started.";
35
43
  export const JobProgramCreateMode = {
36
44
  Scheduled: "scheduled",
37
45
  Immediate: "immediate",
@@ -44,377 +52,294 @@ export class JobsFX {
44
52
  this.now = opts.now ?? (() => new globalThis.Date());
45
53
  }
46
54
  async createLocation(opts) {
47
- const out = await this.jobs.insertOneLocation(opts);
48
- const id = requiredOperationID(out, msgCreatedLocationIDMissing);
49
- return await this.findLocation(id);
50
- }
51
- async createOperationalLocation(opts) {
52
- const persistent = opts.in.type === LocationTypePersistent;
53
- return await this.createLocation({
55
+ const out = await this.jobs.insertOneLocation({
54
56
  in: {
55
57
  ...opts.in,
56
- status: persistent ? Started : Pending,
57
- is_active: persistent,
58
- auto_start: persistent ? true : opts.in.auto_start,
59
- all_members: [],
58
+ is_archived: false,
59
+ address_timezone: "",
60
60
  current_members: normalizeIDs(opts.in.current_members),
61
61
  },
62
62
  });
63
+ const id = requiredOperationID(out, msgCreatedLocationIDMissing);
64
+ return await this.findLocation(id);
63
65
  }
64
- async replaceLocation(opts) {
65
- await this.jobs.replaceOneLocation(opts);
66
- return await this.findLocation(opts.id);
66
+ async updateLocation(opts) {
67
+ const id = requiredID(opts.location.id, "location", msgLocationIDRequired);
68
+ const input = {
69
+ ...opts.in,
70
+ ...locationAddressInput(opts.location),
71
+ };
72
+ if (opts.in.current_members !== undefined) {
73
+ input.current_members = normalizeIDs(opts.in.current_members);
74
+ }
75
+ await this.jobs.replaceOneLocation({ id, in: input });
76
+ return await this.findLocation(id);
67
77
  }
68
78
  async searchLocations(opts) {
79
+ const { is_archived, ...searchOpts } = opts;
69
80
  return await runOwnerSearch({
70
- ...opts,
71
- search: (searchOpts) => this.jobs.searchManyLocations(searchOpts),
81
+ ...searchOpts,
82
+ query: is_archived === undefined
83
+ ? undefined
84
+ : queryParams({ is_archived }),
85
+ search: (opts) => this.jobs.searchManyLocations(opts),
72
86
  });
73
87
  }
74
88
  async searchAccessibleLocations(opts = {}) {
89
+ const { is_archived, ...searchOpts } = opts;
75
90
  return await runSearch({
76
- ...opts,
77
- search: (searchOpts) => this.jobs.searchMineLocations(searchOpts),
78
- });
79
- }
80
- async replaceJobProgram(opts) {
81
- await this.jobs.replaceOneJobProgram(opts);
82
- return await this.findJobProgram(opts.id);
83
- }
84
- async searchJobPrograms(opts) {
85
- return await runOwnerSearch({
86
- ...opts,
87
- search: (searchOpts) => this.jobs.searchManyJobPrograms(searchOpts),
88
- });
89
- }
90
- async replaceJob(opts) {
91
- await this.jobs.replaceOneJob(opts);
92
- return await this.findJob(opts.id);
93
- }
94
- async searchJobs(opts) {
95
- return await runOwnerSearch({
96
- ...opts,
97
- search: (searchOpts) => this.jobs.searchManyJobs(searchOpts),
98
- });
99
- }
100
- async searchAccessibleJobs(opts = {}) {
101
- return await runSearch({
102
- ...opts,
103
- search: (searchOpts) => this.jobs.searchMineJobs(searchOpts),
104
- });
105
- }
106
- async createJob(opts) {
107
- const out = await this.createLocationJob(opts);
108
- const id = requiredOperationID(out, msgCreatedJobIDMissing);
109
- return await this.findJob(id);
110
- }
111
- async createLocationJob(opts) {
112
- const location_id = requiredID(opts.location.id, "location", msgLocationIDRequired);
113
- const foremen = normalizeIDs(opts.in.foremen);
114
- const current_members = unionIDs(opts.in.current_members, foremen);
115
- validateLocationMembers({
116
- members: current_members,
117
- location: opts.location,
118
- field: "in",
119
- msg: msgJobMembersOutsideLocation,
120
- });
121
- const timezone = locationTimezone(opts.location, "location");
122
- const input = {
123
- ...opts.in,
124
- tz: timezone,
125
- timezone,
126
- status: opts.start_immediately ? Started : Pending,
127
- is_active: opts.start_immediately,
128
- auto_start: opts.start_immediately ? true : opts.auto_start,
129
- all_members: [],
130
- current_members,
131
- foremen,
132
- location_id,
133
- recurrent: false,
134
- };
135
- validateJobStart({
136
- input,
137
- location: opts.location,
138
- now: this.now(),
139
- start_immediately: opts.start_immediately,
140
- });
141
- return await this.jobs.insertOneJob({
142
- in: input,
91
+ ...searchOpts,
92
+ query: is_archived === undefined
93
+ ? undefined
94
+ : queryParams({ is_archived }),
95
+ search: (opts) => this.jobs.searchMineLocations(opts),
143
96
  });
144
97
  }
145
98
  async createJobProgram(opts) {
146
- const out = await this.createLocationJobProgram(opts);
147
- if (out.mode === JobProgramCreateMode.Immediate) {
148
- return {
149
- mode: JobProgramCreateMode.Immediate,
150
- };
151
- }
152
- const id = requiredOperationID(out.create, msgCreatedJobProgramIDMissing);
153
- return {
154
- mode: JobProgramCreateMode.Scheduled,
155
- job_program: await this.findJobProgram(id),
156
- };
157
- }
158
- async createLocationJobProgram(opts) {
159
- const job_location_id = requiredID(opts.location.id, "location", msgLocationIDRequired);
99
+ validateLocationAvailable(opts.location, "location");
100
+ const job_location_id = locationID(opts.location, opts.in.job_location_id, "in", msgProgramLocationMismatch);
101
+ const job_current_members = normalizeIDs(opts.in.job_current_members);
160
102
  const job_foremen = normalizeIDs(opts.in.job_foremen);
161
- const job_current_members = unionIDs(opts.in.job_current_members, job_foremen);
162
103
  validateLocationMembers({
163
104
  members: job_current_members,
164
105
  location: opts.location,
165
106
  field: "in",
166
107
  msg: msgProgramMembersOutsideLocation,
167
108
  });
168
- const timezone = locationTimezone(opts.location, "location");
109
+ validateForemen({
110
+ foremen: job_foremen,
111
+ members: job_current_members,
112
+ field: "in",
113
+ msg: msgProgramForemenOutsideJob,
114
+ });
115
+ validateDuration(opts.in.job_expected_duration_in_minutes, "in");
116
+ validateRecurrenceRate(opts.in.recurrence_rate, "in");
117
+ const recurrence = normalizeRecurrenceEnd({
118
+ end_type: opts.in.recurrence_end_type,
119
+ occurrences_to_end: opts.in.occurrences_to_end,
120
+ recurrence_end_date: opts.in.recurrence_end_date,
121
+ field: "in",
122
+ });
169
123
  const input = {
170
124
  ...opts.in,
171
- timezone,
172
- job_start_date: {
173
- ...opts.in.job_start_date,
174
- tz: timezone,
175
- },
176
- recurrence_end_date: {
177
- ...opts.in.recurrence_end_date,
178
- tz: timezone,
179
- },
125
+ job_start_date: normalizeBackendDate(opts.in.job_start_date),
180
126
  job_current_members,
181
127
  job_foremen,
182
128
  job_location_id,
183
- current_occurrences: 0,
129
+ occurrences_to_end: recurrence.occurrences_to_end,
130
+ recurrence_end_date: recurrence.recurrence_end_date,
184
131
  };
185
- const now = this.now();
186
- const current_day = isCurrentProgramDay(input, now);
187
- validateProgramStart({
188
- input,
132
+ const current_day = validateProgramStart({
133
+ start: input.job_start_date,
189
134
  location: opts.location,
190
- now,
191
- current_day,
135
+ now: this.now(),
192
136
  });
193
137
  if (current_day) {
194
138
  await this.jobs.immediateJobFromProgram(input);
195
- return {
196
- mode: JobProgramCreateMode.Immediate,
197
- };
139
+ return { mode: JobProgramCreateMode.Immediate };
198
140
  }
199
- const create = await this.jobs.insertOneJobProgram({
200
- in: input,
201
- });
141
+ const out = await this.jobs.insertOneJobProgram({ in: input });
142
+ const id = requiredOperationID(out, msgCreatedJobProgramIDMissing);
202
143
  return {
203
144
  mode: JobProgramCreateMode.Scheduled,
204
- create,
145
+ job_program: await this.findJobProgram(id),
205
146
  };
206
147
  }
207
- async findLocationOverlaps(opts) {
208
- const input = {
209
- lat: opts.in.lat,
210
- lon: opts.in.lon,
211
- start_date: {
212
- y: opts.in.y,
213
- m: opts.in.m,
214
- d: opts.in.d,
215
- h: opts.in.h,
216
- min: opts.in.min,
217
- tz: opts.in.tz,
218
- },
219
- end_date: {
220
- y: opts.in.end_date.y,
221
- m: opts.in.end_date.m,
222
- d: opts.in.end_date.d,
223
- h: opts.in.end_date.h,
224
- min: opts.in.end_date.min,
225
- tz: opts.in.end_date.tz,
226
- },
227
- source_id: resolvedID(opts.source_id) ?? ZeroID,
228
- exclude_pending: opts.exclude_pending ?? false,
229
- exclude_started: opts.exclude_started ?? false,
230
- exclude_terminated: opts.exclude_terminated ?? false,
231
- };
232
- return await this.jobs.findOverlaps(input);
148
+ async searchJobPrograms(opts) {
149
+ return await runOwnerSearch({
150
+ ...opts,
151
+ search: (searchOpts) => this.jobs.searchManyJobPrograms(searchOpts),
152
+ });
233
153
  }
234
- async addJobForeman(opts) {
235
- const id = requiredID(opts.job.id, "job", msgJobIDRequired);
236
- const location_id = requiredID(opts.location.id, "location", msgLocationIDRequired);
237
- const job_location_id = opts.job.location_id.trim();
238
- if (job_location_id !== location_id) {
239
- throw errValidation({
240
- field: "job",
241
- msg: msgJobLocationMismatch,
242
- });
243
- }
244
- const member_id = opts.member_id.trim();
245
- if (member_id === "") {
246
- throw errRequired({
247
- field: "member_id",
248
- msg: msgMemberIDRequired,
249
- });
250
- }
251
- const location_members = new Set(normalizeIDs(opts.location.current_members));
252
- if (!location_members.has(member_id)) {
154
+ async createJob(opts) {
155
+ validateLocationAvailable(opts.location, "location");
156
+ const location_id = locationID(opts.location, opts.in.location_id, "in", msgJobLocationMismatch);
157
+ if (opts.in.status !== Pending && opts.in.status !== Started) {
253
158
  throw errValidation({
254
- field: "member_id",
255
- msg: msgForemanOutsideLocation,
159
+ field: "in",
160
+ msg: msgInitialJobStatusInvalid,
256
161
  });
257
162
  }
258
- return await this.jobs.replaceOneJob({
259
- id,
163
+ const current_members = normalizeIDs(opts.in.current_members);
164
+ const foremen = normalizeIDs(opts.in.foremen);
165
+ validateLocationMembers({
166
+ members: current_members,
167
+ location: opts.location,
168
+ field: "in",
169
+ msg: msgJobMembersOutsideLocation,
170
+ });
171
+ validateForemen({
172
+ foremen,
173
+ members: current_members,
174
+ field: "in",
175
+ msg: msgForemenOutsideJob,
176
+ });
177
+ const expected_end_date = normalizeBackendDate(opts.in.expected_end_date);
178
+ validateExpectedEnd({
179
+ start: opts.in,
180
+ end: expected_end_date,
181
+ field: "in",
182
+ });
183
+ const out = await this.jobs.insertOneJob({
260
184
  in: {
261
- current_members: unionIDs(opts.job.current_members, [member_id]),
262
- foremen: unionIDs(opts.job.foremen, [member_id]),
185
+ ...opts.in,
186
+ ...normalizeBackendDate(opts.in),
187
+ expected_end_date,
188
+ current_members,
189
+ foremen,
190
+ location_id,
263
191
  },
264
192
  });
193
+ const id = requiredOperationID(out, msgCreatedJobIDMissing);
194
+ return await this.findJob(id);
265
195
  }
266
- async removeJobMember(opts) {
196
+ async searchJobs(opts) {
197
+ const { location_id, ...searchOpts } = opts;
198
+ const id = resolvedID(location_id);
199
+ return await runOwnerSearch({
200
+ ...searchOpts,
201
+ query: id === undefined ? undefined : queryParams({ location_id: id }),
202
+ search: (opts) => this.jobs.searchManyJobs(opts),
203
+ });
204
+ }
205
+ async searchAccessibleJobs(opts = {}) {
206
+ const { location_id, ...searchOpts } = opts;
207
+ const id = resolvedID(location_id);
208
+ return await runSearch({
209
+ ...searchOpts,
210
+ query: id === undefined ? undefined : queryParams({ location_id: id }),
211
+ search: (opts) => this.jobs.searchMineJobs(opts),
212
+ });
213
+ }
214
+ async addJobForeman(opts) {
267
215
  const id = requiredID(opts.job.id, "job", msgJobIDRequired);
268
- const member_id = opts.member_id.trim();
269
- if (member_id === "") {
270
- throw errRequired({
216
+ const location_id = locationID(opts.location, opts.job.location_id, "job", msgJobLocationMismatch);
217
+ const member_id = requiredID(opts.member_id, "member_id", msgMemberIDRequired);
218
+ validateLocationAvailable(opts.location, "location");
219
+ if (!normalizeIDs(opts.job.current_members).includes(member_id)) {
220
+ throw errValidation({
271
221
  field: "member_id",
272
- msg: msgMemberIDRequired,
222
+ msg: msgForemenOutsideJob,
273
223
  });
274
224
  }
275
- return await this.jobs.replaceOneJob({
225
+ validateLocationMembers({
226
+ members: [member_id],
227
+ location: opts.location,
228
+ field: "member_id",
229
+ msg: msgJobMembersOutsideLocation,
230
+ });
231
+ await this.jobs.replaceOneJob({
276
232
  id,
277
233
  in: {
278
- current_members: withoutID(opts.job.current_members, member_id),
234
+ location_id,
235
+ foremen: unionIDs(opts.job.foremen, [member_id]),
279
236
  },
280
237
  });
238
+ return await this.findJob(id);
281
239
  }
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({
240
+ async removeJobMember(opts) {
241
+ const id = requiredID(opts.job.id, "job", msgJobIDRequired);
242
+ locationID(opts.location, opts.job.location_id, "job", msgJobLocationMismatch);
243
+ validateLocationAvailable(opts.location, "location");
244
+ const member_id = requiredID(opts.member_id, "member_id", msgMemberIDRequired);
245
+ await this.jobs.replaceOneJob({
290
246
  id,
291
247
  in: {
292
- ...opts.in,
293
- current_members,
248
+ current_members: withoutID(opts.job.current_members, member_id),
249
+ foremen: withoutID(opts.job.foremen, member_id),
294
250
  },
295
251
  });
252
+ return await this.findJob(id);
296
253
  }
297
254
  async setLocationMembers(opts) {
298
- const id = requiredID(opts.location.id, "location", msgLocationIDRequired);
299
- const current_members = normalizeIDs(opts.current_members);
300
- await this.validateLocationMemberRemoval({
255
+ return await this.updateLocation({
301
256
  location: opts.location,
302
- current_members,
303
- });
304
- return await this.jobs.replaceOneLocation({
305
- id,
306
257
  in: {
307
- current_members,
258
+ current_members: normalizeIDs(opts.current_members),
308
259
  },
309
260
  });
310
261
  }
311
262
  async setJobMembers(opts) {
312
263
  const id = requiredID(opts.job.id, "job", msgJobIDRequired);
313
- const location_id = requiredID(opts.location.id, "location", msgLocationIDRequired);
314
- if (opts.job.location_id.trim() !== location_id) {
315
- throw errValidation({
316
- field: "job",
317
- msg: msgJobLocationMismatch,
318
- });
319
- }
264
+ const location_id = locationID(opts.location, opts.job.location_id, "job", msgJobLocationMismatch);
265
+ validateLocationAvailable(opts.location, "location");
266
+ const current_members = normalizeIDs(opts.current_members);
320
267
  const foremen = normalizeIDs(opts.foremen);
321
- const current_members = unionIDs(opts.current_members, foremen);
322
268
  validateLocationMembers({
323
269
  members: current_members,
324
270
  location: opts.location,
325
271
  field: "current_members",
326
272
  msg: msgJobMembersOutsideLocation,
327
273
  });
328
- return await this.jobs.replaceOneJob({
329
- id,
330
- in: {
331
- current_members,
332
- foremen,
333
- },
274
+ validateForemen({
275
+ foremen,
276
+ members: current_members,
277
+ field: "foremen",
278
+ msg: msgForemenOutsideJob,
334
279
  });
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
- },
280
+ await this.jobs.replaceOneJob({
281
+ id,
282
+ in: { location_id, current_members, foremen },
348
283
  });
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
- }
284
+ return await this.findJob(id);
361
285
  }
362
286
  jobLifecycleControls(opts) {
363
287
  const actor_id = requiredID(opts.actor_id, "actor_id", msgMemberIDRequired);
364
288
  const can_manage = opts.job.owner_id === actor_id ||
365
289
  normalizeIDs(opts.job.foremen).includes(actor_id);
366
- const terminated = opts.job.status === Terminated;
367
290
  return {
368
- can_start: can_manage &&
369
- opts.job.is_active &&
370
- opts.job.status === Pending &&
371
- !terminated,
372
- can_terminate: can_manage && !terminated,
291
+ can_start: can_manage && opts.job.status === Pending,
292
+ can_complete: can_manage && opts.job.status === Started,
293
+ can_cancel: can_manage &&
294
+ (opts.job.status === Pending || opts.job.status === Started),
373
295
  };
374
296
  }
375
297
  async startJob(opts) {
376
- const id = requiredID(opts.job.id, "job", msgJobIDRequired);
377
- if (opts.job.status === Terminated) {
298
+ if (opts.job.status === Started) {
299
+ return opts.job;
300
+ }
301
+ if (opts.job.status !== Pending) {
378
302
  throw errValidation({
379
303
  field: "job",
380
- msg: msgJobTerminated,
304
+ msg: msgJobStartInvalid,
381
305
  });
382
306
  }
383
- if (opts.job.status === Started) {
307
+ return await this.setJobStatus(opts.job, Started);
308
+ }
309
+ async completeJob(opts) {
310
+ if (opts.job.status === Completed) {
384
311
  return opts.job;
385
312
  }
386
- if (!opts.job.is_active) {
313
+ if (opts.job.status !== Started) {
387
314
  throw errValidation({
388
315
  field: "job",
389
- msg: msgJobNotActive,
316
+ msg: msgJobCompleteInvalid,
390
317
  });
391
318
  }
392
- await this.jobs.replaceOneJob({
393
- id,
394
- in: {
395
- status: Started,
396
- },
397
- });
398
- return await this.findJob(id);
319
+ return await this.setJobStatus(opts.job, Completed);
399
320
  }
400
- async terminateJob(opts) {
401
- const id = requiredID(opts.job.id, "job", msgJobIDRequired);
402
- if (opts.job.status === Terminated) {
321
+ async cancelJob(opts) {
322
+ if (opts.job.status === Cancelled) {
403
323
  return opts.job;
404
324
  }
325
+ if (opts.job.status !== Pending && opts.job.status !== Started) {
326
+ throw errValidation({
327
+ field: "job",
328
+ msg: msgJobCancelInvalid,
329
+ });
330
+ }
331
+ return await this.setJobStatus(opts.job, Cancelled);
332
+ }
333
+ async setJobStatus(job, status) {
334
+ const id = requiredID(job.id, "job", msgJobIDRequired);
405
335
  await this.jobs.replaceOneJob({
406
336
  id,
407
- in: {
408
- status: Terminated,
409
- is_active: false,
410
- },
337
+ in: { status },
411
338
  });
412
339
  return await this.findJob(id);
413
340
  }
414
341
  async findLocation(id) {
415
- const out = await this.jobs.findOneLocation({
416
- id,
417
- });
342
+ const out = await this.jobs.findOneLocation({ id });
418
343
  const location = out.value;
419
344
  if (location === undefined) {
420
345
  throw errResolveFailed({
@@ -425,9 +350,7 @@ export class JobsFX {
425
350
  return location;
426
351
  }
427
352
  async findJobProgram(id) {
428
- const out = await this.jobs.findOneJobProgram({
429
- id,
430
- });
353
+ const out = await this.jobs.findOneJobProgram({ id });
431
354
  const job_program = out.value;
432
355
  if (job_program === undefined) {
433
356
  throw errResolveFailed({
@@ -438,9 +361,7 @@ export class JobsFX {
438
361
  return job_program;
439
362
  }
440
363
  async findJob(id) {
441
- const out = await this.jobs.findOneJob({
442
- id,
443
- });
364
+ const out = await this.jobs.findOneJob({ id });
444
365
  const job = out.value;
445
366
  if (job === undefined) {
446
367
  throw errResolveFailed({
@@ -463,109 +384,122 @@ function validateLocationMembers(opts) {
463
384
  });
464
385
  }
465
386
  }
466
- function validateJobStart(opts) {
467
- const now = localDateParts(opts.now, opts.input.timezone);
468
- if (now === undefined) {
387
+ function validateForemen(opts) {
388
+ const members = new Set(opts.members);
389
+ if (opts.foremen.some((id) => !members.has(id))) {
469
390
  throw errValidation({
470
- field: "in",
471
- msg: msgTimezoneInvalid,
391
+ field: opts.field,
392
+ msg: opts.msg,
472
393
  });
473
394
  }
474
- if (!opts.start_immediately && compareLocalDate(opts.input, now) < 0) {
395
+ }
396
+ function validateLocationAvailable(location, field) {
397
+ if (location.is_archived) {
475
398
  throw errValidation({
476
- field: "in",
477
- msg: msgJobStartPast,
399
+ field,
400
+ msg: msgArchivedLocation,
401
+ });
402
+ }
403
+ }
404
+ function locationID(location, requested_id, field, msg) {
405
+ const id = requiredID(location.id, field, msgLocationIDRequired);
406
+ if (resolvedID(requested_id) !== id) {
407
+ throw errValidation({ field, msg });
408
+ }
409
+ return id;
410
+ }
411
+ function validateExpectedEnd(opts) {
412
+ if (isZeroDate(opts.end)) {
413
+ return;
414
+ }
415
+ if (compareLocalDate(opts.end, opts.start) < 0) {
416
+ throw errValidation({
417
+ field: opts.field,
418
+ msg: msgExpectedEndBeforeStart,
478
419
  });
479
420
  }
480
- validateLocationStart({
481
- start: opts.input,
482
- location: opts.location,
483
- field: "in",
484
- msg: msgJobStartOutsideLocation,
485
- });
486
421
  }
487
422
  function validateProgramStart(opts) {
488
- const now = localDateParts(opts.now, opts.input.timezone);
423
+ const timezone = locationTimezone(opts.location, "location");
424
+ const now = localDateParts(opts.now, timezone);
489
425
  if (now === undefined) {
490
426
  throw errValidation({
491
- field: "in",
427
+ field: "location",
492
428
  msg: msgTimezoneInvalid,
493
429
  });
494
430
  }
495
- if (!opts.current_day &&
496
- compareLocalDate(opts.input.job_start_date, now) < 0) {
431
+ const current_day = sameCalendarDay(opts.start, now);
432
+ if (!current_day && compareLocalDate(opts.start, now) < 0) {
497
433
  throw errValidation({
498
434
  field: "in",
499
435
  msg: msgProgramStartPast,
500
436
  });
501
437
  }
502
- validateLocationStart({
503
- start: opts.input.job_start_date,
504
- location: opts.location,
505
- field: "in",
506
- msg: msgProgramStartOutsideLocation,
507
- });
438
+ return current_day;
508
439
  }
509
- function validateLocationStart(opts) {
510
- if (opts.location.type === LocationTypePersistent) {
511
- return;
512
- }
513
- const start = localDateFromLocation(opts.location);
514
- const end = opts.location.end_date;
515
- if (compareLocalDate(end, start) < 0) {
516
- throw errValidation({
517
- field: opts.field,
518
- msg: msgLocationRangeInvalid,
519
- });
440
+ function validateDuration(v, field) {
441
+ if (!Number.isFinite(v) || !Number.isInteger(v) || v < 0) {
442
+ throw errValidation({ field, msg: msgProgramDurationInvalid });
520
443
  }
521
- if (compareLocalDate(opts.start, start) < 0 ||
522
- compareLocalDate(opts.start, end) > 0) {
523
- throw errValidation({
524
- field: opts.field,
525
- msg: opts.msg,
526
- });
444
+ }
445
+ function validateRecurrenceRate(v, field) {
446
+ if (!Number.isFinite(v) || !Number.isInteger(v) || v <= 0) {
447
+ throw errValidation({ field, msg: msgRecurrenceRateInvalid });
527
448
  }
528
449
  }
529
- function isCurrentProgramDay(input, now) {
530
- const day = localDateParts(now, input.timezone);
531
- if (day === undefined) {
532
- throw errValidation({
533
- field: "in",
534
- msg: msgTimezoneInvalid,
535
- });
450
+ function normalizeRecurrenceEnd(opts) {
451
+ switch (opts.end_type) {
452
+ case RecurrenceEndTypeIndefinite:
453
+ return {
454
+ occurrences_to_end: 0,
455
+ recurrence_end_date: zeroDate(),
456
+ };
457
+ case RecurrenceEndTypeAfterOccurrences:
458
+ if (!Number.isFinite(opts.occurrences_to_end) ||
459
+ !Number.isInteger(opts.occurrences_to_end) ||
460
+ opts.occurrences_to_end <= 0) {
461
+ throw errValidation({
462
+ field: opts.field,
463
+ msg: msgOccurrencesInvalid,
464
+ });
465
+ }
466
+ return {
467
+ occurrences_to_end: opts.occurrences_to_end,
468
+ recurrence_end_date: zeroDate(),
469
+ };
470
+ case RecurrenceEndTypeAfterDate:
471
+ if (isZeroDate(opts.recurrence_end_date)) {
472
+ throw errRequired({
473
+ field: opts.field,
474
+ msg: msgRecurrenceEndDateRequired,
475
+ });
476
+ }
477
+ return {
478
+ occurrences_to_end: 0,
479
+ recurrence_end_date: normalizeBackendDate(opts.recurrence_end_date),
480
+ };
481
+ default:
482
+ throw errValidation({
483
+ field: opts.field,
484
+ msg: msgRecurrenceEndTypeInvalid,
485
+ });
536
486
  }
537
- return (input.job_start_date.y === day.y &&
538
- input.job_start_date.m === day.m &&
539
- input.job_start_date.d === day.d);
487
+ }
488
+ function sameCalendarDay(a, b) {
489
+ return a.y === b.y && a.m === b.m && a.d === b.d;
540
490
  }
541
491
  function locationTimezone(location, field) {
542
- const out = location.address_timezone.trim();
492
+ const out = location.timezone.trim();
543
493
  if (out === "") {
544
- throw errValidation({
545
- field,
546
- msg: msgTimezoneInvalid,
547
- });
494
+ throw errValidation({ field, msg: msgTimezoneInvalid });
548
495
  }
549
496
  return out;
550
497
  }
551
- function localDateFromLocation(location) {
552
- return {
553
- y: location.y,
554
- m: location.m,
555
- d: location.d,
556
- h: location.h,
557
- min: location.min,
558
- };
559
- }
560
498
  function localDateParts(now, timezone) {
561
- const time_zone = timezone.trim();
562
- if (time_zone === "") {
563
- return undefined;
564
- }
565
499
  let parts;
566
500
  try {
567
501
  parts = new Intl.DateTimeFormat("en-CA", {
568
- timeZone: time_zone,
502
+ timeZone: timezone,
569
503
  year: "numeric",
570
504
  month: "numeric",
571
505
  day: "numeric",
@@ -589,13 +523,7 @@ function localDateParts(now, timezone) {
589
523
  min === undefined) {
590
524
  return undefined;
591
525
  }
592
- return {
593
- y,
594
- m,
595
- d,
596
- h,
597
- min,
598
- };
526
+ return { y, m, d, h, min };
599
527
  }
600
528
  function compareLocalDate(a, b) {
601
529
  for (const [left, right] of [
@@ -625,13 +553,25 @@ function datePart(parts, type) {
625
553
  }
626
554
  return out;
627
555
  }
556
+ function locationAddressInput(location) {
557
+ return {
558
+ address_timezone: location.address_timezone,
559
+ lat: location.lat,
560
+ lon: location.lon,
561
+ street: location.street,
562
+ city: location.city,
563
+ state: location.state,
564
+ postal_code: location.postal_code,
565
+ country: location.country,
566
+ formatted_address: location.formatted_address,
567
+ place_name: location.place_name,
568
+ place_id: location.place_id,
569
+ };
570
+ }
628
571
  function requiredID(v, field, msg) {
629
572
  const out = resolvedID(v);
630
573
  if (out === undefined) {
631
- throw errRequired({
632
- field,
633
- msg,
634
- });
574
+ throw errRequired({ field, msg });
635
575
  }
636
576
  return out;
637
577
  }
@@ -639,8 +579,8 @@ function normalizeIDs(ids) {
639
579
  const seen = new Set();
640
580
  const out = [];
641
581
  for (const raw of ids) {
642
- const id = raw.trim();
643
- if (id === "" || seen.has(id)) {
582
+ const id = resolvedID(raw);
583
+ if (id === undefined || seen.has(id)) {
644
584
  continue;
645
585
  }
646
586
  seen.add(id);
@@ -4,6 +4,7 @@
4
4
  // not use this file except in compliance with the License. You may obtain
5
5
  // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6
6
  import { PunchModeDefault, PunchModeDelete, PunchModeReplace, PunchModeWeekSheet, PunchStatusPending, PunchStatusWorking, PunchTypeIn, PunchTypeOut, PunchTypeRideIn, PunchTypeRideOut, ZeroID, } from "@fabriktor/schema";
7
+ import { zeroDate } from "../core/date.js";
7
8
  import { errRequired, errResolveFailed, errValidation, } from "../core/err.js";
8
9
  const allWeekDays = [0, 1, 2, 3, 4, 5, 6];
9
10
  const minuteStep = 15;
@@ -361,17 +362,6 @@ function readyToPunchInControls() {
361
362
  can_ride_out: false,
362
363
  };
363
364
  }
364
- function zeroDate() {
365
- return {
366
- utc: "",
367
- y: 0,
368
- m: 0,
369
- d: 0,
370
- h: 0,
371
- min: 0,
372
- tz: "",
373
- };
374
- }
375
365
  function cloneDate(v) {
376
366
  return {
377
367
  utc: v.utc,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fabriktor/fx",
3
- "version": "0.0.75",
3
+ "version": "0.0.77",
4
4
  "description": "![Fabriktor Logo](./img/fabriktor-character.gif)",
5
5
  "type": "module",
6
6
  "exports": {
@@ -17,7 +17,7 @@
17
17
  "typescript": "^6.0.3"
18
18
  },
19
19
  "dependencies": {
20
- "@fabriktor/client": "0.0.67",
21
- "@fabriktor/schema": "0.0.49"
20
+ "@fabriktor/client": "0.0.68",
21
+ "@fabriktor/schema": "0.0.50"
22
22
  }
23
23
  }