Enhance DTOs and services to support sequence and operational status for coaches and stations

This commit is contained in:
Stephanos A
2026-06-16 16:25:33 +03:00
parent a61130cd51
commit 421e30dc6c
7 changed files with 85 additions and 20 deletions

View File

@@ -1,4 +1,4 @@
import { IsString, IsNumber, IsOptional } from 'class-validator';
import { IsString, IsNumber, IsOptional, IsInt, IsBoolean } from 'class-validator';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
export class CreateStationDto {
@@ -6,6 +6,9 @@ export class CreateStationDto {
@ApiProperty({ example: 'Addis Ababa' }) @IsString() name: string;
@ApiProperty({ example: 'Addis Ababa' }) @IsString() city: string;
@ApiPropertyOptional() @IsOptional() @IsString() timezone?: string;
@ApiPropertyOptional() @IsOptional() @IsString() countryCode?: string;
@ApiProperty({ example: 9.0054 }) @IsNumber() lat: number;
@ApiProperty({ example: 38.7636 }) @IsNumber() lng: number;
@ApiPropertyOptional({ example: 1 }) @IsOptional() @IsInt() sequence?: number;
@ApiPropertyOptional({ example: true }) @IsOptional() @IsBoolean() isOperational?: boolean;
}

View File

@@ -1,4 +1,4 @@
import { Injectable, NotFoundException, Inject, Optional } from '@nestjs/common';
import { Injectable, NotFoundException, Inject, Optional, BadRequestException } from '@nestjs/common';
import { REQUEST } from '@nestjs/core';
import { PrismaService } from '../../common/prisma.service';
import { AuditService } from '../../common/audit.service';
@@ -65,9 +65,15 @@ export class StationsService {
async update(id: string, dto: Partial<CreateStationDto>) {
const oldStation = await this.findOne(id);
const { code, name, city, timezone, lat, lng } = dto;
const data: any = { code, name, city, timezone, lat, lng };
if ('countryCode' in dto) data.countryCode = (dto as any).countryCode;
if ('sequence' in dto) data.sequence = (dto as any).sequence;
if ('isOperational' in dto) data.isOperational = (dto as any).isOperational;
const updatedStation = await this.prisma.station.update({
where: { id },
data: dto,
data,
});
await this.auditService.log({