-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
452 additions
and
26 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"exclude": [ | ||
"coverage/", | ||
"coverages/", | ||
"tests/", | ||
"mocks/", | ||
|
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
'use strict'; | ||
|
||
class ExportFormatters { | ||
|
||
/** | ||
* Format a user into a single string | ||
* | ||
* @param {Object} user | ||
* @returns {string|null} | ||
*/ | ||
static formatUser(user) { | ||
|
||
if(!user) | ||
return null; | ||
|
||
const firstname = user.firstname || '-'; | ||
const lastname = user.lastname || '-'; | ||
const email = user.email || '-'; | ||
return `${firstname} ${lastname} (${email})`; | ||
} | ||
|
||
/** | ||
* It formats a date into locale. | ||
* | ||
* @param {string} dateToFormat | ||
* @returns {string|null} | ||
*/ | ||
static formatDate(dateToFormat) { | ||
|
||
if(!dateToFormat) | ||
return null; | ||
|
||
const date = new Date(dateToFormat); | ||
|
||
return date.toLocaleString(); | ||
} | ||
|
||
} | ||
|
||
module.exports = ExportFormatters; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
'use strict'; | ||
|
||
class ExportHelper { | ||
|
||
/** | ||
* return a list of ids from an entity. | ||
* | ||
* @static | ||
* @param {string} entity | ||
* @returns | ||
* @memberof ExportHelper | ||
*/ | ||
static getIds(entity) { | ||
|
||
const ids = new Set(); | ||
|
||
this.items.forEach(({ [entity]: itemEntity }) => { | ||
|
||
if(!itemEntity) | ||
return; | ||
|
||
if(!Array.isArray(itemEntity)) | ||
itemEntity = [itemEntity]; | ||
|
||
itemEntity.forEach(id => ids.add(id)); | ||
}); | ||
|
||
return [...ids]; | ||
} | ||
|
||
/** | ||
* Returns an object with atributte the id of the entity and the value the enitity itself. | ||
* | ||
* @param {Array} entities | ||
* @memberof ExportHelper | ||
*/ | ||
static mapIdToEntity(entities) { | ||
return entities.reduce((entityMappedById, entity) => { | ||
return { ...entityMappedById, [entity.id]: entity }; | ||
}, {}); | ||
} | ||
} | ||
|
||
module.exports = ExportHelper; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
'use strict'; | ||
|
||
const MsCall = require('@janiscommerce/microservice-call'); | ||
const ExportHelper = require('./export-helper'); | ||
|
||
class ExportUserHelper extends ExportHelper { | ||
|
||
/** | ||
* | ||
* @static | ||
* @param {Array} items | ||
* @param {Object} session | ||
* @returns | ||
* @memberof ExportUserHelper | ||
*/ | ||
static async getUsers(items, session) { | ||
this.items = items; | ||
|
||
const userIds = this.getIds(); | ||
|
||
const microServiceCall = new MsCall(session); | ||
|
||
let users = await microServiceCall.list('id', 'user', { filters: { id: userIds } }); | ||
|
||
users = this.mapIdToEntity(users); | ||
|
||
return users; | ||
} | ||
|
||
/** | ||
* return a list of ids from users. | ||
* | ||
* @static | ||
* @param {string} entity | ||
* @returns | ||
* @memberof ExportUserHelper | ||
*/ | ||
static getIds() { | ||
|
||
const ids = new Set(); | ||
|
||
this.items.forEach(({ userCreated, userModified }) => { | ||
|
||
if(userCreated) | ||
ids.add(userCreated); | ||
|
||
if(userModified) | ||
ids.add(userModified); | ||
}); | ||
|
||
return [...ids]; | ||
} | ||
} | ||
|
||
module.exports = ExportUserHelper; |
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
Oops, something went wrong.