Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async create(req, res) {
let body = req.body;
let obj = _.pick(body, 'name', 'email', 'mobile', 'address', 'content');
obj.ip = util.getIp(req);
obj.content = xss(obj.content);
let user = req.user
if (user) {
obj.author = mongoose.Types.ObjectId(user._id)
}
let data;
let error;
try {
data = await messageService.create(obj);
} catch (e) {
// console.log(e);
error = e.message;
}
res.json({
success: !error,
data: data,
error: error
});
}
}
router.get('/ajax/hideNotification', (req, res) => {
console.log('hide nofication');
console.log(req.query.idOfNotif);
// console.log(mongoose.Types.ObjectId(req.query.idOfNotif));
myNotification.findByIdAndRemove(mongoose.Types.ObjectId(req.query.idOfNotif), (err) => {
if (err) {
console.log(err);
}
User.findOne({ username: req.user.username }).populate('notifications').exec(async (err, foundUser) => {
foundUser.markModified('notifications');
await foundUser.save();
});
});
res.status(200).send('done');
});
}
function reverseEntry() {
JournalEntryService.findAndReverse({id: id, dbName: dbIndex, uId: req.session.uId});
}
if (data.invoiceDate) {
date = moment(new Date(data.invoiceDate));
date = date.format('YYYY-MM-DD');
}
if (data.notes && data.notes.length !== 0) {
obj = data.notes[data.notes.length - 1];
if (!obj._id) {
obj._id = mongoose.Types.ObjectId();
}
// obj.date = new Date();
if (!obj.user) {
obj.user = {};
obj.user._id = req.session.uId;
obj.user.login = req.session.uName;
}
data.notes[data.notes.length - 1] = obj;
}
if (data.fileName) {
fileName = data.fileName;
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var ObjectId = Schema.ObjectId;
var mObjectId = mongoose.Types.ObjectId;
var event = require('../Shared/event.js');
var optionSchema = {
name: String,
content: String,
allowAddReasonStatus: {type: Boolean, default: false} // 某一项选择中是否可以用户选择后添加文字说明
}
var gradeSchema = {
step: Number,
begin: Number,
end: Number,
type: String
}
gradeSchema = new Schema(gradeSchema, {versionKey: false, id: false});
function testAddErrorAndCheck()
{
console.log("Starting TestAddErrorAndCheck...");
var mt1 = new Movietheater();
var mt2 = new Movietheater(); mt2._id = (new mongoose.Types.ObjectId).toString(); mt2.city = "city"; mt2.country = "country"; mt2.name = "name";
if (mt1.validateSync() === undefined || Object.values(mt1.validateSync().errors).length !== 4)
console.error("Error: movietheater1 was not correctly validated.");
if (mt2.validateSync() !== undefined)
console.error("Error: movietheater2 was not correctly validated.");
var m1 = new Media(); m1.name = "name1"; m1.url = "url1";
var m2 = new Media(); m2.name = "name2"; m2.url = "url2";
if (m1.validateSync() !== undefined)
console.error("Error: media1 was not correctly validated.");
if (m2.validateSync() !== undefined)
console.error("Error: media2 was not correctly validated.");
var c1 = new Criticism(); c1.color = "color1"; c1.journalist = "journalist1"; c1.media = [m1, m2];
var c2 = new Criticism(); c2.color = "color2"; c2.journalist = "journalist2"; c2.media = "media2";
function testAddErrorAndCheck()
{
console.log("Starting TestAddErrorAndCheck...");
var a1 = new Artist();
var a2 = new Artist(); a2._id = (new mongoose.Types.ObjectId).toString(); a2.name = "name"; a2.startingYear = 1999;
if (a1.validateSync() === undefined || Object.values(a1.validateSync().errors).length !== 3)
console.error("Error: artist1 was not correctly validated.");
if (a2.validateSync() !== undefined)
console.error("Error: artist2 was not correctly validated.");
var m1 = new Media(); m1.name = "name1"; m1.url = "url1"; m1.type = "type1";
var m2 = new Media(); m2.name = "name2"; m2.url = "url2"; m2.type = "type2";
if (m1.validateSync() !== undefined)
console.error("Error: media1 was not correctly validated.");
if (m2.validateSync() !== undefined)
console.error("Error: media2 was not correctly validated.");
var r1 = new Review(); r1.journalist = "journalist1"; r1.rank = "Very good"; r1.media = [m1, m2];
var r2 = new Review(); r2.journalist = "journalist2"; r2.rank = "Poor"; r2.media = "media2";
exports.create_toolbox = (req, res, next) => {
const newToolbox = new Toolbox({
_id: new mongoose.Types.ObjectId(),
name: req.body.name,
displayName: req.body.displayName,
desc: req.body.desc,
category: req.body.category,
usecase: req.body.usecase,
tools: req.body.tools
});
newToolbox
.save()
.then(result => {
console.log(result);
res.status(201).json({
message: "Created toolbox successfully",
createdToolbox: {
_id: result._id,
name: result.name,
return new Promise(function(fulfill, reject) {
if (!userId) reject("recipient user id is missing");
userId = mongoose.Types.ObjectId(userId);
messageId = mongoose.Types.ObjectId(messageId);
if (!userId || !messageId) reject("User or message id is missing. Message deletion failed.");
else
{
MessageModel.remove({ "$and": [ { "$or": [{to: userId}, {from: userId} ] }, {_id: messageId} ] },
function(err, message) {
if (err) {
logger.error("messageService.deleteMessage " + err);
reject("Message deletion failed");
}
else {
fulfill(message);
}
});
}
});