Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add balance for newly registered user #4498

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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