nkowaokwu / igbo-api-admin

Data entry platform for the Igbo API.
https://editor.igboapi.com
Apache License 2.0
8 stars 20 forks source link

Copy Firebase users to MongoDB and generate unique referral code #450

Closed IfyNdu closed 11 months ago

IfyNdu commented 1 year ago

Is your feature request related to a problem? Please describe. We want to copy firebase user accounts over to MongoDB as a prerequisite to creating a referral system. At the moment we have no way of assigning unique referral codes to existing users as well as tracking who referred who.

Describe the solution you'd like Create a User Schema with the following structure

type User = {
  firebaseId: string; // self explanatory
  referralCode: string; // generated in the script below
}

Create a temp js script that pings Firebase for a list of existing users, loops through them and creates a new User Document. Or batch create User Documents by calling User.insertMany with an array ofUser Documents

As part of the migration process a unique referral code is generated for each User using nanoid.

const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
const referral_code = nanoid.customAlphabet(`${alphabet}${new Date().valueOf()}`, 6);

await User.insertMany[{ firebaseId: 'awesome-id', referralCode}]

Additional context

  1. Software design document for inspiration.
  2. Please reach @ijemmao for direct access to firebase and mongoDB prod accounts.
IfyNdu commented 1 year ago

@ijemmao Please assign to me