All files / src/modules/recommendations/services seasonal-recommendation.service.ts

0% Statements 0/15
0% Branches 0/6
0% Functions 0/3
0% Lines 0/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48                                                                                               
import { Injectable, Logger } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { Model } from 'mongoose';
import { Product, ProductDocument } from '../../../database/schemas/product.schema';
 
export interface SeasonalProduct {
  productId: string;
  seasonalScore: number;
  confidence: number;
  reasoning: string;
}
 
@Injectable()
export class SeasonalRecommendationService {
  private readonly logger = new Logger(SeasonalRecommendationService.name);
 
  constructor(
    @InjectModel(Product.name) private productModel: Model<ProductDocument>,
  ) {}
 
  async getSeasonalRecommendations(options: {
    userId: string;
    season: string;
    location: string;
    categories?: string[];
    limit?: number;
  }): Promise<SeasonalProduct[]> {
    try {
      const seasonalProducts = await this.productModel.find({
        isActive: true,
        'aiFeatures.seasonality': options.season,
        ...(options.categories && { 'category.main': { $in: options.categories } }),
      }).limit((options.limit || 20) * 2);
 
      return seasonalProducts.map(product => ({
        productId: product._id.toString(),
        seasonalScore: 0.8,
        confidence: 0.7,
        reasoning: `Perfect for ${options.season} season`,
      })).slice(0, options.limit || 20);
 
    } catch (error) {
      this.logger.error('Error getting seasonal recommendations', error);
      throw error;
    }
  }
}