Skip to content

Commit

Permalink
Initial setup (#726)
Browse files Browse the repository at this point in the history
* Initial setup

* simplified creation

* added readme.md file
  • Loading branch information
ebrahim354 authored Jul 10, 2022
1 parent 446f929 commit ae9d1d0
Show file tree
Hide file tree
Showing 25 changed files with 1,185 additions and 0 deletions.
76 changes: 76 additions & 0 deletions lib/Database/MongoImplementation/index.js
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;
30 changes: 30 additions & 0 deletions lib/Database/MongoImplementation/schema/Chat.js
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;
42 changes: 42 additions & 0 deletions lib/Database/MongoImplementation/schema/Comment.js
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;
38 changes: 38 additions & 0 deletions lib/Database/MongoImplementation/schema/DirectChat.js
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 lib/Database/MongoImplementation/schema/DirectChatMessage.js
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;
101 changes: 101 additions & 0 deletions lib/Database/MongoImplementation/schema/Event.js
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;
43 changes: 43 additions & 0 deletions lib/Database/MongoImplementation/schema/EventProject.js
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;
Loading

0 comments on commit ae9d1d0

Please sign in to comment.