|
@@ -51,6 +51,10 @@ module.exports = async (dbName='graphql-chat') => {
|
|
|
delete: []
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ static get guestRelations(){
|
|
|
+ return ["chats"];
|
|
|
+ }
|
|
|
}
|
|
|
SlicedSavable.addClass(User)
|
|
|
|
|
@@ -110,6 +114,19 @@ module.exports = async (dbName='graphql-chat') => {
|
|
|
SlicedSavable.addClass(Media)
|
|
|
|
|
|
class Message extends OwnerSlicedSavable {
|
|
|
+
|
|
|
+ async save(...params){
|
|
|
+ if (!this.chat){
|
|
|
+ throw new RefernceError("You should set chat")
|
|
|
+ }
|
|
|
+ const chatId = this.chat._id.toString()
|
|
|
+
|
|
|
+ this.___permissions.read.push(chatId)
|
|
|
+ this.___permissions.read = [...new Set(this.___permissions.read)]
|
|
|
+
|
|
|
+ return await super.save(...params)
|
|
|
+ }
|
|
|
+
|
|
|
static get relations(){
|
|
|
return {
|
|
|
media: ['messages'],
|
|
@@ -123,8 +140,8 @@ module.exports = async (dbName='graphql-chat') => {
|
|
|
|
|
|
static get defaultPermissions(){
|
|
|
return {
|
|
|
- create: ['user'],
|
|
|
- read: ['owner', 'user', 'admin'],
|
|
|
+ create: ['user', 'admin'],
|
|
|
+ read: ['user', 'owner', 'admin'],
|
|
|
write: ['owner','admin'],
|
|
|
delete: ['admin']
|
|
|
}
|
|
@@ -140,6 +157,15 @@ module.exports = async (dbName='graphql-chat') => {
|
|
|
class Chat extends OwnerSlicedSavable {
|
|
|
constructor(...params){
|
|
|
super(...params)
|
|
|
+ this.members = Savable.arrize(this.members)
|
|
|
+ }
|
|
|
+
|
|
|
+ async save(...params){
|
|
|
+ if (!this._id){
|
|
|
+ await super.save(...params)
|
|
|
+ this.___permissions.read.push(this._id)
|
|
|
+ }
|
|
|
+ return await super.save(...params)
|
|
|
}
|
|
|
|
|
|
static get relations(){
|
|
@@ -153,13 +179,17 @@ module.exports = async (dbName='graphql-chat') => {
|
|
|
static get defaultPermissions(){
|
|
|
return {
|
|
|
create: ['user'],
|
|
|
- read: ['owner', 'admin'],
|
|
|
+ read: ['owner', 'admin', 'user'],
|
|
|
write: ['owner'],
|
|
|
delete: []
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ static get guestRelations(){
|
|
|
+ return ['messages']
|
|
|
+ }
|
|
|
}
|
|
|
- SlicedSavable.addClass(TimeTrack)
|
|
|
+ SlicedSavable.addClass(Chat)
|
|
|
|
|
|
const thisUser = id !== 'anon' && await Savable.m.User.findOne({_id: ObjectID(id)})
|
|
|
|