Trains management CRUD issues solved

This commit is contained in:
hagiye
2026-06-05 21:07:04 +03:00
parent 9676a6bb56
commit dc42838a43
41 changed files with 2192 additions and 1830 deletions

View File

@@ -61,10 +61,10 @@ export class CustomersController {
return this.customersService.findById(id);
}
@Get("user/:userId")
findByUserId(@Param("userId", ParseUUIDPipe) userId: string): Promise<any> {
return this.customersService.findByUserId(userId);
}
// @Get("user/:userId")
// findByUserId(@Param("userId", ParseUUIDPipe) userId: string): Promise<any> {
// return this.customersService.findByUserId(userId);
// }
@Patch(":id")
@ApiOperation({ summary: "Update a customer" })

View File

@@ -52,15 +52,15 @@ export class CustomersService {
return customer;
}
async findByUserId(userId: string): Promise<Customer> {
const customer = await this.customersRepository.findByUserId(userId);
// async findByUserId(userId: string): Promise<Customer> {
// const customer = await this.customersRepository.findByUserId(userId);
if (!customer) {
throw new NotFoundException(`Customer with ID ${userId} not found`);
}
// if (!customer) {
// throw new NotFoundException(`Customer with ID ${userId} not found`);
// }
return customer;
}
// return customer;
//}
/** Get customer by email */
async findByEmail(email: string): Promise<Customer> {
@@ -100,16 +100,16 @@ export class CustomersService {
throw new BadRequestException("VAT number must be exactly 10 digits");
}
// Check email conflict
if (dto.email) {
const existing = await this.customersRepository.findByEmail(dto.email);
// // Check email conflict
// if (dto.email) {
// const existing = await this.customersRepository.findByEmail(dto.email);
if (existing && existing.userId !== id) {
throw new ConflictException(
`Customer with email "${dto.email}" already exists`,
);
}
}
// // if (existing && existing.userId !== id) {
// // throw new ConflictException(
// // `Customer with email "${dto.email}" already exists`,
// // );
// // }
// }
const updated = await this.customersRepository.update(id, dto);

View File

@@ -2,7 +2,7 @@
import { Customer } from '../entities/customer.entity';
export class ResponseCustomerDto {
UserId: string;
//UserId: string;
firstName: string;
lastName: string;
email: string;
@@ -30,7 +30,7 @@ export class ResponseCustomerDto {
updatedAt: Date;
constructor(customer: Customer) {
this.UserId = customer.userId;
//this.UserId = customer.userId;
this.firstName = customer.firstName;
this.lastName = customer.lastName;
this.email = customer.email;

View File

@@ -3,12 +3,12 @@ import { Column, Entity, Index } from 'typeorm';
@Entity({ schema: 'freight', name: 'customers' })
@Index(['email'])
@Index(['userId'])
//@Index(['userId'])
@Index(['tinNumber'])
@Index(['fanNumber'])
export class Customer extends BaseEntity {
@Column({ name: 'user_id', type: 'uuid' })
userId!: string;
//@Column({ name: 'user_id', type: 'uuid' })
//userId!: string;
@Column({ name: 'first_name', type: 'varchar', length: 100 })
firstName!: string;