delete password enhancement

made first implementation of #403 for review
Is DAO.prototype.loadByValues the only par t to change?

On 11:10PM, Mon, Dec 29, 2014 Brian <notifications@github.com> wrote:

> In include/dao/dao.js
> <https://github.com/pencilblue/pencilblue/pull/407#discussion-diff-22333143>
> :
>
> > +DAO.prototype.loadByValues = function(where, collection, options, cb) {
> > +    if (options && options.select !== undefined) {
> > +        var options = {
> > +            where: where,
> > +            select: options,
> > +            order: DAO.NATURAL_ORDER,
> > +            limit: 1
> > +        };
> > +    } else {
> > +        var options = {
> > +            where: where,
> > +            select: DAO.PROJECT_ALL,
> > +            order: DAO.NATURAL_ORDER,
> > +            limit: 1
> > +        };
> > +    }
>
> Looks good. 1 small change.
>
> DAO.prototype.loadByValues = function(where, collection, opts, cb) {
>     if (pb.utils.isFunction(opts)) {
>         cb = opts;
>         opts = null;
>     }
>     if (!pb.utils.isObject(opts)) {
>         opts = { };
>     }
>         var options = {
>             where: where,
>             select: opts.select || DAO.PROJECT_ALL,
>             order: opts.order || DAO.NATURAL_ORDER,
>             limit: 1
>         };
>     this.q(collection, options, function(err, result){
>            cb(err, util.isArray(result) && result.length > 0 ? result[0] : null);
>     });
> };
>
> The reason I would recommend structuring it like this because we want to
> catch 3 edge cases.
> 1) The case where the opts parameter is not passed. In this case opts
> parameter is actually the callback.
>
> 2) The second case we want to catch is if a non object is passed as the
> opts parameter. The second if statement will catch that.
> 3) Lastly, we want to catch the case where opts is passed but has no
> select property. We want to default in that case.
>
> If you can update the pull request with the recommendation I'll merge it
> in.
>
> Thanks again for taking care of that for us!
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/pencilblue/pencilblue/pull/407/files#r22333143>.
>