0

I want to save the interview array object. I want when scheduled round 1 occurs and their feedback too based on round 1, want to save round 1 data with feedback and round 2 data with feedback, and so on

interview array has two objects

  1. schedule (for scheduling the number of rounds)
  2. feedback (for getting the feedback of every rounds occur)

Here is my Mongoose Schema

const mongoose = require('mongoose');
const mongoosePaginate = require('mongoose-paginate-v2');
const { Schema } = mongoose;

const InterviewSchema = new Schema(
  {
    firstName: {
      type: String,
      required: true,
      trim: true,
      maxlength: 30,
    },
    lastName: {
      type: String,
      trim: true,
      maxlength: 30,
    },
    email: {
      type: String,
      required: true,
      trim: true,
    },
    gender: {
      type: String,
      required: true,
    },
    contactNumber: {
      type: Number,
      required: true,
    },
    profile: {
      type: String,
      required: true,
    },
    status: {
      type: String,
    },

  **// Interview Array Objects, Need to update and save**

    interview: [
      {
        schedule: {
          interviewerName: {
            type: String,
            trim: true,
          },
          date: {
            type: Date,
            default: Date.now,
          },
          mode: {
            type: String,
          },
          meeting: {
            link: {
              type: String,
              trim: true,
            },
            platform: {
              type: String,
              trim: true,
            },
          },
          round: {
            count: {
              type: Number,
              default: 1,
            },
            type: {
              type: String,
              default: 'hr',
            },
          },
        },

        feedback: {
          technical: {
            type: Number,
            required: true,
            min: 1,
            max: 5,
          },
          logical: {
            type: Number,
            required: true,
            min: 1,
            max: 5,
          },
          communication: {
            type: Number,
            required: true,
            min: 1,
            max: 5,
          },
          comment: {
            type: String,
            min: 10,
            max: 200,
            default: '',
          },

          interviewStatus: {
            type: String,
          },
          recommendation: {
            type: String,
            default: '',
          },**
        },
      },
    ],


  },
  {
    timestamps: true,
  },
);

InterviewSchema.plugin(mongoosePaginate);
const InterviewProcess = mongoose.model('interviewprocess', InterviewSchema);
module.exports = InterviewProcess;

I have done the update part i.e in the array object schedule round is updated with feedback but I am unable to save the data, it just overrides the previous schedule.

Here is code what I have done:

static async updateSchedule(request, h) {
    try {
      const payload = request.payload.interview[0];
      const params = request.query._id;
      const interviewSchedule =
        await interviewProcessService.findByinterviewProcessId(params);
      if (!interviewSchedule) {
        return h.response({
          statusCode: MESSAGE.STATUS.ERROR,
          message: MESSAGE.ID_NOT_EXIST,
        });
      }

      let mode,
        meeting,
        round,
        technical,
        logical,
        communication,
        comment,
        interviewStatus,
        recommendation,
        interviewerName;
      if (payload.schedule) {
        interviewerName = _.get(payload.schedule, 'interviewerName');
        mode = _.get(payload.schedule, 'mode');
        meeting = _.get(payload.schedule, 'meeting');
        round = _.get(payload.schedule, 'round') || {};
      }

      if (payload.feedback) {
        mode = _.get(interviewSchedule.interview[0].schedule, 'mode');
        meeting = _.get(interviewSchedule.interview[0].schedule, 'meeting');
        round = _.get(interviewSchedule.interview[0].schedule, 'round') || {};
        interviewerName = _.get(
          interviewSchedule.interview[0].schedule,
          'interviewerName',
        );

        technical = _.get(payload.feedback, 'technical');
        logical = _.get(payload.feedback, 'logical');
        communication = _.get(payload.feedback, 'communication');
        comment = _.get(payload.feedback, 'comment');
        interviewStatus = _.get(payload.feedback, 'interviewStatus');
        recommendation = _.get(payload.feedback, 'recommendation');
      }

      const result = await interviewProcessService.update(params, {
        interview: {
          schedule: {
            interviewerName,
            mode,
            meeting,
            round,
          },
          feedback: {
            technical,
            logical,
            communication,
            comment,
            interviewStatus,
            recommendation,
          },
        },
      });

      return h.response({
        result,
        statusCode: MESSAGE.STATUS.SUCCESS,
        message: MESSAGE.ROUTES.SCHEDULE_UPDATE.MESSAGE,
      });
    } catch (error) {
      return ErrorHandler.error(error);
    }
  }

Want to Achieve: whenever the GET method is applied, I want to receive no. of rounds with feedback.

RK Varun
  • 61
  • 5
  • You need to insert a new `interview` object in the array of the `InterviewProcess` with `_id = request.query._id`. Correct? – lpizzinidev Jan 05 '23 at 07:27
  • @lpizzinidev Yes, But I am unable to do this. every time when the schedule or feedback is updated its generated a new id. and I am unable to reach that. I am trying to access it like this. **payload = request. payload.interview._id;** – RK Varun Jan 06 '23 at 12:48

1 Answers1

0

var update = {name: 'updated item2', value: 'two updated'}; Person. update({'items.id': 2}, {'$set': {'items. $': update}}, function(err) { ... Problem with this approach is that it updates/sets the entire object, therefore in this case I lose the id field.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 05 '23 at 13:46
  • @Alisha_Vashists I didn't get can you please elaborate more? – RK Varun Jan 06 '23 at 12:55