<commit_before>import {Service} from "./Service";
import {User} from "../DataObjects/User";
/**
 * Created by hypfer on 06.06.17.
 */
type UserCallback = (hash : User) => any;
export class UserService extends Service{

    protected getCollection(): string {
        return "User";
    }

    FindUser(user : User, callback : UserCallback) : any {
        const self = this;

        super.GetById(user.ID, function(result){
            if(result) {
                callback(new User(result.ID, result.FirstName, result.Roles, result.Username));
            } else {
                const newUser = new User(user.ID, user.FirstName, [], user.Username);
                self.SaveUser(newUser, function(){
                    callback(newUser);
                });
            }
        });

    }
    FindUserById(id : string, callback : UserCallback) : any {
        const self = this;

        super.GetById(id, function(result){
            if(result) {
                callback(new User(result.ID, result.FirstName, result.Roles, result.Username));
            } else {<commit_msg>- keep user data up to date<commit_after>import {Service} from "./Service";
import {User} from "../DataObjects/User";
/**
 * Created by hypfer on 06.06.17.
 */
type UserCallback = (hash : User) => any;
export class UserService extends Service{

    protected getCollection(): string {
        return "User";
    }

    FindUser(user : User, callback : UserCallback) : any {
        const self = this;

        super.GetById(user.ID, function(result){
            if(result) {
                if(result.FirstName !== user.FirstName ||
                   result.Username !== user.Username) {
                    user.Roles = result.Roles;
                    self.SaveUser(user, function(){
                        callback(user);
                    })
                }
                callback(new User(result.ID, result.FirstName, result.Roles, result.Username));
            } else {
                const newUser = new User(user.ID, user.FirstName, [], user.Username);
                self.SaveUser(newUser, function(){
                    callback(newUser);
                });
            }
        });

    }
    FindUserById(id : string, callback : UserCallback) : any {
        const self = this;

        super.GetById(id, function(result){
            if(result) {
                callback(new User(result.ID, result.FirstName, result.Roles, result.Username));
            } else {
{'fraction_non_alphanumeric': 0.12439418416801293, 'fraction_numerical': 0.004846526655896607, 'mean_word_length': 1.7894144144144144, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '92646', 'n_tokens_mistral': 680, 'n_tokens_neox': 641, 'n_words': 157}