Browse Source

everything i working

pull/1/head
Senta Mandutz 5 years ago
parent
commit
31f1add35d
4 changed files with 44 additions and 18 deletions
  1. 10
    0
      message.model.js
  2. 7
    7
      public/createMessage.js
  3. 1
    0
      public/home.js
  4. 26
    11
      server.js

+ 10
- 0
message.model.js View File

@@ -1,6 +1,16 @@
const mongoose = require('mongoose');

//const Schema = mongoose.Schema,
//ObjectId = Schema.ObjectId;

const MessageSchema = mongoose.Schema({
//_id: ObjectId,
/*id: {
type: String,
getter: function(val) { return this._id.toString(); },
unique: true
},*/
//id: {type: String, required: true},
subject: { type: String, required: true },
message: { type: String, required: true },
user: { type: String, required: true },

+ 7
- 7
public/createMessage.js View File

@@ -5,19 +5,19 @@ const CreateMsgRouter = {
<form class="new-msg-form" @submit.prevent=createMsg>
<div class="form-group bmd-form-group">
<label class="bmd-label-floating">Betreff</label>
<input type="text" class="form-control" id="subject">
<input type="text" class="form-control" id="subject" value="WICHTIG!">
</div>
<div class="form-group bmd-form-group">
<label class="bmd-label-floating">Tags</label>
<input type="text" class="form-control" id="tag">
<input type="text" class="form-control" id="tag" value="#efi">
</div>
<div class="form-group">
<label class="bmd-label-floating">Nachricht</label>
<textarea class="form-control" id="message" rows="5"></textarea>
<textarea class="form-control" id="message" rows="5">Nachricht</textarea>
</div>
<div class="form-group">
<label class="bmd-label-floating">User</label>
<textarea class="form-control" id="user"></textarea>
<input type="text" class="form-control" id="user" value="Dito27">
</div>
<div class="form-group">
<div class="checkbox">
@@ -40,13 +40,13 @@ const CreateMsgRouter = {
var message=$("#message").val();
var tag=$("#tag").val();
var user=$("#user").val();
console.log ("Message Created: "+id+" "+tag+" "+message+" "+user);
$.ajax ({ url: "/api/createMsg", data: {subject: subject, tag: tag, message: message, user: user}, method: "POST" }) .done (have_result) .fail (have_error);
console.log ("Message Created: "+tag+" "+message+" "+user);
$.ajax ({ url: "/api/createMsg", data: {sub: subject, mess: message, use: user, ta: tag}, method: "POST" }) .done (have_result) .fail (have_error);
function have_result (res) {
console.log (res);
}
function have_error (err) {
console.log ("error:" + err.responseText);
console.log ("error: " + err.responseText);
console.log (err);
}
},

+ 1
- 0
public/home.js View File

@@ -29,6 +29,7 @@ const HomeRouter = {
// NICHT SO wg. Vue: _messagelist = jd;
_messagelist.splice(0, _messagelist.length);
_messagelist.push.apply(_messagelist, jd);
console.log("jd: "+jd);
for (var e in jd) {
if (!_messages[jd[e]]) {
get_insert_message(jd[e]);

+ 26
- 11
server.js View File

@@ -103,14 +103,14 @@ mongoose.connect(dbConfig.url)

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


app.get ('/api/ids', function (req, res) {
Message.find({},{_id: true}) .exec () .then(results => {
/* selects id from message: var parsed = [];
Message.find({},{id: true}) .exec () .then(results => {
//selects id from message:
var parsed = [];
for (var i in results) {
parsed.push (results[i]._id);
} */
var parsed = results.map (x => x._id);
parsed.push (results[i].id);
}
//var parsed = results.map (x => x._id);
res.send(parsed);
} )
.catch(err => {
@@ -131,14 +131,29 @@ app.get ("/api/msg/:id", function (req, res) {
});
});

function makeid() {
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

for (var i = 0; i < 5; i++)
text += possible.charAt(Math.floor(Math.random() * possible.length));

return text;
}

app.post("/api/createMsg", function(req, res){
var message = new Message(req.body);
//x = mongoose.Types.ObjectId();
//y = x.toString();
//var z = makeid();
console.log("SUbject: "+JSON.stringify(req.body));
var message = new Message( {subject: req.body.sub, message: req.body.mess, user: req.body.use, tag: req.body.ta } );

message.save(function(err,result){
if(err)
return res .status(401) .send(err.message);

res.json({message: "Message created!!"});
if(err){
return res .status(401) .send(err.message);
}else{
res.json({message: "Message created!!"});
}
});
});


Loading…
Cancel
Save