mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-28 17:10:56 +00:00
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.
This commit is contained in:
@@ -7,7 +7,8 @@ import { Column, Entity, Index } from 'typeorm';
|
||||
@Index(['country'])
|
||||
@Index(['isActive'])
|
||||
export class Yard extends BaseEntity {
|
||||
@Column({ name: 'code', type: 'varchar', length: 20, unique: true })
|
||||
// 40 leaves room for the `@<epoch-ms>` suffix soft-delete appends to free the code.
|
||||
@Column({ name: 'code', type: 'varchar', length: 40, unique: true })
|
||||
code!: string;
|
||||
|
||||
@Column({ name: 'label', type: 'varchar', length: 100 })
|
||||
|
||||
@@ -31,7 +31,7 @@ export class YardsService {
|
||||
|
||||
/** Create a yard. */
|
||||
async create(dto: CreateYardDto): Promise<Yard> {
|
||||
const code = generateCode(dto.label);
|
||||
const code = generateCode(dto.label).slice(0, 40);
|
||||
const existing = await this.repository.findByCode(code);
|
||||
if (existing) throw new ConflictException(`Yard with label "${dto.label}" conflicts with existing code "${code}"`);
|
||||
|
||||
@@ -58,9 +58,19 @@ export class YardsService {
|
||||
return updated;
|
||||
}
|
||||
|
||||
/** Soft-delete a yard. */
|
||||
/**
|
||||
* Soft-delete a yard. The unique `code` (and the label) get a `@<epoch-ms>`
|
||||
* suffix first — e.g. SEBETA → SEBETA@1755612345678 — so a new yard with the
|
||||
* same name can be created later without tripping UQ_yards_code, which spans
|
||||
* soft-deleted rows too.
|
||||
*/
|
||||
async remove(id: string): Promise<void> {
|
||||
await this.findById(id);
|
||||
const yard = await this.findById(id);
|
||||
const suffix = `@${Date.now()}`;
|
||||
await this.repository.update(id, {
|
||||
code: `${yard.code.slice(0, 40 - suffix.length)}${suffix}`,
|
||||
label: `${yard.label.slice(0, 100 - suffix.length)}${suffix}`,
|
||||
});
|
||||
await this.repository.softDelete(id);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user