-
Notifications
You must be signed in to change notification settings - Fork 25
Import Bizness apps user Loyalty points
Mohammad Al Rawashdah edited this page May 18, 2023
·
1 revision
In this feature we are going to handle export Bizness app loyalty user data and allow app owner to import these data to buildfire loyalty account
-
The loyalty user data need for buildfire loyalty plugin
-
Biznesss app loyalty user data tables
# from app_users
email, contact_first_name, contact_last_name
# from loyalty
id, app_id, total_perks, reward_text, perk_unit_type, reward_on_download, reward_on_download_text
# from user_loyalty
redeem_count, count, last_redeem, state, zipCode
# from loyalty_perks
title, description, total_points
# user_loyalty_perk
awarded, redeemed
# app_tabs
tab_label
# Query // FULL Loyalty Query
SELECT loyalty.id loyalty_id, loyalty.app_id, app_users.email,app_users.contact_first_name first_name, app_users.contact_last_name last_name,
user_loyalty.redeem_count, user_loyalty.count user_loyalty_count, user_loyalty.last_redeem,
loyalty.reward_text, loyalty.perk_unit_type, loyalty.reward_on_download,
loyalty.reward_on_download_text, loyalty.total_perks, loyalty_perks.title as perk_title,
loyalty_perks.description as perk_description ,loyalty_perks.total_points as perk_total_points,
user_loyalty_perk.awarded , user_loyalty_perk.redeemed,
app_tabs.tab_label
FROM user_loyalty
inner join app_users on user_loyalty.user_id = app_users.device_user_id
inner join loyalty on loyalty.id = user_loyalty.loyalty_id
inner join app_tabs on app_tabs.id = loyalty.tab_id
inner join user_loyalty_perk on user_loyalty_perk.user_loyalty_id = user_loyalty.id
inner join loyalty_perks on loyalty_perks.id = user_loyalty_perk.perk_id
- Database tables related
- loyalty: App loyalty feature
- loyalty_perks: App loyalty feature perks
- user_loyalty: App Loyalty feature users
- user_loyalty_perk: App Loyalty feature user perks
Here the query that we will use to export loyalty users which is email and count which is represent totalPoint
SELECT app_users.email, user_loyalty.count totalPoint,
FROM user_loyalty
inner join app_users on user_loyalty.user_id = app_users.device_user_id
where app_users.app_id = ""-
Add new option to the plugin to export loyalty user data.
-
Prepare data and map it to import loaylity user template which sould include
emailandtotalPoint. -
Export loyalty user data as CSV to be imported to Loyalty plugin.
- Add new option to Points/Redeem page import data
- get user Ids by using
searchUsersAPIand sending email for all loyalty user data, get10or20users at once by send list of emails.
buildfire.auth.searchUsres({ emails: [], limit: 10 | 20})- prepare data and get user Ids for each record by email, data shoule be as following after:
data = [
{
userId,
email,
points
}
]- Then loop over data and start sending it to KLoyaly n
const addUserPoint = () {
# By using `LoyaltyAPI.addLoyaltyPoints`service in plugin
# Pass new proprty called points which will be added to API call
LoyaltyAPI.addLoyaltyPoints(userId, userToken, loyaltyUnqiueId, passcode, amount, points)
}-
Handle
AddPointsAPI to accept userpoints, -
Handle AddPoints dao function to handle new
pointsproperty and update theamountlogic
addPoints: function ({loyaltyUnqiueId, redemptionPasscode, amount, userId, points }, callback) {
...
...
userLog.amount = amount? amount : 0; //null if the user redeem a reward
userLog.points = points? points : parseInt(resultApp[0].pointsPerDollar * amount + resultApp[0].pointsPerVisit);
...
...
}