-
-
Notifications
You must be signed in to change notification settings - Fork 961
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Initial setup * simplified creation * added readme.md file
- Loading branch information
1 parent
446f929
commit ae9d1d0
Showing
25 changed files
with
1,185 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
const MongooseInstance = require('mongoose').Mongoose; | ||
const logger = require('logger'); | ||
const MessageChat = require('./schema/Chat'); | ||
const Comment = require('./schema/Comment'); | ||
const DirectChat = require('./schema/DirectChat'); | ||
const DirectChatMessage = require('./schema/DirectChatMessage'); | ||
const Event = require('./schema/Event'); | ||
const EventProject = require('./schema/EventProject'); | ||
const File = require('./schema/File'); | ||
const Group = require('./schema/Group'); | ||
const GroupChat = require('./schema/GroupChat'); | ||
const GroupChatMessage = require('./schema/GroupChatMessage'); | ||
const ImageHash = require('./schema/ImageHash'); | ||
const Language = require('./schema/Language'); | ||
const MembershipRequest = require('./schema/MembershipRequest'); | ||
const Message = require('./schema/Message'); | ||
const Organization = require('./schema/Organization'); | ||
const Plugin = require('./schema/Plugin'); | ||
const PluginField = require('./schema/PluginField'); | ||
const Post = require('./schema/Post'); | ||
const Task = require('./schema/Task'); | ||
const User = require('./schema/User'); | ||
|
||
const defaultSchema = { | ||
MessageChat, | ||
Comment, | ||
DirectChat, | ||
DirectChatMessage, | ||
Event, | ||
EventProject, | ||
File, | ||
Group, | ||
GroupChat, | ||
GroupChatMessage, | ||
ImageHash, | ||
Language, | ||
MembershipRequest, | ||
Message, | ||
Organization, | ||
Plugin, | ||
PluginField, | ||
Post, | ||
Task, | ||
User, | ||
}; | ||
|
||
function MongoDB(url, schemaObjects) { | ||
this.mongo = new MongooseInstance(); | ||
this.schema = schemaObjects ? schemaObjects : defaultSchema; | ||
|
||
this.type = 'Mongoose'; | ||
this.Native = this.mongo.connection.db; | ||
this.connect = async () => { | ||
try { | ||
await this.mongo.connect(url, { | ||
useCreateIndex: true, | ||
useUnifiedTopology: true, | ||
useFindAndModify: false, | ||
useNewUrlParser: true, | ||
}); | ||
this.Native = this.mongo.connection.db; | ||
} catch (error) { | ||
logger.error('Error while connecting to mongo database', error); | ||
process.exit(1); | ||
} | ||
}; | ||
this.disconnect = async () => { | ||
await this.mongo.connection.close(); | ||
}; | ||
// creating the schema | ||
for (let key in this.schema) { | ||
this[key] = this.mongo.model(key, this.schema[key]); | ||
} | ||
} | ||
|
||
module.exports = MongoDB; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const mongoose = require('mongoose'); | ||
const Schema = mongoose.Schema; | ||
|
||
const chatSchema = new Schema({ | ||
message: { | ||
type: String, | ||
required: true, | ||
}, | ||
languageBarrier: { | ||
type: Boolean, | ||
required: false, | ||
default: false, | ||
}, | ||
sender: { | ||
type: Schema.Types.ObjectId, | ||
ref: 'User', | ||
required: true, | ||
}, | ||
receiver: { | ||
type: Schema.Types.ObjectId, | ||
ref: 'User', | ||
required: true, | ||
}, | ||
createdAt: { | ||
type: Date, | ||
required: true, | ||
default: Date.now, | ||
}, | ||
}); | ||
module.exports = chatSchema; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const mongoose = require('mongoose'); | ||
const Schema = mongoose.Schema; | ||
|
||
//this is the Structure of the Comments | ||
const commentSchema = new Schema({ | ||
text: { | ||
type: String, | ||
required: true, | ||
}, | ||
createdAt: { | ||
type: Date, | ||
default: Date.now, | ||
}, | ||
creator: { | ||
type: Schema.Types.ObjectId, | ||
ref: 'User', | ||
required: true, | ||
}, | ||
post: { | ||
type: Schema.Types.ObjectId, | ||
ref: 'Post', | ||
required: true, | ||
}, | ||
likedBy: [ | ||
{ | ||
type: Schema.Types.ObjectId, | ||
ref: 'User', | ||
}, | ||
], | ||
likeCount: { | ||
type: Number, | ||
default: 0, | ||
}, | ||
status: { | ||
type: String, | ||
required: true, | ||
default: 'ACTIVE', | ||
enum: ['ACTIVE', 'BLOCKED', 'DELETED'], | ||
}, | ||
}); | ||
|
||
module.exports = commentSchema; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const mongoose = require('mongoose'); | ||
|
||
const Schema = mongoose.Schema; | ||
|
||
//this is the Structure of the direct chat | ||
const directChatSchema = new Schema({ | ||
users: [ | ||
{ | ||
type: Schema.Types.ObjectId, | ||
ref: 'User', | ||
required: true, | ||
}, | ||
], | ||
messages: [ | ||
{ | ||
type: Schema.Types.ObjectId, | ||
ref: 'DirectChatMessage', | ||
}, | ||
], | ||
creator: { | ||
type: Schema.Types.ObjectId, | ||
ref: 'User', | ||
required: true, | ||
}, | ||
organization: { | ||
type: Schema.Types.ObjectId, | ||
ref: 'Organization', | ||
required: true, | ||
}, | ||
status: { | ||
type: String, | ||
required: true, | ||
default: 'ACTIVE', | ||
enum: ['ACTIVE', 'BLOCKED', 'DELETED'], | ||
}, | ||
}); | ||
|
||
module.exports = directChatSchema; |
38 changes: 38 additions & 0 deletions
38
lib/Database/MongoImplementation/schema/DirectChatMessage.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const mongoose = require('mongoose'); | ||
|
||
const Schema = mongoose.Schema; | ||
|
||
//this is the Structure of the Direct chats | ||
const directChatMessageSchema = new Schema({ | ||
directChatMessageBelongsTo: { | ||
type: Schema.Types.ObjectId, | ||
ref: 'DirectChat', | ||
required: true, | ||
}, | ||
sender: { | ||
type: Schema.Types.ObjectId, | ||
ref: 'User', | ||
required: true, | ||
}, | ||
receiver: { | ||
type: Schema.Types.ObjectId, | ||
ref: 'User', | ||
required: true, | ||
}, | ||
createdAt: { | ||
type: Date, | ||
required: true, | ||
}, | ||
messageContent: { | ||
type: String, | ||
required: true, | ||
}, | ||
status: { | ||
type: String, | ||
required: true, | ||
default: 'ACTIVE', | ||
enum: ['ACTIVE', 'BLOCKED', 'DELETED'], | ||
}, | ||
}); | ||
|
||
module.exports = directChatMessageSchema; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
const mongoose = require('mongoose'); | ||
const Schema = mongoose.Schema; | ||
const UserAttendes = require('./UserAttendes'); | ||
|
||
//this is the Structure of the event | ||
const eventSchema = new Schema({ | ||
title: { | ||
type: String, | ||
required: true, | ||
}, | ||
description: { | ||
type: String, | ||
required: true, | ||
}, | ||
attendees: { | ||
type: String, | ||
required: false, | ||
}, | ||
location: { | ||
type: String, | ||
}, | ||
recurring: { | ||
type: Boolean, | ||
required: true, | ||
default: false, | ||
}, | ||
allDay: { | ||
type: Boolean, | ||
required: true, | ||
}, | ||
startDate: { | ||
type: String, | ||
required: true, | ||
}, | ||
endDate: { | ||
type: String, | ||
required: function () { | ||
return !this.allDay; | ||
}, | ||
}, | ||
startTime: { | ||
type: String, | ||
required: function () { | ||
return !this.allDay; | ||
}, | ||
}, | ||
endTime: { | ||
type: String, | ||
required: function () { | ||
return !this.allDay; | ||
}, | ||
}, | ||
recurrance: { | ||
type: String, | ||
default: 'ONCE', | ||
enum: ['DAILY', 'WEEKLY', 'MONTHLY', 'YEARLY', 'ONCE'], | ||
required: function () { | ||
return this.recurring; | ||
}, | ||
}, | ||
isPublic: { | ||
type: Boolean, | ||
required: true, | ||
}, | ||
isRegisterable: { | ||
type: Boolean, | ||
required: true, | ||
}, | ||
creator: { | ||
type: Schema.Types.ObjectId, | ||
ref: 'User', | ||
required: true, | ||
}, | ||
registrants: [UserAttendes], | ||
admins: [ | ||
{ | ||
type: Schema.Types.ObjectId, | ||
ref: 'User', | ||
required: true, | ||
}, | ||
], | ||
organization: { | ||
type: Schema.Types.ObjectId, | ||
ref: 'Organization', | ||
required: true, | ||
}, | ||
tasks: [ | ||
{ | ||
type: Schema.Types.ObjectId, | ||
ref: 'Task', | ||
}, | ||
], | ||
status: { | ||
type: String, | ||
required: true, | ||
default: 'ACTIVE', | ||
enum: ['ACTIVE', 'BLOCKED', 'DELETED'], | ||
}, | ||
}); | ||
|
||
module.exports = eventSchema; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
const mongoose = require('mongoose'); | ||
|
||
const Schema = mongoose.Schema; | ||
|
||
//this is the Structure of the event project | ||
const eventProjectSchema = new Schema({ | ||
title: { | ||
type: String, | ||
required: true, | ||
}, | ||
description: { | ||
type: String, | ||
required: true, | ||
}, | ||
createdAt: { | ||
type: Date, | ||
default: Date.now, | ||
}, | ||
event: { | ||
type: Schema.Types.ObjectId, | ||
ref: 'Event', | ||
required: true, | ||
}, | ||
creator: { | ||
type: Schema.Types.ObjectId, | ||
ref: 'User', | ||
required: true, | ||
}, | ||
tasks: [ | ||
{ | ||
type: Schema.Types.ObjectId, | ||
ref: 'Task', | ||
}, | ||
], | ||
status: { | ||
type: String, | ||
required: true, | ||
default: 'ACTIVE', | ||
enum: ['ACTIVE', 'BLOCKED', 'DELETED'], | ||
}, | ||
}); | ||
|
||
module.exports = eventProjectSchema; |
Oops, something went wrong.