Created
April 14, 2018 17:15
-
-
Save 1fabiopereira/7ceb09e4cc4919f4a7515eb36a8c5c99 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Faz consulta no BD 1 | |
class Database1 { | |
static getAll () { | |
return [ | |
{ | |
id: 1, | |
name: "Name-1" | |
}, | |
{ | |
id: 2, | |
name: "Name-2" | |
}, | |
{ | |
id: 3, | |
name: "Name-3" | |
}, | |
{ | |
id: 4, | |
name: "Name-4" | |
} | |
] | |
} | |
} | |
// Faz consulta no BD 2 | |
class Database2 { | |
static get all() { | |
return [ | |
{ | |
id: 2, | |
Status: "Status-2" | |
}, | |
{ | |
id: 3, | |
Status: "Status-3" | |
}, | |
{ | |
id: 1, | |
Status: "Status-1" | |
} | |
]; | |
} | |
static getAll () { | |
return Database2.all; | |
} | |
static get (id) { | |
return Database2.all.filter((item) => item.id === id).pop(); | |
} | |
} | |
// Abstrai a junção de dados | |
class Service { | |
static getRegisters (qt) { | |
const query1 = Database1.getAll(qt); | |
const joinData = query1.map((item) => { | |
const data = Database2.get(item.id) || {Status: null}; | |
return { | |
...item, | |
...data | |
} | |
}) | |
return joinData; | |
} | |
} | |
console.info(new Date(), " --------> ", Service.getRegisters(10)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment