function updateParentFields(Subject, parentId, parentAbsolutePath, inst) {
  let newAbsolutePath;
  return Subject.scope({ method:
    ['id', inst.previous('parentId')],
  }).find()
  .then((oldParent) => {
    if (oldParent) {
      oldParent.decrement('childCount');
    }

    newAbsolutePath = parentAbsolutePath ?
      parentAbsolutePath + '.' + inst.name : inst.name;
    const whereObj = { where: { absolutePath: { [Op.iLike]: newAbsolutePath } } };
    return Subject.find(whereObj);
  })
  .then((subj) => {
    if (subj && subj.id !== inst.id) {
      throw new SubjectAlreadyExistsUnderParent({
        message: newAbsolutePath + ' already exists.',
      });
    }
  })
  .then(() => {
    // update the subject values
    inst.setDataValue('parentId', parentId);
    inst.setDataValue('parentAbsolutePath', parentAbsolutePath);
    inst.setDataValue('absolutePath', newAbsolutePath);
    return inst;
  });
}
/**
 * Decrements childCount on old parent
 * Sets the parent-related fields on inst
 *
 * @param {Object} Subject - the model
 * @param {String} parentId - The new parentId
 * @param {String} parentAbsolutePath - The new parentAbsolutePath
 *  for new absolutePath
 * @param {Object} inst - the subject instance
 * @returns {Object} the subject instance
 */
Decrements childCount on old parent
Sets the parent-related fields on inst


Decrements childCount on old parent Sets the parent - related fields on inst
function updateParentFields(Subject, parentId, parentAbsolutePath, inst) {
  let newAbsolutePath;
  return Subject.scope({ method:
    ['id', inst.previous('parentId')],
  }).find()
  .then((oldParent) => {
    if (oldParent) {
      oldParent.decrement('childCount');
    }
    newAbsolutePath = parentAbsolutePath ?
      parentAbsolutePath + '.' + inst.name : inst.name;
    const whereObj = { where: { absolutePath: { [Op.iLike]: newAbsolutePath } } };
    return Subject.find(whereObj);
  })
  .then((subj) => {
    if (subj && subj.id !== inst.id) {
      throw new SubjectAlreadyExistsUnderParent({
        message: newAbsolutePath + ' already exists.',
      });
    }
  })
  .then(() => {
    inst.setDataValue('parentId', parentId);
    inst.setDataValue('parentAbsolutePath', parentAbsolutePath);
    inst.setDataValue('absolutePath', newAbsolutePath);
    return inst;
  });
}
function updateParentFields ( Subject , parentId , parentAbsolutePath , inst ) { let newAbsolutePath ; return Subject . scope ( { method : [ 'id' , inst . previous ( 'parentId' ) ] , } ) . find ( ) . then ( ( oldParent ) => { if ( oldParent ) { oldParent . decrement ( 'childCount' ) ; } newAbsolutePath = parentAbsolutePath ? parentAbsolutePath + '.' + inst . name : inst . name ; const whereObj = { where : { absolutePath : { [ Op . iLike ] : newAbsolutePath } } } ; return Subject . find ( whereObj ) ; } ) . then ( ( subj ) => { if ( subj && subj . id !== inst . id ) { throw new SubjectAlreadyExistsUnderParent ( { message : newAbsolutePath + ' already exists.' , } ) ; } } ) . then ( ( ) => { inst . setDataValue ( 'parentId' , parentId ) ; inst . setDataValue ( 'parentAbsolutePath' , parentAbsolutePath ) ; inst . setDataValue ( 'absolutePath' , newAbsolutePath ) ; return inst ; } ) ; }
Decrements childCount on old parent
 Sets the parent-related fields on inst
Decrements childCount on old parent Sets the parent - related fields on inst
// update the subject values