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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | import { Injectable, Logger } from '@nestjs/common'; import { InjectModel } from '@nestjs/mongoose'; import { Model } from 'mongoose'; import { SocialActivity, SocialActivityDocument } from '../../../database/schemas/social-activity.schema'; @Injectable() export class ActivityService { private readonly logger = new Logger(ActivityService.name); constructor( @InjectModel(SocialActivity.name) private activityModel: Model<SocialActivityDocument>, ) {} async createActivity(data: { userId: string; activityType: string; targetType?: string; targetId?: string; title: string; description?: string; metadata?: any; visibility?: string; }): Promise<SocialActivityDocument> { try { const activity = new this.activityModel({ userId: data.userId, activityType: data.activityType, targetType: data.targetType, targetId: data.targetId, title: data.title, description: data.description, metadata: data.metadata || {}, visibility: data.visibility || 'friends', reactions: [], comments: [], engagement: { views: 0, shares: 0, clicks: 0, engagementRate: 0, reach: 0, }, shares: [], flags: { trending: false, featured: false, pinned: false, archived: false, }, priority: 0, isActive: true, createdAt: new Date(), updatedAt: new Date(), }); await activity.save(); this.logger.log(`Activity created: ${activity._id} by user ${data.userId}`); return activity; } catch (error) { this.logger.error(`Error creating activity for user ${data.userId}`, error); throw error; } } } |