Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dbModel no such file or directory error #11

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 24 additions & 10 deletions src/tours/createDBModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,28 @@ export default async function createDBModel(): Promise<ITours> {
},
{
title: "Messages Model",
file: 'apps/meteor/server/models/raw/Messages.ts',
file: 'packages/models/src/models/Messages.ts',
description:
"## Messages Model\n\n- **Firstly we start by importing some important components and modules such as BaseRaw which contains Operations related to Database model.**\n\n- **We have *Rooms* model imported from *@rocket.chat/models* which is again a model like we are looking at right now, Checkout [Rooms](./apps/meteor/server/models/raw/Rooms.ts) Model**\n\n- **We also have imports from model-typings such as FindPaginated and IMessageModel which have type definitions for the model**\n\n- **We have multiple imports from mongodb as *AggregationCursor, Collection, FindCursor, UpdateResult, etc.* which help in mongodb operations**",
searchString: 'type DeepWritable',
offset: -1,
},
{
title: "MessagesRaw Class",
file: 'apps/meteor/server/models/raw/Messages.ts',
file: 'packages/models/src/models/Messages.ts',
description:
"## MessagesRaw class\n\n- **To register a DB model in Rocket.Chat, it is necessary to create a corresponding class for that model. In our case, as we are creating the Messages Model, we need to define a class specifically for it. This class will serve as the blueprint for the Messages Model and will be used for registering and interacting with the corresponding data in the database.**\n\n- **In order to facilitate the management of the Messages Model in Rocket.Chat's database, we have a class called MessageRaw. This class extends the BaseRaw class and implements the IMessageModel interface, which we discussed earlier. By extending BaseRaw and implementing the IMessageModel interface, MessageRaw inherits necessary functionalities and ensures it adheres to the required structure and behavior of the Messages Model in Rocket.Chat.**",
searchString: 'export class MessagesRaw',
},
{
title: "Collection name",
file: "apps/meteor/server/models/raw/Messages.ts",
file: 'packages/models/src/models/Messages.ts',
description: "```javascript\nsuper(db, 'message', trash);\n```\n\nThe name of our mongodb collection will be **rocketchat_message**. You can open mongodb compass and check all the collections with its respective contents.",
searchString: "super(db, 'message', trash);",
},
{
title: "Methods and Operations",
file: 'apps/meteor/server/models/raw/Messages.ts',
file: 'packages/models/src/models/Messages.ts',
description:
"## Methods and Operations\n\n### From here onwards there are multiple methods and operations related with Message Model you can go through each of them and try to undestand what are they doing, It is easy to understand them.\n\n- **There are multiple methods such as**\n - ***findStarredByUserAtRoom***\n - ***findLivechatMessages***\n - ***findStarred***\n - ***setMessageAttachments***\n - ***getMessageByFileIdAndUsername***\n - and many more",
searchString:
Expand All @@ -46,17 +46,31 @@ export default async function createDBModel(): Promise<ITours> {
},
{
title: "Registering a DB model 1",
file: 'apps/meteor/server/models/Messages.ts',
file: 'apps/meteor/server/models.ts',
description:
"## Registering a DB model\n\n### Now let us see how can we register any DB model\n\n### 1 - First of all we need to import *registerModel* from *@rocket.chat/models*\n\n### 2 - Import MessagesRaw- The DB model Class we created which includes operations, and we are also importing db, trashCollection- It contains deleted messages",
searchString: "registerModel",
"## Registering a DB model\n\n### Now let us see how can we register any DB model\n\n### 1 - First of all we need to import *registerModel* from *@rocket.chat/models*",
searchString: "registerModel,",
},
{
title: "Registering a DB model 2",
file: 'apps/meteor/server/models/Messages.ts',
file: 'apps/meteor/server/models.ts',
description:
"## Registering\n\n### Here we are using the registerModel import and passing 'IMessageModel' and then we pass in db and trashCollection into MessageRaw Class\n\n### The register model function looks something like this -\n```\nfunction registerModel<TModel extends IBaseModel<any, any, any>>(name: string, instance: TModel | (() => TModel)): void;\n```\n\n### And we pass data into it like - \n```\n registerModel('IMessagesModel', new MessagesRaw(db, trashCollection));\n //It becomes something like this, Here IMessageModel is basically implemented in MessagesRaw as we saw in previous steps\n registerModel<MessagesRaw>(name: string, instance: MessagesRaw | (() => MessagesRaw)): void\n```",
searchString: "registerModel(",
"### 2 - Import MessagesRaw- The DB model Class we created which includes operations, and we are also importing db, trashCollection- It contains deleted messages",
searchString: "MessagesRaw,",
},
{
title: "Registering a DB model 3",
file: 'apps/meteor/server/models.ts',
description:
"### 3 - we are also importing db, trashCollection- It contains deleted messages",
searchString: "import { db",
},
{
title: "Registering a DB model 4",
file: 'apps/meteor/server/models.ts',
description:
"## 4 - Registering\n\n### Here we are using the registerModel import and passing 'IMessageModel' and then we pass in db and trashCollection into MessageRaw Class\n\n### The register model function looks something like this -\n```\nfunction registerModel<TModel extends IBaseModel<any, any, any>>(name: string, instance: TModel | (() => TModel)): void;\n```\n\n### And we pass data into it like - \n```\n registerModel('IMessagesModel', new MessagesRaw(db, trashCollection));\n //It becomes something like this, Here IMessageModel is basically implemented in MessagesRaw as we saw in previous steps\n registerModel<MessagesRaw>(name: string, instance: MessagesRaw | (() => MessagesRaw)): void\n```",
searchString: "registerModel('IMessagesModel'",
},

]
Expand Down