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

upgrade mongo and mongoose packages #3950

Merged
merged 30 commits into from
Oct 8, 2021

Conversation

RafaPolit
Copy link
Member

fixes #3395

PR checklist:

  • Update READ.me ?
  • Update API documentation ?

QA checklist:

  • Smoke test the functionality described in the issue
  • Test for side effects
  • UI responsiveness
  • Cross browser testing
  • Code review

const user = permissionsContext.getUserInContext();
const query = { _id: data._id } as PermissionsUwaziFilterQuery<T>;
Copy link
Member Author

@RafaPolit RafaPolit Oct 1, 2021

Choose a reason for hiding this comment

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

Not sure why I am required to do this "casts". In Typescript 4.x, they are not needed, in 3.x it does not accept this as an argument for the below function. I am open to ideas as to what may be wrong. Same issue in line 158.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I am not sure how to solve but what i think is wrong is:
this method save uses data: WithPermissionsDataType<T> while appendPermissionsQuery uses as the first param query: PermissionsUwaziFilterQuery<T>
the first is based on PartialDataType, which means, _id can be not defined, the second is based on DataType which means _id can NOT be undefined. i think despite the difficult to read error this is the issue.

@RafaPolit RafaPolit changed the title upgrade typescript packages upgrade mongo and mongoose packages Oct 1, 2021
@RafaPolit RafaPolit mentioned this pull request Oct 1, 2021
7 tasks
@@ -115,14 +120,15 @@ const controlPermissionsData = <T>(data: T & { published?: boolean }, user?: Use
};

export class ModelWithPermissions<T> extends OdmModel<T> {
async save(data: DataType<T & { permissions?: PermissionSchema[] }>) {
Copy link
Member Author

Choose a reason for hiding this comment

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

I believe this was wrong to start with, the & permissions should have been OUTSIDE of the bracket.

Copy link
Collaborator

Choose a reason for hiding this comment

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

im not sure this is the case with the current implementation, lets take a look together.

import { tenants } from '../tenants/tenantContext';
import { DB } from './DB';

class MultiTenantMongooseModel<T> {
dbs: { [k: string]: mongoose.Model<WithId<T> & mongoose.Document> };
dbs: { [k: string]: mongoose.Model<DataType<T>> };
Copy link
Member Author

@RafaPolit RafaPolit Oct 1, 2021

Choose a reason for hiding this comment

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

In the first iteration, DataType included an & Document clause. This is no longer true. This means that dbs no longer explicitly has the mongoose.Document type extended, but I think that T should already have that passed along on instance.

}

return this.dbs[currentTenant.name];
}

findById(id: any | string | number, select?: any) {
findById(id: any, select?: any) {
Copy link
Member Author

Choose a reason for hiding this comment

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

I was confused that this had any | string | number... any is already any.

) {
return this.dbForCurrentTenant().findOneAndUpdate(query, update, options);
}

async create(data: Readonly<Partial<T>> & { _id?: any }) {
async create(data: PartialDataType<T>) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Nothing in the new implementation has Readonly. Any hint as to why this could have been needed? I just removed it from everywhere and nothing is failing. I'm open to being enlightened about this as well.

Copy link
Collaborator

Choose a reason for hiding this comment

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

not sure, @fnocetti @mfacar ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think it's needed for the permissions model 🤔

Comment on lines +22 to 23
// @ts-ignore
await expect(logHelper.upsertLogMany({ _id: null })).resolves.toBeEmpty;
Copy link
Member Author

Choose a reason for hiding this comment

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

This is testing a value that is not valid as _id. This type of errors should, in theory, be caught by TS from now on, so this test scenario should ideally not arise. Unsure if this merits a deletion of both expects (this and the next one, which is more or less the same situation), but I'm keeping them as I am unsure of the scenario this was written in.

@fnocetti fnocetti merged commit 438d763 into development Oct 8, 2021
@fnocetti fnocetti deleted the 3393-upgrade-mongoose-working branch October 8, 2021 20:34
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.

ci tasks run multiple times on internal PR
4 participants