message: Add missing migrations parts for file unit
diff: @@ -5,6 +5,9 @@ import {ObjectID} from 'bson';
  import {IFileUnit} from '../../../../shared/models/units/IFileUnit';
  import fs = require('fs');
  import {File} from '../../models/mediaManager/File';
  +import {Course} from '../../models/Course';
  +import {Directory} from '../../models/mediaManager/Directory';
  +import {ICourse} from '../../../../shared/models/ICourse';
  const unitSchema = new mongoose.Schema({
  _course: {
  @@ -80,6 +83,34 @@ class FileUnitMigration {
  async up() {
  console.log('FileUnit up was called');
  try {
  + const courses = await Course.find().exec();
  + const directories: any = {};
  + const updatedCoursesMap: any = {};
  + const updatedCourses = await Promise.all(courses.map(async (course) => {
  + const courseObj: ICourse = <ICourse>course.toObject();
  + const returnObj: any = {};
  + if (!courseObj.hasOwnProperty('media')) {
  + const directoryObj: any = {
  + name: courseObj.name,
  + subDirectories: [],
  + files: []
  + };
  +
  + const createdDirectory: any = await Directory.create(directoryObj);
  + courseObj.media = createdDirectory._id;
  + const updatedCourse = await Course.findOneAndUpdate({'_id': courseObj._id}, courseObj, {new: true}).exec();
  +
  + directories[createdDirectory._id] = await createdDirectory.toObject();
  +
  + updatedCoursesMap[courseObj._id] = await updatedCourse.toObject();
  + return updatedCourse;
  + } else {
  + const directory = await Directory.findById(courseObj.media).exec();
  + directories[directory._id] = await directory.toObject();
  + updatedCoursesMap[courseObj._id] = courseObj;
  + return course;
  + }
  + }));
  const fileUnits = await Unit.find({'__t': 'file'}).exec();
  const updatedFileUnits = await Promise.all(fileUnits.map(async (fileUnit) => {
  if (fileUnit._id instanceof ObjectID) {
  @@ -120,13 +151,22 @@ class FileUnitMigration {
  return createdFile._id;
  }));
  + const directoryId = updatedCoursesMap[fileUnitObj._course].media.toString();
  fileUnitObj._id = new ObjectID(fileUnitObj._id);
  fileUnitObj._course = new ObjectID(fileUnitObj._course);
  + directories[directoryId].files = directories[directoryId].files.concat(fileUnitObj.files);
  +
  const unitAfterReplace = await mongoose.connection.collection('units')
  .findOneAndReplace({'_id': fileUnit._id}, fileUnitObj);
  return fileUnitObj;
  }
  }));
  +
  + for (const directoryId of Object.keys(directories)) {
  + const directory = directories[directoryId];
  + const updatedDirectory = await Directory.findOneAndUpdate({'_id': directoryId}, directory, {new: true}).exec();
  + }
  +
  } catch (error) {
  console.log(error);
  }
  