-
-
Notifications
You must be signed in to change notification settings - Fork 573
[WIP] mongoose implementation #332
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
Conversation
Awesome! |
Basic joins are now possible via the crud-mongoose package. Requirements for joins to work: Mongoose schema must be setup to use virtuals |
if this feature is mostly ready, would be awesome to have it published as separate package until merge, as canary or so, Thanks! |
Hey @Bnaya, There is still some unit testing I would like to write but I could publish it as a separate package for now! I will update this soon! Just heading home for Christmas but would like to get that done soon! |
I just published a 0.0.1 version to npm here
I need to update the readme to reflect mongoose instead of typeORM which I will try and get done today. Feel free to comment on this issue with any questions or concerns. I will comment again when the docs after been updated. |
Updated. |
@Bnaya have you used the package at all? |
I've created this project template based on your integration tests code + in memory mongo |
- basic CRUD operations - missing: aggregate functionality and more advanced operators
- joins with projections work by using mongoose populate
- can deeply nest joins to recursively populate through virtuals
- `getMany` will return an array of JSON objects now instead of array of Mongoose documents
I have rebased my code onto what is released on nestjsx/crud but am having issues with the mongoose documents not being converted to POJOs now, the request just returns a JSON object of the document not the value of the document itself. Not sure what changed with this but toJSON isn't being called correctly. I will try and figure it out soon. |
@zMotivat0r is there something that would have changed in 4.3.x that would have caused the requests to not toJSON the mongoose Documents? All of my tests passed before but now the Documents are returned as they are represented in memory instead of the value of the document itself. I had to remove all references of authFilter and the getTake and getSkip methods plus I had to remove the code that prefixed the operators with a $ as they before the operators were just Thanks for any input you have.. |
|
Yup, noticed those methods were added to abstract thus were not needed, that is nice, the intercetpor is probably what is doing it! Thanks I will take a look. |
- remove getTake and getSkip, included in abstract service now - fix extra $ for operators
So I am going to need to spend some more time on this, for now the interceptors need to be turned off like in my spec files for it to work because of the way mongoose serializes the |
…ain objects - `crud-response.interceptor.ts` will handle Mongoose Documents now - mongoose `.toObject()` will return getters and virtuals
peerDependencies now include |
I have tried your I think, in the public async createBuilder<K>(
fn: (...args) => DocumentQuery<K, T>,
parsed: ParsedRequestParams,
options: CrudRequestOptions,
many = true,
): Promise<{ builder: DocumentQuery<K, T>; take?: number; skip?: number }> {
// get select fields
const select = this.getSelect(parsed, options.query);
// default search condition
const defaultSearch = this.queryFilterToSearch(parsed.search);
const builder = fn(defaultSearch);
// select fields
builder.select(select); |
Hey @lafeuil, thanks for letting me know! I will take a look at that today, could you provide me with the code for the Crud controller you were using in the example you provided? |
For example, if you want to filter the posts by the user that is authenticated : @Crud({
model: {
type: Post,
},
})
@CrudAuth({
filter: (user) => {
return { userId: user.id };
},
@Controller('posts')
export class PostsController implements CrudController<Post> {
...
} Example in the integration TypeOrm : crud/integration/crud-typeorm/projects/my-projects.controller.ts Lines 28 to 31 in bf54fe8
You can login a user automatically with the AuthGuard in the integration TypeOrm : crud/integration/crud-typeorm/auth.guard.ts Lines 1 to 16 in bf54fe8
|
Awesome thank you! Will take a look at that today! |
Hey @zMotivat0r , Just wondering if you would know what is going on here as it is the crud-request code causing it. When I run this test in the mongoose package:
The For the time being I wrote some code to prevent invalid values to be used for building the query here:
But would like to just be able to use |
Hey @lafeuil , my apologies I have not had time to look at this yet, will try and look tomorrow if I can find the time. |
@yharaskrik Hi, Thanks for the package! I found search or filter in query is not working and seems not been implemented. Is this related to the following issue?
|
@9173860 I believe in the version that was merged into v5 did have search and filter working, the comment you reference is talking about some code that i haven't pushed yet. Could you open a new issue with more info about them problem you are having? Thanks a lot. |
Thanks for the reply. I've opened #435 for reporting it with a demo. |
Basic mongoose implementation, working branch.