54 lines
986 B
JavaScript
Executable File
54 lines
986 B
JavaScript
Executable File
const mongoose = require('mongoose').set('debug', false)
|
|
const Schema = mongoose.Schema;
|
|
|
|
mongoose.Promise = global.Promise;
|
|
mongoose.level = "F";
|
|
|
|
const tools = require('../tools/general');
|
|
|
|
const { ObjectId } = require('mongodb');
|
|
|
|
// Resolving error Unknown modifier: $pushAll
|
|
mongoose.plugin(schema => {
|
|
schema.options.usePushEach = true
|
|
});
|
|
|
|
const searchSchema = new Schema({
|
|
idapp: {
|
|
type: String,
|
|
},
|
|
userId: {
|
|
type: String,
|
|
},
|
|
date_created: {
|
|
type: Date,
|
|
default: Date.now,
|
|
},
|
|
text: {
|
|
type: String,
|
|
},
|
|
});
|
|
|
|
searchSchema.statics.findAllByUserIdAndIdApp = function (userId, idapp, sall) {
|
|
const Search = this;
|
|
|
|
let myfind = {};
|
|
if (sall === '1')
|
|
myfind = { idapp };
|
|
else
|
|
myfind = { userId, idapp };
|
|
|
|
return Search.find(myfind, (err, arrsearch) => {
|
|
return arrsearch
|
|
});
|
|
};
|
|
|
|
|
|
const Search = mongoose.model('Search', searchSchema);
|
|
|
|
Search.createIndexes((err) => {
|
|
if (err) throw err;
|
|
});
|
|
|
|
module.exports = { Search };
|