Files
edr-platform/apps/edr-freight-api/src/seed/dropdown-settings.seeder.ts
Marshal 771aa2a605 Add train deactivation feature and import train number management
- Introduced DEACTIVATED status for trains, allowing staff to park trains indefinitely.
- Implemented methods to deactivate and reactivate trains in the TrainBuilderService.
- Added UI components for train deactivation and reactivation in TrainBuilderDetailPage.
- Created a dropdown setting for admin-managed import train numbers, with corresponding migrations.
- Updated yard code length to accommodate soft-delete suffix.
- Enhanced train status handling to include DEACTIVATED state.
2026-07-20 07:04:23 +00:00

98 lines
3.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { Injectable, Logger } from "@nestjs/common";
import { DataSource } from "typeorm";
import {
DropdownSetting,
DropdownSettingMeta,
} from "../modules/dropdown-settings/entities/dropdown-setting.entity";
interface DefaultDropdownSetting {
code: string;
label: string;
description: string;
multiple: boolean;
meta?: DropdownSettingMeta | null;
}
/**
* Known dropdown settings, seeded as empty catalogs (no options). The options
* are managed by the admin from the backoffice Dropdown Settings editor.
*/
const DEFAULT_DROPDOWN_SETTINGS: DefaultDropdownSetting[] = [
{
code: "stations_ter",
label: "Stations TER",
description:
"Temporary freight station list used by booking origin and destination yards.",
multiple: false,
meta: { searchable: true, clearable: true, version: "temporary" },
},
{
code: "general_contract_period",
label: "General Contract Period (months)",
description:
"How many months a general contract stays open for ordering after activation.",
multiple: false,
},
{
code: "contract_validity_periods",
label: "Contract Validity Periods (days)",
description:
"Validity durations (in days) a staff can choose when accepting a submitted contract.",
multiple: false,
},
{
code: "ro_vessel_min_days",
label: "RO vessel minimum lead time (days)",
description:
"Minimum days between today and the vessel departure date on an export Release Order.",
multiple: false,
},
{
code: "import_train_numbers",
label: "Import train numbers",
description:
"Even IMPORT run numbers (Djibouti → Ethiopia) selectable when building a train. The paired export number is derived automatically (import 1).",
multiple: false,
meta: { searchable: true, clearable: true },
},
];
@Injectable()
export class DropdownSettingsSeeder {
private readonly logger = new Logger(DropdownSettingsSeeder.name);
constructor(private readonly dataSource: DataSource) {}
async run() {
const settingRepository = this.dataSource.getRepository(DropdownSetting);
// Seed only into an empty table: any existing rows (including
// soft-deleted ones, which would still conflict on the unique `code`)
// mean the data is admin-managed, so leave it untouched.
const existing = await settingRepository.count({ withDeleted: true });
if (existing > 0) {
this.logger.log(
`dropdown_settings already has ${existing} rows — skipping seed`,
);
return;
}
// Insert setting rows only — no DropdownOption rows. Options start empty
// and are configured by the admin from the backoffice editor.
await settingRepository.insert(
DEFAULT_DROPDOWN_SETTINGS.map((setting) => ({
code: setting.code,
label: setting.label,
description: setting.description,
multiple: setting.multiple,
meta: setting.meta ?? null,
})),
);
this.logger.log(
`Seeded ${DEFAULT_DROPDOWN_SETTINGS.length} dropdown settings with empty options`,
);
}
}