Error with log4js configuration: must have a property "appenders" of type object - protractor

I am getting Error: Problem with log4js configuration: ({ appenders:
[ { type: 'logLevelFilter',
level: 'INFO',
appenders: { type: 'console' } } ] }) - must have a property "appenders" of type object.
My protractor.conf.js file snippet:
beforeLaunch:function(){
log4js.configure({
appenders:
[{ type: 'log4js-protractor-appender',
category: 'protractorLog4js' },
{
type: "file",
filename: './logs/ExecutionLog.log',
category: 'protractorLog4js'
}
]
});
},
I am not sure why i am getting this error even though there is appenders in the conf.

log4js-node in version 1.x using format like yours:
appenders:[] // Array
but Object in version 2.x like this:
appenders: {
cheeseLogs: { type: 'file', filename: 'cheese.log' },
console: { type: 'console' }
},
categories: {
cheese: { appenders: ['cheeseLogs'], level: 'error' },
another: { appenders: ['console'], level: 'trace' },
default: { appenders: ['console', 'cheeseLogs'], level: 'trace' }
}
https://github.com/nomiddlename/log4js-node

In the new version your appenders would look like this:
appenders: {
fileLog: { type: 'file', filename: './logs/ExecutionLog.log' },
console: { type: 'log4js-protractor-appender' }
},
categories: {
file: { appenders: ['fileLog'], level: 'error' },
another: { appenders: ['console'], level: 'trace' },
default: { appenders: ['console', 'fileLog'], level: 'trace' }
}

Configuration format changed in version 2.x
https://github.com/nomiddlename/log4js-node/issues/500

Related

Strapi Plugin localization

I need help figuring this out
debug: ⛔️ Server wasn't able to start properly.
[2022-09-22 11:30:06.580] error: Cannot read property 'routes' of undefined
TypeError: Cannot read property 'routes' of undefined
at Object.addCreateLocalizationAction
An error comes up when i add localization option for my strapi plugin and this is the content scheme, i installed the i18n but it still didnt work
module.exports = {
kind: "collectionType",
collectionName: "tests",
info: {
singularName: "test",
pluralName: "tests",
displayName: "test"
},
options: {
"draftAndPublish": true
},
pluginOptions: {
i18n: {
localized :true
}
},
attributes: {
name: {
pluginOptions: {
i18n: {
localized: true
}
},
type: "string",
required: true
},
}
}

MongoDB validation part with any one of the field check

Trying to figure out how to validate an array of object and map(key, value) pair
{
"commonIdentification": {
"CR": "BR",
"SN": "NAVS87397394"
}
"digitalIdentiifcation": {
"UUID": "326f040b-cf14-4cf9-9e67-57f7ca3ce1b2"
}
}
Here , I want to add the validation like,
In commonIdentification with the presence of CR ,no need for digitalIdentiifcation's presence
In commonIdentification with the absence of CR, digitalIdentiifcation's 'UUID' field is required.
Can anyone please help on reformatting the validation part?I am struggling to validate based on the above points.
{
$jsonSchema: {
properties: {
commonIdentification: {
type: 'object',
required: [
'CR'
],
properties: {
CR: {
type: 'string',
description: 'CR is mandatory '
}
}
}
},
type: 'object',
required: [
'commonIdentification',
'digitalIdentiifcation'
]
}
}
{
$jsonSchema: {
type: 'object',
required: [
'commonIdentification'
],
anyOf: [
{
required: [
'digitalIdentiifcation'
]
},
{
required: [
'commonIdentification'
]
}
],
properties: {
commonIdentification: {
type: 'object',
anyOf: [
{
required: [
'CR'
]
},
{
required: [
'SN'
]
}
],
properties: {
SN: {
type: 'string',
description: 'SN or CR or digitalIdentiifcation is mandatory '
},
CR: {
type: 'string',
description: 'SN or CR or digitalIdentiifcation is mandatory '
}
},
description: 'SN or CR or digitalIdentiifcation is mandatory '
},
digitalIdentiifcation: {
description: 'digitalIdentiifcation'
}
}
}
}

How do you update a nested array with Mongoose?

