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,23 @@
import { IsNumber, IsOptional, IsString } from 'class-validator';
export class CreateStationDto {
@IsString()
code!: string;
@IsString()
name!: string;
@IsString()
city!: string;
@IsString()
country!: string;
@IsOptional()
@IsNumber()
latitude?: number;
@IsOptional()
@IsNumber()
longitude?: number;
}

View File

@@ -0,0 +1,23 @@
import { BaseEntity } from '@edr/api-common';
import { Column, Entity } from 'typeorm';
@Entity({ name: 'stations' })
export class Station extends BaseEntity {
@Column({ name: 'code', type: 'varchar', length: 16, unique: true })
code!: string;
@Column({ name: 'name', type: 'varchar', length: 128 })
name!: string;
@Column({ name: 'city', type: 'varchar', length: 128 })
city!: string;
@Column({ name: 'country', type: 'varchar', length: 64 })
country!: string;
@Column({ name: 'latitude', type: 'numeric', precision: 9, scale: 6, nullable: true })
latitude?: number | null;
@Column({ name: 'longitude', type: 'numeric', precision: 9, scale: 6, nullable: true })
longitude?: number | null;
}

View File

@@ -0,0 +1,30 @@
import { Body, Controller, Get, Param, ParseUUIDPipe, Post } from '@nestjs/common';
import { ApiOperation, ApiTags } from '@nestjs/swagger';
import { CreateStationDto } from './dto/create-station.dto';
import { StationsService } from './stations.service';
@ApiTags('stations')
// @UseGuards(JwtAuthGuard) — TODO: integrate @edr/auth
@Controller('stations')
export class StationsController {
constructor(private readonly stationsService: StationsService) {}
@Post()
@ApiOperation({ summary: 'Register a new station' })
create(@Body() dto: CreateStationDto) {
return this.stationsService.create(dto);
}
@Get()
@ApiOperation({ summary: 'List all stations' })
findAll() {
return this.stationsService.findAll();
}
@Get(':id')
@ApiOperation({ summary: 'Get a station by ID' })
findOne(@Param('id', ParseUUIDPipe) id: string) {
return this.stationsService.findById(id);
}
}

View File

@@ -0,0 +1,14 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { Station } from './entities/station.entity';
import { StationsController } from './stations.controller';
import { StationsService } from './stations.service';
@Module({
imports: [TypeOrmModule.forFeature([Station])],
controllers: [StationsController],
providers: [StationsService],
exports: [StationsService],
})
export class StationsModule {}

View File

@@ -0,0 +1,34 @@
import { Injectable, NotFoundException } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { CreateStationDto } from './dto/create-station.dto';
import { Station } from './entities/station.entity';
@Injectable()
export class StationsService {
constructor(
@InjectRepository(Station)
private readonly stationsRepository: Repository<Station>,
) {}
/** Register a new station. */
create(dto: CreateStationDto): Promise<Station> {
const entity = this.stationsRepository.create(dto);
return this.stationsRepository.save(entity);
}
/** List every station (alphabetical). */
findAll(): Promise<Station[]> {
return this.stationsRepository.find({ order: { name: 'ASC' } });
}
/** Get a single station by ID. */
async findById(id: string): Promise<Station> {
const station = await this.stationsRepository.findOne({ where: { id } });
if (!station) {
throw new NotFoundException(`Station ${id} not found`);
}
return station;
}
}