PSA/shared/workflow/streams/domainEventBuilders/scheduleBlockEventBuilders.ts
Hermes 284313f908
Some checks are pending
Bidi Control Character Guard / bidi-control-guard (push) Waiting to run
Circular Dependency Check / Check for new circular dependencies (push) Waiting to run
Citus Migration Smoke / Combined migrations on single-node Citus (push) Waiting to run
E2E Fresh Install Tests / fresh-install-e2e (push) Waiting to run
ext-v2 guardrails / Run ext-v2 guard and ESLint (push) Waiting to run
Integration Tests / Check for relevant changes (push) Waiting to run
Integration Tests / ${{ (github.event_name == 'schedule' || github.event.inputs.suite == 'full') && 'Full integration suite' || 'Tier-1 integration subset' }} (push) Blocked by required conditions
Mobile checks / Mobile lint + typecheck (push) Waiting to run
Mobile checks / Mobile unit tests (push) Waiting to run
Mobile checks / Mobile dependency audit (report) (push) Waiting to run
Mobile checks / Mobile reproducibility checks (push) Waiting to run
Secrets guard (env backups) / Ensure no tracked env backup files (push) Waiting to run
Temporal Readiness / fast-readiness (push) Waiting to run
Temporal Readiness / docker-parity (push) Waiting to run
TypeScript Type Check / Nx affected typecheck (push) Waiting to run
Unit Tests / Skipped-test budget (push) Waiting to run
Unit Tests / Nx affected unit tests (push) Waiting to run
Unit Tests / Server unit coverage (informational) (push) Waiting to run
Validate Tenant Management Schema / Check for relevant changes (push) Waiting to run
Validate Tenant Management Schema / Validate Tenant Management Schema (push) Blocked by required conditions
EE Workflows Build Guard / ee-workflows-build-guard (push) Waiting to run
Initial import of AlgaPSA codebase from PSA server
Excluded: .git, node_modules, secrets/, compose.env, assemblyscript tgz

Source: /opt/alga-psa on psa.joliet.tech
2026-06-22 16:12:17 -05:00

74 lines
2.4 KiB
TypeScript

type ScheduleEntryLike = {
entry_id: string;
work_item_type?: string | null;
work_item_id?: string | null;
is_private?: boolean | null;
scheduled_start?: Date | string | null;
scheduled_end?: Date | string | null;
assigned_user_ids?: string[] | null;
created_at?: Date | string | null;
title?: string | null;
notes?: string | null;
};
function toIsoString(value: Date | string | null | undefined): string | undefined {
if (!value) return undefined;
const date = value instanceof Date ? value : new Date(value);
if (Number.isNaN(date.getTime())) return undefined;
return date.toISOString();
}
export function isScheduleBlockEntry(entry: ScheduleEntryLike): boolean {
return (
entry.is_private === true &&
entry.work_item_type === 'ad_hoc' &&
!entry.work_item_id &&
(entry.assigned_user_ids ?? []).length === 1
);
}
export function getScheduleBlockOwnerUserId(entry: ScheduleEntryLike): string | undefined {
const ids = entry.assigned_user_ids ?? [];
if (ids.length !== 1) return undefined;
return ids[0];
}
export function buildScheduleBlockCreatedPayload(params: {
entry: ScheduleEntryLike;
timezone: string;
reason?: string;
}): Record<string, unknown> {
const startAt = toIsoString(params.entry.scheduled_start);
const endAt = toIsoString(params.entry.scheduled_end);
if (!startAt || !endAt) throw new Error('Schedule block entry is missing scheduled_start/scheduled_end');
const ownerId = getScheduleBlockOwnerUserId(params.entry);
if (!ownerId) throw new Error('Schedule block entry must have exactly one assigned user id');
const title = String(params.entry.title ?? '').trim();
const notes = String(params.entry.notes ?? '').trim();
const inferredReason = title && title.toLowerCase() !== 'busy' ? title : notes || undefined;
return {
scheduleBlockId: params.entry.entry_id,
ownerId,
ownerType: 'user',
startAt,
endAt,
timezone: params.timezone,
...(toIsoString(params.entry.created_at) ? { createdAt: toIsoString(params.entry.created_at) } : {}),
...(params.reason ? { reason: params.reason } : inferredReason ? { reason: inferredReason } : {}),
};
}
export function buildScheduleBlockDeletedPayload(params: {
scheduleBlockId: string;
reason?: string;
}): Record<string, unknown> {
return {
scheduleBlockId: params.scheduleBlockId,
deletedAt: new Date().toISOString(),
...(params.reason ? { reason: params.reason } : {}),
};
}