This commit is contained in:
Marshal
2026-07-14 11:06:49 +00:00
parent 957a185a4d
commit 6d0cf50b4d
64 changed files with 4896 additions and 404 deletions

View File

@@ -15,7 +15,7 @@ export class CargoTypesRepository implements ICargoTypesRepository {
}
findById(id: string): Promise<CargoType | null> {
return this.repo.findOne({ where: { id }, relations: { parent: true } });
return this.repo.findOne({ where: { id }, relations: { parent: true, wagonTypes: true } });
}
findByCode(code: string): Promise<CargoType | null> {
@@ -35,6 +35,7 @@ export class CargoTypesRepository implements ICargoTypesRepository {
const qb = this.repo
.createQueryBuilder('cargoType')
.leftJoinAndSelect('cargoType.parent', 'parent')
.leftJoinAndSelect('cargoType.wagonTypes', 'wagonType')
.orderBy(`cargoType.${query.sortBy ?? 'displayOrder'}`, query.sortOrder ?? 'ASC');
if (query.isActive !== undefined) {
@@ -63,7 +64,18 @@ export class CargoTypesRepository implements ICargoTypesRepository {
}
async update(id: string, data: Partial<CargoType>): Promise<CargoType | null> {
await this.repo.update(id, data as never);
// Relation lists can't ride a column UPDATE — sync them via entity save.
const { wagonTypes, ...columns } = data;
if (Object.keys(columns).length) {
await this.repo.update(id, columns as never);
}
if (wagonTypes) {
const entity = await this.repo.findOne({ where: { id } });
if (entity) {
entity.wagonTypes = wagonTypes;
await this.repo.save(entity);
}
}
return this.findById(id);
}

View File

@@ -15,7 +15,7 @@ export class ContainerTypesRepository implements IContainerTypesRepository {
}
findById(id: string): Promise<ContainerType | null> {
return this.repo.findOne({ where: { id } });
return this.repo.findOne({ where: { id }, relations: { wagonTypes: true } });
}
findByCode(code: string): Promise<ContainerType | null> {
@@ -34,6 +34,7 @@ export class ContainerTypesRepository implements IContainerTypesRepository {
findPaged(query: ListContainerTypesQueryDto): Promise<PaginatedResponse<ContainerType>> {
const qb = this.repo
.createQueryBuilder('containerType')
.leftJoinAndSelect('containerType.wagonTypes', 'wagonType')
.orderBy(`containerType.${query.sortBy ?? 'displayOrder'}`, query.sortOrder ?? 'ASC');
if (query.isActive !== undefined) {
@@ -54,7 +55,18 @@ export class ContainerTypesRepository implements IContainerTypesRepository {
}
async update(id: string, data: Partial<ContainerType>): Promise<ContainerType | null> {
await this.repo.update(id, data as never);
// Relation lists can't ride a column UPDATE — sync them via entity save.
const { wagonTypes, ...columns } = data;
if (Object.keys(columns).length) {
await this.repo.update(id, columns as never);
}
if (wagonTypes) {
const entity = await this.repo.findOne({ where: { id } });
if (entity) {
entity.wagonTypes = wagonTypes;
await this.repo.save(entity);
}
}
return this.findById(id);
}