⚠️ This is a backend issue — work is done inside the backend/ folder
Description
The weight-tracking module has an entity (backend/src/weight-tracking/entities/weight-entry.entity.ts), a controller (weight-tracking.controller.ts), and a module file, but weight-tracking.service.ts does not exist. The controller has no service to delegate to, making all weight tracking endpoints non-functional.
Current State
backend/src/weight-tracking/entities/weight-entry.entity.ts — entity exists
backend/src/weight-tracking/weight-tracking.controller.ts — controller exists
backend/src/weight-tracking/weight-tracking.module.ts — module exists
backend/src/weight-tracking/weight-tracking.service.ts — missing
What Needs to Be Built
1. WeightTrackingService (weight-tracking.service.ts)
@Injectable()
export class WeightTrackingService {
async addEntry(petId: string, dto: CreateWeightEntryDto): Promise<WeightEntry>
async getHistory(petId: string, limit?: number): Promise<WeightEntry[]>
async getLatest(petId: string): Promise<WeightEntry | null>
async getTrend(petId: string): Promise<{ trend: 'gaining' | 'losing' | 'stable'; changeKg: number; periodDays: number }>
async deleteEntry(id: string): Promise<void>
}
2. Trend Calculation Logic
- Compare the last 2 entries to determine direction
- Calculate
changeKg and periodDays between entries
- Return
stable if change is < 0.1 kg
3. Alert Integration
- If weight change exceeds a configurable threshold (e.g. >10% in 30 days), emit a notification via
NotificationsService
4. Unit Tests (weight-tracking.spec.ts)
- Test trend calculation for gaining, losing, and stable cases
- Test alert threshold logic
Acceptance Criteria
Files to Create / Modify
backend/src/weight-tracking/weight-tracking.service.ts (new)
backend/src/weight-tracking/weight-tracking.module.ts (modify — register service)
backend/src/weight-tracking/weight-tracking.spec.ts (modify — add service tests)
Priority
Medium — module is wired but completely non-functional without the service
Estimated Effort
1–2 days
backend/folderDescription
The
weight-trackingmodule has an entity (backend/src/weight-tracking/entities/weight-entry.entity.ts), a controller (weight-tracking.controller.ts), and a module file, butweight-tracking.service.tsdoes not exist. The controller has no service to delegate to, making all weight tracking endpoints non-functional.Current State
backend/src/weight-tracking/entities/weight-entry.entity.ts— entity existsbackend/src/weight-tracking/weight-tracking.controller.ts— controller existsbackend/src/weight-tracking/weight-tracking.module.ts— module existsbackend/src/weight-tracking/weight-tracking.service.ts— missingWhat Needs to Be Built
1. WeightTrackingService (
weight-tracking.service.ts)2. Trend Calculation Logic
changeKgandperiodDaysbetween entriesstableif change is < 0.1 kg3. Alert Integration
NotificationsService4. Unit Tests (
weight-tracking.spec.ts)Acceptance Criteria
GET /weight-tracking/:petId/trendreturns trend direction, change, and periodWeightTrackingModuleFiles to Create / Modify
backend/src/weight-tracking/weight-tracking.service.ts(new)backend/src/weight-tracking/weight-tracking.module.ts(modify — register service)backend/src/weight-tracking/weight-tracking.spec.ts(modify — add service tests)Priority
Medium — module is wired but completely non-functional without the service
Estimated Effort
1–2 days