import { Job } from 'bullmq';
import { Logger } from '@nestjs/common';

import { ObjectType } from '@nice/common';

import { QueueJobType } from '../types';
import { updatePostViewCount } from '../models/post/utils';
const logger = new Logger('QueueWorker');
export default async function processJob(job: Job<any, any, QueueJobType>) {
  try {
    if (job.name === QueueJobType.UPDATE_POST_VISIT_COUNT) {
      await updatePostViewCount(job.data.id, job.data.type);
    }
    if (job.name === QueueJobType.UPDATE_POST_STATE) {
      await updatePostViewCount(job.data.id, job.data.type);
    }
  } catch (error: any) {
    logger.error(
      `Error processing stats update job: ${error.message}`,
      error.stack,
    );
  }
}
