Add timeline tracking features with database schema updates
- Introduced new tables `timeline_footprints` and `timeline_activities` to manage employee location data and activity records. - Updated `company_settings` to include `gps_interval_seconds` and `checkout_warning_radius_meters` for enhanced tracking configuration. - Implemented foreign key constraints to ensure data integrity between new tables and existing `employees`, `customers`, and `visits` tables. - Created services and controllers for handling timeline activities and footprints, including ingestion and retrieval of data. - Enhanced DTOs and validation logic to support new fields and ensure correct data formats in API requests. - Added unit and integration tests to validate the new functionalities and ensure proper handling of timeline records. - Created migration scripts to apply the necessary database schema changes for the new features.
This commit is contained in:
@@ -23,6 +23,7 @@ import {
|
||||
type CheckInPayload,
|
||||
} from '../shared/check-in-verification';
|
||||
import { FIELD_VISIT_PRIVILEGE_KEY } from '../shared/field-purpose';
|
||||
import { TimelineActivitiesService } from '../timeline/timeline-activities.service';
|
||||
import type { Visit } from './visit';
|
||||
import type {
|
||||
ListVisitsQueryDto,
|
||||
@@ -40,6 +41,7 @@ export class VisitsService {
|
||||
private readonly customersService: CustomersService,
|
||||
private readonly employeesService: EmployeesService,
|
||||
private readonly companySettingsService: CompanySettingsService,
|
||||
private readonly timelineActivitiesService: TimelineActivitiesService,
|
||||
) {}
|
||||
|
||||
async list(query: ListVisitsQueryDto): Promise<PaginationResponse<VisitDto>> {
|
||||
@@ -131,6 +133,17 @@ export class VisitsService {
|
||||
checkInDistanceMeters: verified.distanceMeters,
|
||||
userId,
|
||||
});
|
||||
await this.timelineActivitiesService.recordIfLocated({
|
||||
employeeId: employee.id,
|
||||
type: 'customer_check_in',
|
||||
sourceType: 'visit',
|
||||
sourceId: created.id,
|
||||
latitude: verified.latitude,
|
||||
longitude: verified.longitude,
|
||||
recordedAt: now.value,
|
||||
customerId: dto.customerId,
|
||||
visitId: created.id,
|
||||
});
|
||||
return this.toItem(created);
|
||||
}
|
||||
|
||||
@@ -175,6 +188,17 @@ export class VisitsService {
|
||||
checkOutDistanceMeters: verified.distanceMeters,
|
||||
userId,
|
||||
});
|
||||
await this.timelineActivitiesService.recordIfLocated({
|
||||
employeeId: employee.id,
|
||||
type: 'customer_check_out',
|
||||
sourceType: 'visit',
|
||||
sourceId: updated.id,
|
||||
latitude: verified.latitude,
|
||||
longitude: verified.longitude,
|
||||
recordedAt: updated.checkOutAt?.value,
|
||||
customerId: visit.customerId,
|
||||
visitId: updated.id,
|
||||
});
|
||||
return this.toItem(updated);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user