I have added routes to post-event data.
var keystone = require('keystone');
var Event = keystone.list('Event');
module.exports = function (req, res) {
if (!req.body.name || !req.body.startTime || !req.body.endTime) {
return res.send({ status: 'incomplete data set' });
}
var newEvent = new Event.model();
Event.updateItem(newEvent, req.body, function (error) {
res.locals.enquirySubmitted = true;
if (error) res.locals.saveError = true;
res.render('addEvent');
});
};
When I start the app I am getting below error.
if (!result) throw new ReferenceError('Unknown keystone list ' + JSON.stringify(key)); ^
ReferenceError: Unknown keystone list "Events" at Keystone.list (/Users/rigalpatel/KS_shopingcart/node_modules/keystone/lib/core/list.js:7:21) at Object. (/Users/rigalpatel/KS_shopingcart/routes/api/event/post.js:2:22) at Module._compile (internal/modules/cjs/loader.js:689:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10) at Module.load (internal/modules/cjs/loader.js:599:32) at tryModuleLoad (internal/modules/cjs/loader.js:538:12) at Function.Module._load (internal/modules/cjs/loader.js:530:3) at Module.require (internal/modules/cjs/loader.js:637:17) at require (internal/modules/cjs/helpers.js:20:18) at /Users/rigalpatel/KS_shopingcart/node_modules/keystone/lib/core/importer.js:42:23 at Array.forEach () at importer (/Users/rigalpatel/KS_shopingcart/node_modules/keystone/lib/core/importer.js:32:26) at /Users/rigalpatel/KS_shopingcart/node_modules/keystone/lib/core/importer.js:36:22 at Array.forEach ()
Would you please provide your feedback. suggestion how to fix above issue.
| Software | Version
| ---------------- | -------
| Keystone | 4.0.0
| Node.js | 10.9.0
| Browser | Google Chrome 69.0.3497.100
var Event = keystone.list('Event');
@rigalpatel001: You need to change this line to keystone.List('Event');.
I'm assuming you copied this from Part 4 of the Getting started tutorial, which has the same typo.
Regards,
Stennie
Hello,
Thanks for your quick replay and solution.
Now I am getting another error.
"Event.model is not a constructor"
Would you please let me your feedback on how to fix it.
Thanks
Any updates? I have the same problem as @rigalpatel001
@ rigalpatel001 the error comes from using keystone.List instead of keystone.list. The List method, AFAIK, doesn't have a model constructor. It's used for creating mongoose schemas, not for accessing them.
I'm still having the original bug though: Unknown keystone list Wallet" in my case. A few suspicions:
I'll need a fix really soon. Here's my code:
'use strict';
const keystone = require('keystone');
const Types = keystone.Field.Types;
let Country = keystone.list('Country');
let Wallet = keystone.list('Wallet');
let User = new keystone.List('User', {history: true});
User.add({
name: { type: Types.Name, required: true, index: true },
email: { type: Types.Email, initial: true, required: true, unique: true, index: true },
password: { type: Types.Password, initial: true, required: false },
phone: { type: Types.Text, unique: true },
avatar: { type: Types.Text },
registrationEnd: { type: Types.Date },
registrationStart: { type: Types.Date },
utitle: { type: Types.Relationship, ref: 'Title' },
dob: { type: Types.Date },
permAddress: { type: Types.Location, state: { type: Types.Relationship, ref: 'State' }, country: { type: Types.Relationship, ref: 'Country' } },
sor: { type: Types.Relationship, ref: 'State' },
lga: { type: Types.Relationship, ref: 'LGA' },
religion: { type: Types.Relationship, ref: 'Religion' },
marital: { type: Types.Relationship, ref: 'Marital' },
sex: { type: Types.Select, options: 'male, female' },
// wallet: { type: Types.Relationship, ref: 'Wallet', many: false },
education: { type: Types.Relationship, ref: 'Education', dependsOn: { isClient: true } },
seenLawyer: { type: Boolean, default: false, dependsOn: { isClient: true } },
occupation: { type: Types.Relationship, ref: 'Occupation', dependsOn: { isClient: true } },
firm: { type: Types.Text, dependsOn: { isLawyer: true } },
lawyerSince: { type: Types.Date, dependsOn: { isLawyer: true } },
areas: { type: Types.Relationship, ref: 'LawArea', default: false , many: true, dependsOn: { isLawyer: true } },
}, 'Permissions', {
isAdmin: { type: Boolean, label: 'Can access Keystone', index: true, default: false },
isLawyer: { type: Boolean, index: true, default: false },
isClient: { type: Boolean, index: true, default: false },
});
// User.relationship({ path: 'wallet', ref: 'Wallet', refPath: 'currentBalance' });
User.schema.virtual('canAccessKeystone').get(function () {
return this.isAdmin;
});
User.schema.virtual('law').get(function () {
return this.isLawyer;
});
User.schema.virtual('client').get(function () {
return this.isClient;
});
User.schema.virtual('fullname').get(function () {
return this.name.first + ' ' + this.name.last;
});
User.schema.pre('save', function(next) {
let thisUser = this;
Country.model.findOne({name: 'India'}).then((result) => {
thisUser.permAddress.country = result._id;
next();
});
});
// Where the error lies
User.schema.post('save', function(next) {
let thisUser = this;
console.log(thisUser._id) // Works well
Wallet.model({owner: thisUser._id}).save(function(err) => {
if(err) console.error('User does not have a valid wallet');
next();
});
});
User.defaultColumns = 'name, email, roles, isAdmin';
User.register();
And the Wallet model, duly registered
'use strict';
const keystone = require('keystone');
const Types = keystone.Field.Types;
let Wallet = new keystone.List('Wallet');
Wallet.add({
owner: { type: Types.Relationship, ref: 'User', index: true, required: true, initial: false },
previousBalance: { type: Types.Number, default: 0 },
currentBalance: { type: Types.Number, default: 0, required: true },
});
//Wallet.relationship({ path: 'owner', ref: 'User', refPath: '_id' });
Wallet.register();
It's still unclear where I've missed something.
Hello,
Thanks for your quick replay and solution.Now I am getting another error.
"Event.model is not a constructor"
Would you please let me your feedback on how to fix it.
Thanks
hi,
and your good to go, mate.
Most helpful comment
Hello,
Thanks for your quick replay and solution.
Now I am getting another error.
"Event.model is not a constructor"
Would you please let me your feedback on how to fix it.
Thanks