keystonejs/keystone-classic

TypeError: item.set is not a function

Open

#4538 aperta il 30 dic 2017

Vedi su GitHub
 (1 commento) (0 reazioni) (0 assegnatari)JavaScript (2288 fork)batch import
bughelp wanted

Metriche repository

Star
 (14.656 star)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

Expected behavior

Setting a name field via User.updateItem should update the field and return no errors.

Actual/Current behavior

Field is not updated, and error is returned:

TypeError: item.set is not a function
    at name.updateItem (/Users/davidm/development/js/tic-manager/node_modules/keystone/fields/types/name/NameType.js:208:9)
    at doFieldUpdate (/Users/davidm/development/js/tic-manager/node_modules/keystone/lib/list/updateItem.js:149:20)
    at /Users/davidm/development/js/tic-manager/node_modules/async/dist/async.js:3025:16
    at eachOfArrayLike (/Users/davidm/development/js/tic-manager/node_modules/async/dist/async.js:941:9)
    at eachOf (/Users/davidm/development/js/tic-manager/node_modules/async/dist/async.js:991:5)
    at Object.eachLimit (/Users/davidm/development/js/tic-manager/node_modules/async/dist/async.js:3089:3)
    at /Users/davidm/development/js/tic-manager/node_modules/keystone/lib/list/updateItem.js:176:10
    at /Users/davidm/development/js/tic-manager/node_modules/async/dist/async.js:3686:9
    at replenish (/Users/davidm/development/js/tic-manager/node_modules/async/dist/async.js:882:17)
    at iterateeCallback (/Users/davidm/development/js/tic-manager/node_modules/async/dist/async.js:867:17)
    at /Users/davidm/development/js/tic-manager/node_modules/async/dist/async.js:840:16
    at /Users/davidm/development/js/tic-manager/node_modules/async/dist/async.js:3691:13
    at apply (/Users/davidm/development/js/tic-manager/node_modules/async/dist/async.js:21:25)
    at /Users/davidm/development/js/tic-manager/node_modules/async/dist/async.js:56:12
    at /Users/davidm/development/js/tic-manager/node_modules/keystone/lib/list/updateItem.js:171:5
    at /Users/davidm/development/js/tic-manager/node_modules/async/dist/async.js:356:16

Steps to reproduce the actual/current behavior

This is on a super simple 'update profile' style form. I'm learning by screwing around at the moment, so may be user error rather than an actual bug. :)

profile.js:

var keystone = require('keystone');
var User = keystone.list('User');

exports = module.exports = function (req, res) {

    var view = new keystone.View(req, res);
    var locals = res.locals;
    
    // Set locals
	locals.section = 'profile';
	locals.formData = req.body || {};
	locals.validationErrors = {};
    locals.profileUpdated = false;

    view.query('currentUser', User.model.findById(req.user._id));

	view.on('post', { action: 'updateProfile' }, function (next) {
        var userObj = User.model.findById(req.user._id);

        User.updateItem(userObj, req.body, {
            fields: 'name, email',
            user: userObj,
        }, function (err) {
            if (err) {
                console.log(err);
                console.log(req.body);
            } else {
                locals.profileUpdated = true;
            }
            next();
        });
    });
    
    view.render('profile');
  };

profile.pug:

extends ../layouts/default

block intro
	.container
		h1 #{user.username} - Profile
		
block content
	.container
		if profileUpdated
			h3 Your profile has been updated.
		else
			.row: .col-sm-8.col-md-6
				form(method='post')
					input(type='hidden', name='action', value='updateProfile')
					.form-group(class=validationErrors.name ? 'has-error' : null)
						label First Name
						input(type='text', name='name.first', value=user.name.first||'').form-control
					.form-group(class=validationErrors.name ? 'has-error' : null)
						label Last Name
						input(type='text', name='name.last', value=user.name.last||'').form-control
					.form-group(class=validationErrors.email ? 'has-error' : null)
						label Email
						input(type='email', name='email', value=user.email).form-control
					.form-actions
						button(type='submit').btn.btn-primary Send

Environment

Software Version
Keystone 4.0.0-beta.5
Node v8.4.0
OS macOS Sierra
mongoDB v3.6.1

Guida contributor