mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-27 23:40:56 +00:00
Project Initialization
This commit is contained in:
@@ -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;
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
14
apps/edr-freight-api/src/modules/tracking/tracking.module.ts
Normal file
14
apps/edr-freight-api/src/modules/tracking/tracking.module.ts
Normal 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 {}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user