Currently we are fetching data from many external services (firestore, github, discord service). We mostly change a few fields of the data according to our needs and send it to controller and eventually as API response.
A few problem arises with this -
Transformation of data happening at different places
return groups.map((group) => {
const groupCreator = groupCreatorsDetails[group.createdBy];
return {
...group,
firstName: groupCreator?.first_name,
lastName: groupCreator?.last_name,
image: groupCreator?.picture?.url,
memberCount: roleIdToCountMap[group.roleid] || 0, // Number of users joined this group
isMember: subscribedGroupIds.has(group.roleid), // Is current loggedIn user is a member of this group
};
});
No reliable way to ensure no sensitive data is sent.
We mostly return the data object to the frontend as we are given by firestore. Private fields need to be handled with more conditions throughout the codebase.
The below solution helps but is not reliable as - New private fields can be added to user as well as at other models.
Problem
Currently we are fetching data from many external services (firestore, github, discord service). We mostly change a few fields of the data according to our needs and send it to controller and eventually as API response.
A few problem arises with this -
Transformation of data happening at different places
/controller/auth.js
/models/discordactions.js
No reliable way to ensure no sensitive data is sent.
We mostly return the data object to the frontend as we are given by firestore. Private fields need to be handled with more conditions throughout the codebase.
The below solution helps but is not reliable as - New private fields can be added to user as well as at other models.
/services/dataAccessLayer.js
No fixed place to do date parsing or other parsing
/models/extensionRequest.js
Proposed Solution
transformers
with files according to the models we are transforming Eg -/transformers/user.js
,/transformers/goal.js
transformUserFromFirestore()
,transformGoalsFromAPI()
A transformation function would look something like this
Benifits
Demerits
Thankfully, this can done in a step by step process as show in the migration plan
Migration Plan
Alternate Solution
It can be called
serializer
instead.Ember data
serializer does this functionality as mentioned here(To be discussed more)