Expose order route stages
Build and deploy Docker image / build (push) Successful in 2m37s

This commit is contained in:
Ruslan Bakiev
2026-06-08 06:41:51 +07:00
parent c198b6c566
commit 7abba6296b
+42 -1
View File
@@ -527,6 +527,9 @@ function mapQuotation(item: QuotationWithRelations) {
} }
function mapLocalOrder(item: OrderWithRelations) { function mapLocalOrder(item: OrderWithRelations) {
const progress = orderLocationProgress(item.status)
const locationLatitude = interpolateCoordinate(item.sourceLatitude, item.destinationLatitude, progress)
const locationLongitude = interpolateCoordinate(item.sourceLongitude, item.destinationLongitude, progress)
return { return {
uuid: item.uuid, uuid: item.uuid,
quotationUuid: item.quotation?.uuid ?? null, quotationUuid: item.quotation?.uuid ?? null,
@@ -549,10 +552,48 @@ function mapLocalOrder(item: OrderWithRelations) {
updatedAt: item.updatedAt.toISOString(), updatedAt: item.updatedAt.toISOString(),
notes: item.notes ?? '', notes: item.notes ?? '',
orderLines: [], orderLines: [],
stages: [], stages: [
{
uuid: `${item.uuid}-route`,
name: item.name,
sequence: 1,
stageType: 'route',
transportType: item.quotation?.transportTypeCode ?? null,
sourceLocationName: item.sourceLocationName,
sourceLatitude: item.sourceLatitude,
sourceLongitude: item.sourceLongitude,
destinationLocationName: item.destinationLocationName,
destinationLatitude: item.destinationLatitude,
destinationLongitude: item.destinationLongitude,
locationName: orderLocationName(item, progress),
locationLatitude,
locationLongitude,
selectedCompany: null,
trips: [],
},
],
} }
} }
function orderLocationProgress(status: string | null): number {
const normalized = (status ?? '').toLowerCase().replaceAll('-', '_').trim()
if (normalized === 'delivered' || normalized === 'completed' || normalized === 'done') return 1
if (normalized === 'in_transit' || normalized === 'active') return 0.55
if (normalized === 'processing' || normalized === 'accepted') return 0.25
return 0.05
}
function interpolateCoordinate(start: number | null, end: number | null, progress: number): number | null {
if (start === null || end === null) return start ?? end
return start + (end - start) * progress
}
function orderLocationName(item: OrderWithRelations, progress: number): string | null {
if (progress >= 1) return item.destinationLocationName ?? 'Груз доставлен'
if (progress <= 0.05) return item.sourceLocationName ?? 'Груз принят'
return 'Груз в пути'
}
function requiredString(value: unknown, label: string): string { function requiredString(value: unknown, label: string): string {
const next = normalizeString(value) const next = normalizeString(value)
if (!next) { if (!next) {