Browse Source

user model added; message model changed; tag model added

master
Senta Mandutz 5 years ago
parent
commit
8341ed24d0
6 changed files with 62 additions and 16 deletions
  1. 2
    1
      message.model.js
  2. 3
    0
      mong.js
  3. 25
    4
      public/routes/home.js
  4. 22
    10
      server.js
  5. 8
    0
      tag.model.js
  6. 2
    1
      user.model.js

+ 2
- 1
message.model.js View File

@@ -7,8 +7,9 @@ const MessageSchema = mongoose.Schema({
subject: { type: String, required: true },
message: { type: String, required: true },
user: { type: String, required: true },
tag: [{type: String, index: true }],
tag: [{type: String }],
//createtime: { type: Date, default: Date.now },
});
MessageSchema.index({tag:'text'});

module.exports = mongoose.model('Message', MessageSchema);

+ 3
- 0
mong.js View File

@@ -0,0 +1,3 @@
db = db.getSiblingDB('test')

print(db.getCollectionNames())

+ 25
- 4
public/routes/home.js View File

@@ -31,10 +31,23 @@ const HomeRouter = {
_messagelist.push.apply(_messagelist, jd);
console.log("jd: "+jd);
for (var e in jd) {
if (!_messages[jd[e]]) {
get_insert_message(jd[e]);
}
if (!_messages[jd[e]]) {
get_insert_message(jd[e]);
}
}
/*if(!($".om-searchbar" = "")){
for (var e in jd) {
if (!_messages[jd[e]]) {
get_insert_message(jd[e]);
}
}
}else{
for (var e in jd) {
if (!_messages[jd[e]]) {
get_search_message(jd[e]);
}
}
}*/
}).fail(function (e, f, g) {
console.log("err: " + e + f + g);
});
@@ -54,7 +67,15 @@ function get_insert_message(id) {
console.log("cannot load " + id + ".json: " + e + f + g);
})
}
/*$(document).ready(function () {

/*function get_search_message(phrase) {
$.ajax({ url: "api/msg/search/"+phrase, method: "GET" }).done(function (msg) {
Vue.set(_messages, id, msg);
}).fail(function (e, f, g) {
console.log("cannot load " + id + ".json: " + e + f + g);
})
}
$(document).ready(function () {
console.log("egal");
$.get('list.json').done(function (jd) {
// _messagelist = jd;

+ 22
- 10
server.js View File

@@ -10,8 +10,7 @@ var common = require ('./server/common'),
dbs = require ('./server/dbs'),
files = require ('./server/files');
*/

const fs = require ('fs'),
var fs = require ('fs'),
http = require ('http'),
https = require ('https'),
express = require ('express'),
@@ -20,7 +19,7 @@ const fs = require ('fs'),
//serveFavicon = require ('serve-favicon'),
bodyParser = require ('body-parser');
//MongoStore = require ('connect-mongo')(session); // uss mongodb as session storage
const Message = require('./message.model.js');
var Message = require('./message.model.js');

var app = express();

@@ -74,33 +73,34 @@ app.use (bodyParser.urlencoded({extended: true}));
//var api_routes = express.Router(); // express app-object routing
//app.use ('/api', api_routes);

app.use (function (req,res,done) {
console.log (req.url);
app.use (function (req, res, done) {
console.log(req.url);
done();
});

//global.__basedir = __dirname;

// Static Files
app.use (express.static(__dirname + '/public')); // Allow server access to 'public' folder
app.use(express.static(__dirname + '/public')); // Allow server access to 'public' folder

//app.use(express.static('resources'));

// Configuring the database
const dbConfig = require('./mongodb.config.js');
const mongoose = require('mongoose');
var dbConfig = require('./mongodb.config.js');
var mongoose = require('mongoose');

mongoose.Promise = global.Promise;

// Connecting to the database
mongoose.connect(dbConfig.url, {useNewUrlParser: true})
.then(() => {
//mongoose.connect(`mongodb://${server}/${dbConfig.url}`)
mongoose.connect(dbConfig.url, {useNewUrlParser: true}).then(() => {
console.log("Successfully connected to MongoDB.");
}).catch(err => {
console.log('Could not connect to MongoDB.');
process.exit();
});


//require('./app/routes/message.route.js')(app);

app.get ('/api/ids', function (req, res) {
@@ -131,6 +131,18 @@ app.get ("/api/msg/:id", function (req, res) {
});
});

/*app.get ("/api/msg/search/:phrase", function (req, res) {
Message.find ({$text: {$search: req.params.phrase}) .then (function (err, results){
if (err) {
console.log (err);
res .status(404) .json (err);
} else {
console.log(JSON.stringify(results));
res.json(results);
}
});
});
*/
/*function makeid() {
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

+ 8
- 0
tag.model.js View File

@@ -0,0 +1,8 @@
const mongoose = require('mongoose');


const TagSchema = mongoose.Schema({
name: { type: String, required: true }, //unique
});

module.exports = mongoose.model('Tag', TagSchema);

+ 2
- 1
user.model.js View File

@@ -3,7 +3,8 @@ const mongoose = require('mongoose');

const UserSchema = mongoose.Schema({
name: { type: String, required: true },
password: {type: String},
password: {type: String}, password: {type: String},

role: {type: String, required: true},
tags: [{type: String }],
});

Loading…
Cancel
Save