-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(chat): split participantsLog from main ChatRoom schema due t…
…o SQL support (#900)
- Loading branch information
1 parent
e6a110b
commit 87884d3
Showing
4 changed files
with
99 additions
and
46 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,60 @@ | ||
import { ConduitModel, DatabaseProvider, TYPE } from '@conduitplatform/grpc-sdk'; | ||
import { ConduitActiveSchema } from '@conduitplatform/module-tools'; | ||
import { User } from './User.model'; | ||
import { ChatRoom } from './ChatRoom.schema'; | ||
|
||
const schema: ConduitModel = { | ||
_id: TYPE.ObjectId, | ||
action: { | ||
type: TYPE.String, | ||
enum: ['add', 'remove', 'create', 'join', 'leave'], | ||
required: true, | ||
}, | ||
user: { | ||
type: TYPE.Relation, | ||
model: 'User', | ||
required: true, | ||
}, | ||
chatRoom: { | ||
type: TYPE.Relation, | ||
model: 'ChatRoom', | ||
required: true, | ||
}, | ||
createdAt: TYPE.Date, | ||
updatedAt: TYPE.Date, | ||
}; | ||
const modelOptions = { | ||
timestamps: true, | ||
conduit: { | ||
permissions: { | ||
extendable: true, | ||
canCreate: false, | ||
canModify: 'ExtensionOnly', | ||
canDelete: false, | ||
}, | ||
}, | ||
} as const; | ||
const collectionName = undefined; | ||
|
||
export class ChatParticipantsLog extends ConduitActiveSchema<ChatParticipantsLog> { | ||
private static _instance: ChatParticipantsLog; | ||
_id: string; | ||
action: 'add' | 'remove' | 'create' | 'join' | 'leave'; | ||
user: string | User; | ||
chatRoom: string | ChatRoom; | ||
createdAt: Date; | ||
updatedAt: Date; | ||
|
||
private constructor(database: DatabaseProvider) { | ||
super(database, ChatParticipantsLog.name, schema, modelOptions, collectionName); | ||
} | ||
|
||
static getInstance(database?: DatabaseProvider) { | ||
if (ChatParticipantsLog._instance) return ChatParticipantsLog._instance; | ||
if (!database) { | ||
throw new Error('No database instance provided!'); | ||
} | ||
ChatParticipantsLog._instance = new ChatParticipantsLog(database); | ||
return ChatParticipantsLog._instance; | ||
} | ||
} |
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
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
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