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

refactor: add _id to all model interfaces #75

Merged
merged 3 commits into from
Aug 5, 2020
Merged

refactor: add _id to all model interfaces #75

merged 3 commits into from
Aug 5, 2020

Conversation

mantariksh
Copy link
Contributor

@mantariksh mantariksh commented Aug 4, 2020

Problem

We have two interfaces for each model, one for plain objects and one for Mongoose documents. For example, we have IForm for plain Form objects, and IFormSchema for documents retrieved from the database. However, none of our interfaces for plain objects include an _id key, despite the fact that all objects retrieved from the database have an _id key which we frequently access. This makes it difficult for us to write typed code for objects retrieved from the database, as every time we need to access the _id key, we have to create a union type.

Solution

Add an _id key to all relevant interfaces. The following interfaces were excluded because we set _id: false in the schema:

  • Form logo
  • Custom form logo
  • MyInfo schema (part of baseField)
  • Columns in table fields

The disadvantage of this approach is that when declaring new documents to add to the database, we have to omit _id from the type, as can be seen in sms_count.server.model.ts. However, I think this is a tiny minority of cases compared to the number of cases where we need the _id key to be present.

@mantariksh mantariksh requested a review from karrui August 4, 2020 09:59
Copy link
Contributor

@karrui karrui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

src/types/form_feedback.ts Outdated Show resolved Hide resolved
@mantariksh
Copy link
Contributor Author

No idea why build keeps failing, will investigate tmr

@mantariksh mantariksh merged commit ed6b3e0 into develop Aug 5, 2020
@mantariksh mantariksh deleted the type-id branch August 5, 2020 01:22
@karrui
Copy link
Contributor

karrui commented Dec 7, 2020

I removed _id from form again, since we stopped using IForm directly and use IFormSchema nowadays, which has the _id field

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants