These are chat archives for edbirmingham/network

20th
Nov 2015
saabdoli
@saabdoli
Nov 20 2015 01:20
I was testing a function to do some of this, but I can't seem to manually change the discriminator (__t) field.
Participant.findOne({firstName: 'Still', lastName: 'Oaks'}, function(err, par){
    if(err){
        console.log(err);
    }else if(par){
        console.log('Found:', par);
        var member = new Member();
        if(!par.__t){
             member.firstName = par.lastName;
            member.lastName = par.lastName;
            member.phone = par.phone;
            member.affiliation = par.affiliation;
            member.__t = 'Member';

            //save participant as member
            par.save(function(err){
                if(err){
                    console.log(err);
                }else{
                    console.log('Updated', par);
                }
            });
        }

    }else{
        console.log('Participant not found!');
    }
});
There's a typo in that snippet
saabdoli
@saabdoli
Nov 20 2015 01:25

```Participant.findOne({firstName: 'still', lastName: 'oaks'}, function(err, par){
if(err){
console.log(err);
}else if(par){
console.log('Found:', par);
var member = new Member();
if(!par.t){
member.firstName = par.lastName;
member.lastName = par.lastName;
member.phone = par.phone;
member.affiliation = par.affiliation;
member.
t = 'Member';

        //save participant as member
        member.save(function(err){
            if(err){
                console.log(err);
            }else{
                console.log('Updated', par);
            }
        });
    }

}else{
    console.log('Participant not found!');
}

});
```

Participant.findOne({firstName: 'still', lastName: 'oaks'}, function(err, par){
    if(err){
        console.log(err);
    }else if(par){
        console.log('Found:', par);
        var member = new Member();
        if(!par.__t){
             member.firstName = par.lastName;
            member.lastName = par.lastName;
            member.phone = par.phone;
            member.affiliation = par.affiliation;
            member.__t = 'Member';

            //save participant as member
            member.save(function(err){
                if(err){
                    console.log(err);
                }else{
                    console.log('Updated', par);
                }
            });
        }

    }else{
        console.log('Participant not found!');
    }
});
I think the problem with this is that the required fields aren't initialized for the member object
Anthony Crumley
@anthonycrumley
Nov 20 2015 13:59
@saabdoli My current concept would be:
Anthony Crumley
@anthonycrumley
Nov 20 2015 14:10
In the server controller for member memberByID function
    Find the member
    if the member exists 
        assign it to req.member
    else
        Find the participant
        if the participant exists
            assign it to req.participant
            assign new Member(participant) to req.member

In the server controller update action
    if req.participant is present
        if req.member.validate() does not return errors
            delete req.participant
            save req.member
        else
            return the validation errors
    else save req.member
See http://mongoosejs.com/docs/3.7.x/docs/api.html#document_Document-validate
@saabdoli I think what you have on the client controller is pretty close.
marshallpollard
@marshallpollard
Nov 20 2015 14:32
Sending link now
@saabdoli @anthonycrumley
saabdoli
@saabdoli
Nov 20 2015 14:38
It says I'm not allowed to join the video call