Skip to content

Instantly share code, notes, and snippets.

@suissa
Last active July 26, 2021 02:14
Show Gist options
  • Save suissa/64d2c24bf8faa41860c5e44ae9d6640d to your computer and use it in GitHub Desktop.
Save suissa/64d2c24bf8faa41860c5e44ae9d6640d to your computer and use it in GitHub Desktop.
Vou refatorar esse meu code
const mongoose = require('mongoose')
const moleculesPath = './../modules/'
const organellesPath = './../_organelles/'
module.exports = (DNA, Molecule) => {
const Organism = mongoose.model(DNA.name, Molecule) // deixar generico
const Organelles = require('./../_config/organism/organelles.default')
const OrganellesCell =
(Array.isArray(DNA.organelles))
? (Array.isArray(DNA.middlewares))
? DNA.organelles.concat(Organelles).concat(DNA.middlewares)
: DNA.organelles.concat(Organelles)
: Organelles
const createOrganelles = (acc, name) =>
Object.assign(acc, {
[name]: require(organellesPath+name)(Organism, DNA.populate)})
return OrganellesCell.reduce(createOrganelles, {name: DNA.name})
}
@suissa
Copy link
Author

suissa commented Mar 29, 2017

/** 
OUT:
MakeLife { name: 'Bill',
   find: [Function],
   create: [Function],
   getSchema: [Function],
   findByFilter: [Function],
   findAllPopulate: [Function],
   findById: [Function],
   findByIdPopulate: [Function],
   update: [Function],
   remove: [Function],
   findOne: [Function],
   test: [Function] }
*/

@rafaeljourdan
Copy link

MakeLife tirou onda!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment