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,41 @@
import { Injectable, NotFoundException } from '@nestjs/common';
import { ConsignmentsRepository } from './consignments.repository';
import { CreateConsignmentDto } from './dto/create-consignment.dto';
import { FilterConsignmentDto } from './dto/filter-consignment.dto';
import { Consignment } from './entities/consignment.entity';
@Injectable()
export class ConsignmentsService {
constructor(private readonly consignmentsRepository: ConsignmentsRepository) {}
/** Create a new consignment for a freight booking. */
create(dto: CreateConsignmentDto): Promise<Consignment> {
return this.consignmentsRepository.create(dto);
}
/** Return a paginated list of consignments. */
async findAll(filter: FilterConsignmentDto): Promise<{ items: Consignment[]; total: number }> {
const page = filter.page ?? 1;
const pageSize = filter.pageSize ?? 20;
const [items, total] = await this.consignmentsRepository.findAndCount({
where: {
...(filter.status ? { status: filter.status } : {}),
...(filter.bookingId ? { bookingId: filter.bookingId } : {}),
},
skip: (page - 1) * pageSize,
take: pageSize,
order: { createdAt: 'DESC' },
});
return { items, total };
}
/** Get a single consignment by ID. */
async findById(id: string): Promise<Consignment> {
const consignment = await this.consignmentsRepository.findById(id);
if (!consignment) {
throw new NotFoundException(`Consignment ${id} not found`);
}
return consignment;
}
}