-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(typegoose): Add typegoose package (#846)
* wip: Typegoose implementation for nestjs-query * feat: Implementation of the rest of QueryService and Tests * fix: adding in assemblers that were missed * docs: Adding documentation for typegoose * docs: Updating install guides to include Typegoose * docs: Updating the getting-started documentation * feat: adding the ability to add and remove items from an array using a specific UpdateArray Input type. * feat: adds typegoose e2e testing * tests: fixes failing typegoose unit tests * chore: remove commented code * feat(typegoose): Getting tests passing * Initial work * feat(typegoose): WIP * feat(typegoose): WIP * feat(typegoose): WIP * feat(typegoose): small corrections * chore(): Update typegoose example to use QueryOptions decorator * chore(): Fix linting issues Co-authored-by: John McInall <johnmcinall@odro.co.uk> Co-authored-by: John McInall <johnmcinall@pop-os.localdomain> Co-authored-by: Scott <scott.molinari@adduco.de> Co-authored-by: John McInall <johnmcinall@gmail.com>
- Loading branch information
1 parent
0826966
commit 73cf5cd
Showing
78 changed files
with
8,260 additions
and
23 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,13 @@ | ||
<component name="ProjectRunConfigurationManager"> | ||
<configuration default="false" name="start - typegoose" type="js.build_tools.npm"> | ||
<package-json value="$PROJECT_DIR$/examples/package.json" /> | ||
<command value="run" /> | ||
<scripts> | ||
<script value="start" /> | ||
</scripts> | ||
<arguments value="-- typegoose" /> | ||
<node-interpreter value="project" /> | ||
<envs /> | ||
<method v="2" /> | ||
</configuration> | ||
</component> |
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
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
57 changes: 57 additions & 0 deletions
57
documentation/docs/persistence/typegoose/custom-service.md
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,57 @@ | ||
--- | ||
title: Custom Service | ||
--- | ||
|
||
To create a custom query service to add your own methods to you can extend the `TypegooseQueryService`. | ||
|
||
```ts title="todo-item.service.ts" | ||
import { QueryService } from '@nestjs-query/core'; | ||
import { InjectModel } from '@nestjs/mongoose'; | ||
import { TypegooseQueryService } from '@nestjs-query/query-typegoose'; | ||
import { TodoItemEntity } from './entity/todo-item.entity'; | ||
|
||
@QueryService(TodoItemEntity) | ||
export class TodoItemService extends TypegooseQueryService<TodoItemEntity> { | ||
constructor(@InjectModel(TodoItemEntity) model: ReturnModelType<typeof TodoItemEntity>) { | ||
super(model); | ||
} | ||
|
||
async markAllAsCompleted(): Promise<number> { | ||
const entities = await this.query({ filter: { completed: { is: true } } }); | ||
|
||
const { updatedCount } = await this.updateMany( | ||
{ completed: true }, // update | ||
{ id: { in: entities.map((e) => e.id) } }, // filter | ||
); | ||
// do some other business logic | ||
return updatedCount; | ||
} | ||
} | ||
``` | ||
|
||
To use the custom service in the auto-generated resolver you can specify the `ServiceClass` option. | ||
|
||
```ts title="todo-item.module.ts" {12,16} | ||
import { NestjsQueryGraphQLModule } from '@nestjs-query/query-graphql'; | ||
import { NestjsQueryTypegooseModule } from '@nestjs-query/query-typegoose'; | ||
import { Module } from '@nestjs/common'; | ||
import { TodoItemDTO } from './dto/todo-item.dto'; | ||
import { TodoItemEntity } from './todo-item.entity'; | ||
import { TodoItemService } from './todo-item.service'; | ||
|
||
@Module({ | ||
imports: [ | ||
NestjsQueryGraphQLModule.forFeature({ | ||
imports: [NestjsQueryTypegooseModule.forFeature([TodoItemEntity])], | ||
services: [TodoItemService], | ||
resolvers: [ | ||
{ | ||
DTOClass: TodoItemDTO, | ||
ServiceClass: TodoItemService, | ||
}, | ||
], | ||
}), | ||
], | ||
}) | ||
export class TodoItemModule {} | ||
``` |
18 changes: 18 additions & 0 deletions
18
documentation/docs/persistence/typegoose/getting-started.md
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,18 @@ | ||
--- | ||
title: Getting Started | ||
--- | ||
|
||
The `@nestjs-query/query-typegoose` package provides an implementation of `@nestjs-query/core` [QueryService](../../concepts/services.md). | ||
|
||
This package is built using [typegoose](https://typegoose.github.io/typegoose/) and [nestjs/typegoose](https://github.com/kpfromer/nestjs-typegoose#readme). If you are unfamiliar with them I suggest you read their documentation first. | ||
|
||
## Installation | ||
|
||
[Installation Docs](../../introduction/install.md#nestjs-queryquery-typegoose) | ||
|
||
## Docs | ||
|
||
- Read the [QueryService docs](../services.mdx) | ||
- [Relations](./relations.mdx) - How to work with relations/references in `typegoose` with `nestjs-query` | ||
- [Custom Service](./custom-service.md) - Example custom service | ||
- [Serialization](./serialization.md) - How to serialize `typegoose` models. |
Oops, something went wrong.