Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Nightrider0098 committed Oct 28, 2020
0 parents commit 0165833
Show file tree
Hide file tree
Showing 10 changed files with 1,586 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
8 changes: 8 additions & 0 deletions DbConnection/Connectors/mongoose.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
let mongoose = require('mongoose');
mongoose.connect('mongodb+srv://Hitesh:MITohnasan@[email protected]/messenger?retryWrites=true&w=majority', { useNewUrlParser: true, useUnifiedTopology: true })
.then(() => { console.log("connection established with mongodb server online"); })
.catch(err => {
console.log("error while connection", err)
});

module.exports = {mongoose}
19 changes: 19 additions & 0 deletions DbConnection/Schema/messageThreadSchema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const { mongoose } = require('../Connectors/mongoose');

// const Schema =
const messageThreadSchema = new mongoose.Schema({
// threadId: String
threadId: { type: String, unique: true },
messageArray: [{
time: { type: Date, default: Date.now },
sender: String,
receiver: String,
seen: { type: Boolean, default: false },
received: { type: Boolean, default: false },
deleted: { type: Boolean, default: false },
message: String
}]

})

module.export = { mongoose, messageThreadSchema };
56 changes: 56 additions & 0 deletions DbConnection/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// const { mongoose, messageThreadSchema } = require("./Schema/messageThreadSchema")
// Schemas are compiled to Model, A model is a class with which we construct documents.
const { mongoose } = require('./Connectors/mongoose');


const messageThreadSchema = new mongoose.Schema({
// threadId: String
threadId: { type: String, unique: true },
messageArray: [{
time: { type: Date, default: Date.now },
sender: String,
receiver: String,
seen: { type: Boolean, default: false },
received: { type: Boolean, default: false },
deleted: { type: Boolean, default: false },
message: String
}]

})


const messageThreadModel = mongoose.model('newTag', messageThreadSchema);



const sendMessage = (details) => {
console.log(details)
let newMessage = new messageThreadModel({
threadId: details.threadId,
messageArray: [
{
time: details.date || (new Date).toUTCString(),
sender: details.sender,
receiver: details.receiver,
message: details.message
}
]
})
console.log(newMessage)
newMessage.save((err) => {
if (err) {
console.log("Error in sending the message!", err)
return false
}
else {

return true
}
})
}



module.exports = { sendMessage };


1 change: 1 addition & 0 deletions client
Submodule client added at 563c12
5 changes: 5 additions & 0 deletions helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const createMessageThread = (data) => {
return "HiteshDinesh"
}

module.exports = { createMessageThread }
Loading

0 comments on commit 0165833

Please sign in to comment.