File size: 4,343 Bytes
c01955c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import Interview from "../models/interviews.models.js";
import Performance from "../models/performance.models.js";
import { expressRepre } from "@vashuthegreat/vexpress";
import ApiError from "../utils/ApiError.js";
import asyncHandler from "../utils/asyncHandler.js";
import ApiResponse from "../utils/ApiResponse.js";
import mongoose from "mongoose";
import logger from "../logger/create.logger.js";

export const createPerformance = expressRepre(
  {
    summary: "create interview performance",
    body: {
      interview_id: "69671fa2d697bab6f0176ccc",
      overallScore: 7.5,
      verdict: "maybe",
      summaryFeedback: "Strong fundamentals but needs improvement in DSA",
      skills: {
        technical: { score: 8, feedback: "Good ML basics" },
        dsa: { score: 6, feedback: "Needs more practice" },
        problemSolving: { score: 7, feedback: "Decent approach" },
        communication: { score: 7, feedback: "Clear but hesitant" },
        systemDesign: { score: 5, feedback: "Basic understanding" },
        projects: { score: 8, feedback: "Projects well explained" },
        behaviour: { score: 8, feedback: "Positive attitude" }
      },
      strengths: ["ML basics", "Project explanation"],
      weaknesses: ["DSA", "System design"],
      practiceRecommendations: ["Solve DSA daily", "Mock interviews"],
      studyRecommendations: ["Arrays", "Linked Lists"],
      lowPriorityOrAvoid: ["Advanced ML math"]
    },
    response: "performance created"
  },
  asyncHandler(async (req, res) => {
    const user_id = req.user?._id;

    const {
      interview_id,
      overallScore,
      verdict,
      summaryFeedback,
      skills,
      strengths,
      weaknesses,
      practiceRecommendations,
      studyRecommendations,
      lowPriorityOrAvoid,
      confidenceLevel
    } = req.body;

    if (!interview_id || !overallScore || !verdict || !summaryFeedback) {
      throw new ApiError(400, "Required fields are missing");
    }

    logger.info(`Creating performance for interview: ${interview_id}`);

    if (!mongoose.Types.ObjectId.isValid(interview_id)) {
      throw new ApiError(400, "Invalid interview_id format");
    }

    const interview = await Interview.findById(interview_id);
    if (!interview) {
      throw new ApiError(404, "Interview not found");
    }

    const existingPerformance = await Performance.findOne({ interview_id });
    if (existingPerformance) {
      logger.info(`Performance already exists for interview: ${interview_id}`);
      return res
        .status(200)
        .json(
          new ApiResponse(
            200,
            existingPerformance,
            "Performance already exists"
          )
        );
    }

    const performance = await Performance.create({
      interview_id,
      user_id,
      overallScore,
      verdict,
      summaryFeedback,
      skills,
      strengths,
      weaknesses,
      practiceRecommendations,
      studyRecommendations,
      lowPriorityOrAvoid,
      confidenceLevel
    });

    if (!performance) {
      throw new ApiError(500, "Failed to create performance");
    }

    logger.info(`Performance created successfully: ${performance._id}`);
    res
      .status(201)
      .json(
        new ApiResponse(
          201,
          performance,
          "Performance created successfully"
        )
      );
  })
);





export const getInterviewPerformance = expressRepre(
  {
    summary: "get User Performance",
    body:{
      interview_id:"696f48d0aa5b7622c0b98b76"
    },
   
    response: "performance fetched"
  },
  asyncHandler(async (req, res) => {

    const interview_id=req.body?.interview_id

    if (!interview_id) {
      throw new ApiError(400, "Required fields are missing");
    }

    logger.info(`Fetching performance for interview: ${interview_id}`);

   

    const interview = await Interview.findById(interview_id);
    if (!interview) {
      throw new ApiError(404, "Interview not found");
    }

    const existingPerformance = await Performance.findOne({ interview_id });
    if (!existingPerformance) {
        throw new ApiError(404, "interview performance not found");
    }
      return res
        .status(200)
        .json(
          new ApiResponse(
            200,
            existingPerformance,
            "Performance fetched"
          )
        );


  })
);