Toke statistics now recorded in user DB document.

This commit is contained in:
rainbow napkin 2024-12-13 23:53:18 -05:00
parent 3902554e6b
commit 0b84c51cbf
2 changed files with 53 additions and 17 deletions

View file

@ -174,6 +174,35 @@ userSchema.statics.authenticate = async function(user, pass){
}
}
userSchema.statics.tattooToke = function(tokemap){
//For each toke, asynchronously:
tokemap.forEach(async (toke, user) => {
//get user
const userDB = await this.findOne({user});
//Check that the user exists (might come in handy for future treez.one integration?)
if(userDB != null){
var tokeCount = userDB.tokes.get(toke);
//if this is the first time using this toke command
if(tokeCount == null){
//set toke count to one
tokeCount = 1;
//otherwise
}else{
//increment tokecount
tokeCount++;
}
//Set the toke count for the specific command
userDB.tokes.set(toke, tokeCount);
//Save the user doc to the database
await userDB.save();
}
});
}
//methods
userSchema.methods.checkPass = function(pass){
return hashUtil.comparePassword(pass, this.pass);