Skip to content

Commit

Permalink
Add balance for newly registered user
Browse files Browse the repository at this point in the history
  • Loading branch information
dennis531 committed Nov 8, 2024
1 parent 81f2936 commit 1c6b627
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ ILLEGAL_MODEL_REQ_SCORE=5
#========================#

CHECK_BALANCE=false
# REGISTRATION_BALANCE=0

#========================#
# Registration and Login #
Expand Down
10 changes: 10 additions & 0 deletions api/models/userMethods.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const bcrypt = require('bcryptjs');
const signPayload = require('~/server/services/signPayload');
const User = require('./User');
const { Transaction } = require('./Transaction');

/**
* Retrieve a user by ID and convert the found user document to a plain object.
Expand Down Expand Up @@ -71,6 +72,15 @@ const createUser = async (data, disableTTL = true, returnUser = false) => {
}

const user = await User.create(userData);
if (process.env.CHECK_BALANCE && process.env.REGISTRATION_BALANCE) {
await Transaction.create({
user: user._id,
tokenType: 'credits',
context: 'admin',
rawAmount: +process.env.REGISTRATION_BALANCE,
});
}

if (returnUser) {
return user.toObject();
}
Expand Down

0 comments on commit 1c6b627

Please sign in to comment.