Skip to content

Commit

Permalink
refactor(query-mongoose): Update type definitions and test cases for …
Browse files Browse the repository at this point in the history
…string ID compatibility
  • Loading branch information
TriPSs committed Aug 21, 2024
1 parent 43e5891 commit 5fc1238
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/query-mongoose/__tests__/__fixtures__/seeds.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable no-underscore-dangle,@typescript-eslint/no-unsafe-return */
import { Connection } from 'mongoose'
import { Connection, Types } from 'mongoose'

import { TestEntity } from './test.entity'
import { TestReference } from './test-reference.entity'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'
import { Document, SchemaTypes, Types } from 'mongoose'

@Schema()
export class TestReference extends Document {
export class TestReference extends Document<string> {
@Prop({ required: true })
referenceName!: string

@Prop({ type: SchemaTypes.ObjectId, ref: 'TestEntity' })
testEntity?: Types.ObjectId
testEntity?: Types.ObjectId | string
}

export const TestReferenceSchema = SchemaFactory.createForClass(TestReference)
Expand Down
4 changes: 2 additions & 2 deletions packages/query-mongoose/__tests__/__fixtures__/test.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'
import { Document, SchemaTypes, Types } from 'mongoose'

@Schema()
export class TestEntity extends Document {
export class TestEntity extends Document<string> {
@Prop({ required: true })
stringType!: string

Expand All @@ -19,7 +19,7 @@ export class TestEntity extends Document {
testReference?: Types.ObjectId | string

@Prop([{ type: SchemaTypes.ObjectId, ref: 'TestReference' }])
testReferences?: Types.ObjectId[]
testReferences?: Types.ObjectId[] | string[]
}

export const TestEntitySchema = SchemaFactory.createForClass(TestEntity)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ describe('MongooseQueryService', () => {
})

it('should return undefined select if no results are found.', async () => {
const entities: TestEntity[] = [TEST_ENTITIES[0], { _id: new Types.ObjectId() } as TestEntity]
const entities: TestEntity[] = [TEST_ENTITIES[0], { _id: new Types.ObjectId() as never as string } as TestEntity]
const queryService = moduleRef.get(TestEntityService)
const queryResult = await queryService.findRelation(TestReference, 'testReference', entities)

Expand Down Expand Up @@ -1139,7 +1139,7 @@ describe('MongooseQueryService', () => {
})

it('should return an empty array if no results are found.', async () => {
const entities: TestEntity[] = [TEST_ENTITIES[0], { _id: new Types.ObjectId() } as TestEntity]
const entities: TestEntity[] = [TEST_ENTITIES[0], { _id: new Types.ObjectId() as never as string } as TestEntity]
const queryService = moduleRef.get(TestEntityService)
const queryResult = await queryService.aggregateRelations(
TestReference,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ import {
isEmbeddedSchemaTypeOptions,
isSchemaTypeWithReferenceOptions,
isVirtualTypeWithReferenceOptions,
VirtualReferenceOptions,
VirtualTypeWithOptions
VirtualReferenceOptions
} from '../mongoose-types.helper'
import { AggregateBuilder, FilterQueryBuilder } from '../query'

Expand Down

0 comments on commit 5fc1238

Please sign in to comment.