Trying to create an event that changes a String called status in my NetworkApp collection.
Event:
Template.app_detail.events({
'click .accept': function (e, t) {
console.log("Accept");
NetworkApp.update(this._id, {$set:{
status: "Accepted"
}});
},
'click .reject': function (e, t) {
console.log("Reject");
NetworkApp.update(this._id, {$set:{
status: "Rejected"
}});
}
})
It updates the last time the application was modified but not the status. No errors appear in the console but it does log Accepted or Rejected so the code can connect to the db and the helper is being triggered by the buttons. Any help is appreciated!~
Simple Schema:
NetworkAppSchema = new SimpleSchema({
ign: {
type: String,
label: "IGN"
},
discordName: {
type: String,
label: "Discord Name"
},
memberlength: {
type: String,
label: "How long have you been a member at Digital Hazards?"
},
languageKnown: {
type: String,
label: "What languages do you know?",
autoform: {
type: 'textarea'
}
},
whyyou: {
type: String,
label: "Why do you want to join the Network staff?",
autoform: {
type: 'textarea'
}
},
applicant: {
type: String,
label: "Applicant",
autoValue: function() {
return Meteor.userId();
},
autoform: {
type: "hidden"
}
},
createdAt: {
type: Date,
label: "Applied At",
autoValue: function() {
return new Date();
},
autoform: {
type: "hidden"
}
},
status: {
type: String,
label: "Status",
autoValue: function() {
return "Pending";
},
autoform: {
type: "hidden",
}
}
});
autoValue does not mean initial value: your autoValue functions are running every time.
For createdAt for example you should have:
createdAt: {
type: Date,
denyUpdate: true,
autoValue() {
if (this.isInsert) return new Date();
},
},
this will avoid the createdAt ever changing after insert.
Similarly for status:
status: {
type: String,
label: "Status",
autoValue() {
if (this.isInsert) return "Pending";
},
autoform: {
type: "hidden",
}
}
Related
my schema like this
customer : {
type: Schema.Types.ObjectId,
ref: 'Customer'
},
doctor: {
type: Schema.Types.ObjectId,
ref: 'Doctor'
},
return_patient : {
type: Boolean,
default: false
},
consultation: {
type: Number, //1: Phone, 2: Video
required: true
},
fee: {
type: Number
},
payment: {
type: Schema.Types.Mixed
},
schedule_date: {
type: Date
},
schedule_time: {
from: {
type: String
},
to: {
type: String
}
},
now i want check doctor availablity
from req.query
localhost:9000/api/appointment/doctor-available?doctor=5e83704aadca4064368ff24f&date=2020-04-01&from=5.30&to=6.00
match the table and query if data came means doctor is not available otherwise
doctor available
I'm trying to use Facebook to connect and register into my Meteor.js application. In my login template I put a button to do this. I call the function Meteor.loginWithFacebook() but it doesn't work... I'm guessing that Meteor try to create a new user and that it doesn't find the username information but I don't know how to manage that.
My handler to call the login :
'click #facebook-login': function(event) {
Meteor.loginWithFacebook({}, function(err){
if (err) {
throw new Meteor.Error("Facebook login failed");
Materialize.toast('Echec de connexion!', 4000);
}
else {
Router.go(Utils.pathFor('home'));
Materialize.toast('Bon retour parmis nous ' + Meteor.user().username + ' !', 5000);
}
});
}
The error I have :
I20160428-12:44:56.099(2)? Exception while invoking method 'login' Error: Nom d'utilisateur is required
I20160428-12:44:56.100(2)? at getErrorObject (packages/aldeed_collection2-core/lib/collection2.js:437:1)
I20160428-12:44:56.101(2)? at [object Object].doValidate (packages/aldeed_collection2-core/lib/collection2.js:420:1)
I20160428-12:44:56.101(2)? at [object Object].Mongo.Collection. (anonymous function) [as insert] (packages/aldeed_collection2-core/lib/collection2.js:173:1)
I20160428-12:44:56.101(2)? at AccountsServer.Ap.insertUserDoc (packages/accounts-base/accounts_server.js:1250:25)
I20160428-12:44:56.101(2)? at AccountsServer.Ap.updateOrCreateUserFromExternalService (packages/accounts-base/accounts_server.js:1386:20)
I20160428-12:44:56.102(2)? at [object Object].Package (packages/accounts-oauth/oauth_server.js:55:1)
I20160428-12:44:56.103(2)? at packages/accounts-base/accounts_server.js:464:32
I20160428-12:44:56.103(2)? at tryLoginMethod (packages/accounts-base/accounts_server.js:241:14)
I20160428-12:44:56.103(2)? at AccountsServer.Ap._runLoginHandlers (packages/accounts-base/accounts_server.js:461:18)
I20160428-12:44:56.103(2)? at [object Object].methods.login (packages/accounts-base/accounts_server.js:524:27)
I20160428-12:44:56.129(2)? Sanitized and reported to the client as: Nom d'utilisateur is required [400]
User schema :
Globals.schemas.UserProfile = new SimpleSchema({
firstName: {
type: String,
regEx: /^[a-zA-Z-]{2,25}/,
optional: true,
label: "Prénom"
},
lastName: {
type: String,
regEx: /^[a-zA-Z-]{2,25}/,
optional: true,
label: "Nom"
},
birthDay: {
type: Date,
optional: true,
label: "Date de naissance",
min: new Date("1900-01-01T00:00:00.000Z"),
autoform: {
value: new Date("1900-10-18T00:00:00.000Z")
}
},
gender: {
type: String,
allowedValues: ['M', 'F'],
optional: true,
label: "Genre",
autoform: {
options: [
{
label: "Homme",
value: "M"
},
{
label: "Femme",
value: "F"
}
],
firstOption: "(Veuillez sélectionner une réponse)"
}
},
level: {
type: Number,
autoValue: function () {
if (this.isInsert) {
return 1;
}
},
autoform: {
omit: true
},
min: 0,
max: 1000,
label: "Niveau"
},
picture: {
type: String,
optional: true,
autoform: {
omit: true
},
label: "Photo"
}
});
// Schéma principal
Globals.schemas.User = new SimpleSchema({
username: {
type: String,
regEx: /^[a-z0-9A-Z_]{3,30}$/,
label: "Nom d'utilisateur"
},
password: {
type: String,
label: "Mot de passe",
optional: true,
autoform: {
afFieldInput: {
type: "password"
}
}
},
confirmation: {
type: String,
label: "Confirmation",
optional: true,
custom: function(){
if(this.value !== this.field('password').value){
return "passwordMissmatch";
}
},
autoform: {
afFieldInput: {
type: "password"
}
}
},
emails: {
type: [Object],
optional: false,
label: "Adresses Email"
},
"emails.$.address": {
type: String,
regEx: SimpleSchema.RegEx.Email,
label: "Adresses Email"
},
"emails.$.verified": {
type: Boolean,
optional: true,
autoform: {
omit: true
}
},
createdAt: {
type: Date,
autoValue: function () {
if (this.isInsert) {
return new Date;
} else {
this.unset();
}
},
autoform: {
omit: true
}
},
profile: {
type: Globals.schemas.UserProfile,
optional: true
},
services: {
type: Object,
optional: true,
blackbox: true,
autoform:{
omit: true
}
},
roles: {
type: Object,
optional: true,
blackbox: true,
autoform: {
omit: true
}
}
});
Thank's for any help !
The problem is that your schema requires Meteor.users to have a username field, which they don't contain by default. You can, however, generate this field by taking their name name from the Facebook profile.
Accounts.onCreateUser(function(options, user) {
user.username = user.services.facebook.name;
return user;
});
http://docs.meteor.com/#/full/accounts_oncreateuser
Currently, I'm writing an app on Node.js 5.2.0 on a Linux box with Redis and Caminte. When trying to add different prototype methods to a database object, the context of what this refers to constantly shifts within our reference. After calling push in modelRules.js, this shifts types. I was looking for some assistance with:
How to consistently reference the instantiation of a specific module (function that accepts a schema object) outside of the module itself. I want to tack on prototype functions such as addModelBelongsTo to a User object, and sadly my function simply seems to break when referencing the internal modifiable data members within the class.
The proper organization of the prototype accessors. Is there a specific style that should be used when referencing the insides of the instantiations of these classes?
Why the instantiation of the class User persists data across multiple instantiations of the class? For self[restructuredModelName] (type of array), whenever I call this method on one instantiation, another instantiation of the other object already contains the data of the first instantiation. This should not be happening.
User.js
module.exports = function (schema) {
const IBANVerificationStatusSymbol = Symbol('IBANVerificationStatus');
const relationalMapper = require('./../relationalMapper');
const userObj = {
id: { type: schema.Number },
firstName: { type: schema.String },
lastName: { type: schema.String },
IBAN: { type: schema.String, unique: true },
IBANVerified: { type: schema.Boolean, default: false },
IBANVerificationCode: { type: schema.String },
BIC: { type: schema.String },
email: { type: schema.String, index: true, unique: true },
password: { type: schema.String },
status: { type: schema.Number, default: 0 },
profilePicture: { type: schema.String },
phone: { type: schema.String, index: true, unique: true },
accessToken: { type: schema.String },
prefix: { type: schema.String, default: '+31' },
updated: { type: schema.Date, default: Date.now() },
created: { type: schema.Date, default: Date.now() },
lastAccessedFeed: { type: schema.Date },
street: { type: schema.String },
streetNumber: { type: schema.String },
postalCode: { type: schema.String },
city: { type: schema.String },
country: { type: schema.String },
FCR: { type: schema.Number, default: 0 },
};
// There's GOTTA be a way to typecheck at compilation
const associationMap = {
Activity: { belongsTo: 'Activity', hasMany: 'activities' },
Client: { belongsTo: null, hasMany: 'clients' },
Group: { belongsTo: 'Group', hasMany: 'groups' },
Mandate: { belongsTo: null, hasMany: 'mandates' },
Transaction: { belongsTo: null, hasMany: 'transactions' },
Update: { belongsTo: null, hasMany: 'updates' },
Reaction: { belongsTo: null, hasMany: 'reactions' },
};
relationalMapper.createRelations(associationMap, userObj, schema);
const User = schema.define('user', userObj, {
});
const setId = function (self, models) {
// self.addClients(1);
};
User.hooks = {
afterInitialize: [setId],
};
User.prototype.obj = userObj;
User.associationMap = associationMap;
User.prototype.associationMap = associationMap;
return User;
};
modelRules.js:
function addModelBelongsTo(modelName, models, modelObjKey, modelRelated) {
const restructuredModelName = `memberOf${modelName}`;
const restructuredModelNameCamel = `addMemberOf${modelName}`;
const currentModels = models;
currentModels[modelObjKey].prototype[restructuredModelNameCamel] = function(modelId) {
const self = this;
return new Promise((resolve, reject) => {
if (self[restructuredModelName].indexOf(modelId) <= -1) {
modelRelated.exists(modelId, function(err, exists) {
if (err || !exists) { reject(new Error(err || 'Doesnt exist')); }
console.log(`This:${self}\nrestructuredModelName:${JSON.stringify(self[restructuredModelName])}`);
self[restructuredModelName].push(modelId);
console.log(`This:${self}\nrestructuredModelName:${restructuredModelName}`);
self.save((saveErr) => {
saveErr ? reject(new Error(saveErr)) : resolve(self);
});
});
} else {
reject(new Error(''));
}
});
};
}
I'm new working with MeteorJS dev an app, this is a problem when I'm making the collection of some item in an quick inventory app.
Here is the error:
/home/operador/.meteor/packages/meteor-tool/.1.1.10.1kpywhr++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:245
throw(ex);
^
Error: Invalid definition for active field.
at packages/aldeed_simple-schema/packages/aldeed_simple-schema.js:1328:1
at Function._.each._.forEach (packages/underscore/underscore.js:113:1)
at [object Object].SimpleSchema (packages/aldeed_simple-schema/packages/aldeed_simple-schema.js:1325:1)
at collections/assets.js:16:16
at /home/operador/fijos/.meteor/local/build/programs/server/app/collections/assets.js:64:4
at /home/operador/fijos/.meteor/local/build/programs/server/boot.js:242:10
at Array.forEach (native)
at Function._.each._.forEach (/home/operador/.meteor/packages/meteor-tool/.1.1.10.1kpywhr++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/server-lib/node_modules/underscore/underscore.js:79:11)
at /home/operador/fijos/.meteor/local/build/programs/server/boot.js:137:5
Exited with code: 8
Your application is crashing. Waiting for file change.
And this is the assets.js:
Assets = new Mongo.Collection('assets')
Assets.allow({
insert: function(userId, userLvl, doc) {
return !!userId;
}
});
Brands = new SimpleSchema({
name: {
type: String,
label: "Brand"
}
});
Assetsschema = new SimpleSchema({
item: {
type: String,
label: "item"
},
year: {
type: Date,
label: "year"
},
model: {
type: String,
label: "model"
},
serialNumber: {
type: String,
label: "serialNumber"
},
brand: {
type: [Brands]
},
adquarance: {
type: Date,
label: "adquaranceDate"
},
codebar: {
type: String,
label: "codebar"
},
qrcode: {
type: String,
label: "QRcode"
},
active: {
type: Boolean,
label: "active",
autoValue: true
}
});
IDK how to fix the problem, I've tried to change the name of the schema but that gave me the same results.
This is my package list:
kadira:flow-router
kadira:blaze-layout
erasaur:meteor-lodash
fortawesome:fontawesome
spiderable
fastclick
raix:handlebar-helpers
aldeed:collection2
aldeed:autoform
accounts-ui
accounts-password
matb33:bootstrap-glyphicons
zimme:active-route
gwendall:auth-client-callbacks
meteortoys:allthings
datariot:ganalytics
bootswatch:paper
numtel:mysql
hitchcott:qr-scanner
The option autoValue allows you to specify a function. As a consequence, your Schema should be structured as follows:
Assetsschema = new SimpleSchema({
item: {
type: String,
label: "item"
},
year: {
type: Date,
label: "year"
},
model: {
type: String,
label: "model"
},
serialNumber: {
type: String,
label: "serialNumber"
},
brand: {
type: [Brands]
},
adquarance: {
type: Date,
label: "adquaranceDate"
},
codebar: {
type: String,
label: "codebar"
},
qrcode: {
type: String,
label: "QRcode"
},
active: {
type: Boolean,
label: "active",
autoValue: function () {
return true;
}
}
});
I have some jquery like this...
init: function () {
var self = this;
this.dataSource = new kendo.data.DataSource({
transport: {
read: {
url: $.url.action(self.controller, self.action, { projectId: projectId }),
cache: false,
dataType: "json"
}
},
schema: {
model: {
id: "StudyId",
fields: {
Name: { type: "string" },
ViewName: { type: "string" },
Description: { type: "string" },
ViewDescription: { type: "string" },
UpdateDate: { type: "date" },
StudyId: { type: "number" },
NextMilestoneName: { type: "string" },
NextMilestoneDate: { type: "date" },
StudyStatus: { type: "string"}
}
}
},
sort: { field: "UpdateDate", dir: "desc" },
sortable: { mode: "single", allowUnsort: false },
pageSize: 4
});
I want to conditionally display this depending on if ViewDescription is empty...
#if (!String.IsNullOrEmpty(????))
{
<span><strong>#Resources.Resources.Description1 </strong>#:ViewDescription#</span>
<br>
}
I can't figure it out! what do i put into the ????'s to access the ViewDescription?
Based on what you posted, it seems that you are trying to leverage a razor view based on information that wont exist until after the page loads, even until that Kendo control call "Read()". That Razor view will be built before that javascript has executed. However, after that code executes, you can do something like this in JS.
(Also check here: http://docs.telerik.com/kendo-ui/api/framework/datasource#events-change)
init: function () {
var self = this;
this.dataSource = new kendo.data.DataSource({
transport: {
read: {
url: $.url.action(self.controller, self.action, { projectId: projectId }),
cache: false,
dataType: "json"
}
},
change: function(e) {
if(e.items["ViewDescription"]!=null){
$("#IDofDivHere").append("<span><strong>#Resources.Resources.Description1</strong>"+e.items["ViewDescription"]+"</span><br>");
}
},
schema: {
model: {
id: "StudyId",
fields: {
Name: { type: "string" },
ViewName: { type: "string" },
Description: { type: "string" },
ViewDescription: { type: "string" },
UpdateDate: { type: "date" },
StudyId: { type: "number" },
NextMilestoneName: { type: "string" },
NextMilestoneDate: { type: "date" },
StudyStatus: { type: "string"}
}
}
},
sort: { field: "UpdateDate", dir: "desc" },
sortable: { mode: "single", allowUnsort: false },
pageSize: 4
});
So we are wiring up the kendo event change that should get fired when the data is retrieved (like a success callback in ajax), and then appending the data you wanted wherever you want it to go