From a7959fdff266a02fd001a3a33ff00c8a8f2b61f5 Mon Sep 17 00:00:00 2001 From: Ranil Wallace Date: Fri, 26 Jun 2020 13:16:53 -0500 Subject: [PATCH] Added group chat model --- models/Group.js | 28 ++++++++++++++++++++++++++++ models/Message.js | 5 +++++ schema.graphql | 1 - 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 models/Group.js diff --git a/models/Group.js b/models/Group.js new file mode 100644 index 0000000000..df1c43990b --- /dev/null +++ b/models/Group.js @@ -0,0 +1,28 @@ +const mongoose = require("mongoose"); + +const Schema = mongoose.Schema; + +const groupSchema = new Schema({ + title: { + type: String, + required: true, + }, + description: { + type: String, + }, + createdAt: { type: Date, default: Date.now }, + organization: { + type: Schema.Types.ObjectId, + ref: "Organization", + required: true, + }, + admins: [ + { + type: Schema.Types.ObjectId, + ref: "User", + required: true, + }, + ], +}); + +module.exports = mongoose.model("Group", groupSchema); diff --git a/models/Message.js b/models/Message.js index 8989600435..e57e2159df 100644 --- a/models/Message.js +++ b/models/Message.js @@ -26,6 +26,11 @@ const messageSchema = new Schema({ ref: "Organization", required:true }, + group: { + type: Schema.Types.ObjectId, + ref: "Group", + required:true + }, }) module.exports = mongoose.model("Message", messageSchema); diff --git a/schema.graphql b/schema.graphql index 428b45f32a..7c57535c06 100644 --- a/schema.graphql +++ b/schema.graphql @@ -155,7 +155,6 @@ const typeDefs = gql` imageUrl: String videoUrl:String creator: User - organization: Organization } input PostInput {