ScaffoldHub Update v1.7.0: Back-end refactored and commented

Felipe Lima
Felipe Lima
Nov 08, 2019 - SQL MongoDB Firestore
ScaffoldHub Update v1.7.0: Back-end refactored and commented

This new ScaffoldHub update is more an apology than anything else.

I commented, refactored, and updated all the dependencies of all the back-ends of all the scaffolds (SQL, MongoDB, and Firestore). It's available on the 1.7.0 version.

The file that most bothered me - and you, probably - was the SQL Repository.

I created abstractions to avoid duplicated code that ended up creating more harm than good.

The avoidance of duplicated code made it hard to understand even for the ones with the highest knowledge in Sequelize.

Come one, look at this code:

async _createOrUpdateRelations(record, data, options) {
  for (const field of Object.keys(
    this.relationToManyAttributes,
  )) {
    await record[`set${AbstractRepository.jsUcfirst(field)}`](
      data[field] || [],
      {
        transaction: AbstractRepository.getTransaction(
          options,
        ),
      },
    );
  }

  for (const field of Object.keys(
    this.relationToOneAttributes,
  )) {
    await record[`set${AbstractRepository.jsUcfirst(field)}`](
      data[field] || null,
      {
        transaction: AbstractRepository.getTransaction(
          options,
        ),
      },
    );
  }
}

Yeah, shame on me =/

But now I'm redeeming myself.

You can look at an example of the new code here: https://gist.github.com/felipepastorelima/584e47eae2eca325f830082d21587cd4

Thank you, and good coding!