NodeBB referral system plugin

I am creating a plugin for Nodebb forum which works like this:
User(A) created his account - > he gets a referral code (his username)
Anyone(B) uses his referral code while registration + earns 150 currency -> User(A) gets 20 points for each such user.

I have already created the repository and following modules:

Registration screen has input for referral code.
If referral is entered is cross checked against all registered user names.
If founds a matching username, inside a new hash the new user and original users are mapped.
Else displays the message the wrong "referral code entered".
If no referral code was entered user is registered as normal and no mapping happens.