This is what I have so far. This is my AnswerSchema with a comments array nested within that I am trying to update.
const AnswerSchema = new Schema({
user: {
type: Schema.Types.ObjectId,
ref: 'user',
},
question: {
type: Schema.Types.ObjectId,
ref: 'question',
},
text: {
type: String,
required: true,
},
name: {
type: String,
},
avatar: {
type: String,
},
views: {
type: Number,
},
date: {
type: Date,
default: Date.now,
},
answerLikes: [
{
user: {
type: Schema.Types.ObjectId,
ref: 'user',
},
},
],
comments: [
{
user: {
type: Schema.Types.ObjectId,
ref: 'user',
},
text: {
type: String,
required: true,
},
name: {
type: String,
},
avatar: {
type: String,
},
commentLikes: [
{
user: {
type: Schema.Types.ObjectId,
ref: 'user',
},
},
],
date: {
type: Date,
default: Date.now,
},
},
],
})
and here is my update route that I am trying to use to update the comments array text field
try {
const updatedAnswer = await Answer.findOneAndUpdate(
{ _id: req.params.answer_id },
{
$set: { 'comments.$[comment].text': formattedAnswer },
},
{
arrayFilters: [{'comment._id': req.params.comment_id }],
},
{ new: true }
)
res.json(updatedAnswer)
I keep getting the error 'Callback must be a function, got [object Object]' and cant figure out a fix.
Any ideas?
Thanks!
The problem in your code is that you are passing 4 parameters to the findOneAndUpdate function.
The 4th argument is a callback which accepts a function:
(err /* an error if occurred */, doc /* the updated document */) => {}
In order to solve that you need to combine your last 2 arguments into one object like:
{
arrayFilters: [{'comment._id': req.params.comment_id }],
new: true
}
Final query:
const updatedAnswer = await Answer.findOneAndUpdate(
{ _id: req.params.answer_id },
{
$set: { 'comments.$[comment].text': formattedAnswer },
},
{
arrayFilters: [{'comment._id': req.params.comment_id }],
new: true
}
)
The 4th argument in findOneAndUpdate function takes in a callback function that was where your error was.
Try this
try{
const updatedAnswer = await Answer.findOneAndUpdate(
{ _id: req.params.answer_id },
{
$set: { 'comments.$[comment].text': formattedAnswer },
},
{
arrayFilters: [{'comment._id': req.params.comment_id }],
new: true
}
);
res.json(updatedAnswer);
}catch(err){
//console.log(err)
}

sails update the doc, nothing happen, not err message

eventController:
newHelper: function(req, res) {
const eventID = req.body.eventID;
let newHelper = req.body.newHelper;
newHelper.eventAssoc = eventID;
Wapphelprecords.create(newHelper).exec(function(err, newhelper) {
if (err) {
return res.serverError(err); }
sails.log('add new helper:', newhelper);
return res.json(newhelper);
});
}
when I do this action, the database nothing happen, and no err message, this is model under blow:
WappeventController model:
module.exports = {
attributes: {
eventID: {
type: 'integer',
// autoIncrement: true,
unique: true,
// defaultsTo: 0
},
openid: {
type: 'string',
},
author: {
model: 'wappuserinfo'
},
content: {
type: 'string'
},
allowShare: {
type: 'boolean'
},
imageList: {
type: 'array'
},
money: {
type: 'float',
},
helpers: {
collection: 'wapphelprecords',
via: 'eventAssoc',
},
bestHelper: {
collection: 'wapphelprecords',
via: 'eventAssoc',
}
},
Wapphelprecords Model:
module.exports = {
attributes: {
eventAssoc: {
model: 'wappevents',
},
content: {
type: 'string'
},
contact: {
type: 'string'
},
userInfo: {
model: 'wappuserinfo'
},
bestHelper: {
type: 'boolean'
},
moneyEarn: {
type: 'float'
}
}
};
when I do newHelper action, the database nothing happened, and nothing error notice, I just do not understand. need help, thx.
spend whole day to fix it, and finally:
module.exports = {
attributes: {
eventID: {
type: 'integer',
// autoIncrement: true,
primaryKey: true, //<---- set this primarkey to true
unique: true,
// defaultsTo: 0
},
openid: {
type: 'string',
},
author: {
model: 'wappuserinfo'
},
content: {
type: 'string'
},
allowShare: {
type: 'boolean'
},
imageList: {
type: 'array'
},
money: {
type: 'float',
},
helpers: {
collection: 'wapphelprecords',
via: 'eventAssoc',
},
bestHelper: {
collection: 'wapphelprecords',
via: 'eventAssoc',
}
},

ValidatorError: Cannot read property 'options' of undefined on undefined field

I have Shape and ShapeOrientation models. A shape can have many shape orientations. So my models are as follows:
var shapeSchema = new mongoose.Schema({
name: { type: String },
mfrID: { type: String },
category: { type: mongoose.Schema.Types.ObjectId, ref: 'ShapeCategory' },
brand: { type: mongoose.Schema.Types.ObjectId, ref: 'ShapeBrand' },
available: { type: Boolean, default: false },
related: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Shape' }],
orientations: [{ type: mongoose.Schema.Types.ObjectId, ref: 'ShapeOrientation' }],
owner: { type: mongoose.Schema.Types.ObjectId, ref: 'User' },
open: { type: Boolean, default: true },
thumb: { type: String },
thumbMime: { type: String },
thumbPath: { type: String },
shapeid: { type: String },
desc: { type: String },
verified: { type: Boolean, default: true }
My Shape Orientation Schema is thus:
var shapeOrientationSchema = new mongoose.Schema({
name: { type: String },
data: { type: String },
shape: { type: mongoose.Schema.Types.ObjectId, ref: 'Shape' },
shapeid: { type: String },
length: { type: Number },
width: { type: Number },
depth: { type: Number },
thumb: { type: String },
thumbMime: { type:String }
});
When I try to populate my shape orientations and shape at the same time for a massive import.
ShapeOrientation.insertMany(orientations)
.then(function(manyDocs){
console.log('hooked up and saved orientations.');
async.eachSeries(manyDocs, function(orientDoc, orientDone) {
Shape.findOne({shapeid: orientDoc.shapeid})
.then(function(foundShape){
foundShape.orientations.push(orientDoc._id);
foundShape.save(function(err) {
if(err) {
console.log('shape', foundShape)
console.log('cannot save shape', err)
orientDone();
return;
} else {
orientDone();
}
console.log('saved shape')
})
})
})
I get the following error on an undefined field of mongo.
cannot save shape { [ValidationError: Shape validation failed]
message: 'Shape validation failed',
name: 'ValidationError',
errors:
{ undefined:
{ [ValidatorError: Cannot read property 'options' of undefined]
properties: [Object],
message: 'Cannot read property \'options\' of undefined',
name: 'ValidatorError',
kind: 'cast',
path: undefined,
value: undefined } } }
I don't seem to have any required fields and I am just trying to save the related data while I populate the orientation.
Both _.id's of the Shape and the Orientation exist so I don't understand why it won't save.