Project Initialization

This commit is contained in:
Muluhabt
2026-05-12 15:17:16 +03:00
parent 33fa742e8a
commit 3b8b6979db
259 changed files with 15962 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
import { BaseEntity } from '@edr/api-common';
import { Freight } from '@edr/types';
import { Column, Entity } from 'typeorm';
@Entity({ name: 'tracking_events' })
export class TrackingEvent extends BaseEntity {
@Column({ name: 'consignment_id', type: 'uuid' })
consignmentId!: string;
@Column({ name: 'location', type: 'varchar', length: 256 })
location!: string;
@Column({ name: 'status', type: 'enum', enum: Freight.ConsignmentStatus })
status!: Freight.ConsignmentStatus;
@Column({ name: 'occurred_at', type: 'timestamptz' })
occurredAt!: Date;
@Column({ name: 'description', type: 'text', nullable: true })
description?: string | null;
}

View File

@@ -0,0 +1,17 @@
import { Controller, Get, Param, ParseUUIDPipe } from '@nestjs/common';
import { ApiOperation, ApiTags } from '@nestjs/swagger';
import { TrackingService } from './tracking.service';
@ApiTags('tracking')
// @UseGuards(JwtAuthGuard) — TODO: integrate @edr/auth
@Controller('tracking')
export class TrackingController {
constructor(private readonly trackingService: TrackingService) {}
@Get(':consignmentId')
@ApiOperation({ summary: 'Get the tracking timeline for a consignment' })
findByConsignment(@Param('consignmentId', ParseUUIDPipe) consignmentId: string) {
return this.trackingService.findByConsignment(consignmentId);
}
}

View File

@@ -0,0 +1,14 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { TrackingEvent } from './entities/tracking-event.entity';
import { TrackingController } from './tracking.controller';
import { TrackingService } from './tracking.service';
@Module({
imports: [TypeOrmModule.forFeature([TrackingEvent])],
controllers: [TrackingController],
providers: [TrackingService],
exports: [TrackingService],
})
export class TrackingModule {}

View File

@@ -0,0 +1,27 @@
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { TrackingEvent } from './entities/tracking-event.entity';
@Injectable()
export class TrackingService {
constructor(
@InjectRepository(TrackingEvent)
private readonly trackingRepository: Repository<TrackingEvent>,
) {}
/** Get the full timeline of tracking events for a consignment. */
findByConsignment(consignmentId: string): Promise<TrackingEvent[]> {
return this.trackingRepository.find({
where: { consignmentId },
order: { occurredAt: 'ASC' },
});
}
/** Record a new tracking event for a consignment. */
record(event: Partial<TrackingEvent>): Promise<TrackingEvent> {
const entity = this.trackingRepository.create(event);
return this.trackingRepository.save(entity);
}
}