async function validateActivityAndSave(activity, shouldUpdateDb = true) {
  const activityDoc = new Activity(activity);
  // Mongoose returns error here instead of throwing
  const invalid = activityDoc.validateSync();
  if (invalid) {
    console.warn(`Failed to validate activity ${activity.get('_id')}`);
    return false;
  }

  if (!shouldUpdateDb) {
    return activityDoc;
  }

  await Activity.create(activityDoc);
  return activityDoc;
}
/**
 * Validate activity model and save to database
 *
 * @param {Object} activity
 * @param {Bool} shouldUpdateDb If false, will validate without saving
 * @return {Document|false}
 */
Validate activity model and save to database
@param {Object} activity
@param {Bool} shouldUpdateDb If false, will validate without saving
@return {Document|false}
Validate activity model and save to database @param { Object } activity @param { Bool } shouldUpdateDb If false will validate without saving @return { Document|false }
async function validateActivityAndSave(activity, shouldUpdateDb = true) {
  const activityDoc = new Activity(activity);
  const invalid = activityDoc.validateSync();
  if (invalid) {
    console.warn(`Failed to validate activity ${activity.get('_id')}`);
    return false;
  }
  if (!shouldUpdateDb) {
    return activityDoc;
  }
  await Activity.create(activityDoc);
  return activityDoc;
}
async function validateActivityAndSave ( activity , shouldUpdateDb = true ) { const activityDoc = new Activity ( activity ) ; const invalid = activityDoc . validateSync ( ) ; if ( invalid ) { console . warn ( ` ${ activity . get ( '_id' ) } ` ) ; return false ; } if ( ! shouldUpdateDb ) { return activityDoc ; } await Activity . create ( activityDoc ) ; return activityDoc ; }
Validate activity model and save to database
 @param {Object} activity
 @param {Bool} shouldUpdateDb If false, will validate without saving
 @return {Document|false}
Validate activity model and save to database @param { Object } activity @param { Bool } shouldUpdateDb If false will validate without saving @return { Document|false }
// Mongoose returns error here instead of throwing