Skip to content

Commit

Permalink
refactor(): small tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Nov 24, 2020
1 parent 4d8934f commit 3c539d7
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 18 deletions.
6 changes: 3 additions & 3 deletions lib/mongoose.providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { Connection, Document, Model } from 'mongoose';
import { getConnectionToken, getModelToken } from './common/mongoose.utils';
import {
AsyncModelFactory,
ModelDefinition,
DiscriminatorOptions,
ModelDefinition,
} from './interfaces';

function addDiscriminators(
model: Model<Document>,
discriminators: DiscriminatorOptions[] = [],
): Model<Document>[] {
return discriminators.map(({ name, schema }) =>
) {
discriminators.forEach(({ name, schema }) =>
model.discriminator(name, schema),
);
}
Expand Down
10 changes: 5 additions & 5 deletions tests/e2e/discriminator.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { HttpStatus, INestApplication, DynamicModule } from '@nestjs/common';
import { DynamicModule, HttpStatus, INestApplication } from '@nestjs/common';
import { Test } from '@nestjs/testing';
import { Server } from 'http';
import * as request from 'supertest';
import { MongooseModule } from '../../lib';
import { EventModule } from '../src/event/event.module';
import { Event, EventSchema } from '../src/event/schemas/event.schema';
import {
ClieckLinkEvent,
ClickLinkEvent,
ClieckLinkEventSchema,
} from '../src/event/schemas/click-link-event.schema';
import { Event, EventSchema } from '../src/event/schemas/event.schema';
import {
SignUpEvent,
SignUpEventSchema,
Expand All @@ -22,7 +22,7 @@ const testCase: [string, DynamicModule][] = [
name: Event.name,
schema: EventSchema,
discriminators: [
{ name: ClieckLinkEvent.name, schema: ClieckLinkEventSchema },
{ name: ClickLinkEvent.name, schema: ClieckLinkEventSchema },
{ name: SignUpEvent.name, schema: SignUpEventSchema },
],
},
Expand All @@ -35,7 +35,7 @@ const testCase: [string, DynamicModule][] = [
name: Event.name,
useFactory: async () => EventSchema,
discriminators: [
{ name: ClieckLinkEvent.name, schema: ClieckLinkEventSchema },
{ name: ClickLinkEvent.name, schema: ClieckLinkEventSchema },
{ name: SignUpEvent.name, schema: SignUpEventSchema },
],
},
Expand Down
6 changes: 3 additions & 3 deletions tests/src/event/event.controller.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Body, Controller, Get, Post } from '@nestjs/common';
import { EventService } from './event.service';
import { CreateClickLinkEventDto } from './dto/create-click-link-event.dto';
import { CreateSignUpEventDto } from './dto/create-sign-up-event.dto';
import { EventService } from './event.service';
import { ClickLinkEvent } from './schemas/click-link-event.schema';
import { Event } from './schemas/event.schema';
import { ClieckLinkEvent } from './schemas/click-link-event.schema';
import { SignUpEvent } from './schemas/sign-up-event.schema';

@Controller('event')
Expand All @@ -17,7 +17,7 @@ export class EventController {
return this.eventService.create({
...dto,
time: new Date(),
kind: ClieckLinkEvent.name,
kind: ClickLinkEvent.name,
});
}

Expand Down
6 changes: 3 additions & 3 deletions tests/src/event/event.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { Document, Model } from 'mongoose';
import { InjectModel } from '../../../lib';
import { CreateClickLinkEventDto } from './dto/create-click-link-event.dto';
import { CreateSignUpEventDto } from './dto/create-sign-up-event.dto';
import { ClickLinkEvent } from './schemas/click-link-event.schema';
import { Event } from './schemas/event.schema';
import { ClieckLinkEvent } from './schemas/click-link-event.schema';
import { SignUpEvent } from './schemas/sign-up-event.schema';

@Injectable()
Expand All @@ -13,8 +13,8 @@ export class EventService {
@InjectModel(Event.name)
private readonly eventModel: Model<Event & Document>,

@InjectModel(ClieckLinkEvent.name)
private readonly clientEventModel: Model<Event & Document>,
@InjectModel(ClickLinkEvent.name)
private readonly clickEventModel: Model<Event & Document>,

@InjectModel(SignUpEvent.name)
private readonly signUpEventModel: Model<Event & Document>,
Expand Down
4 changes: 2 additions & 2 deletions tests/src/event/schemas/click-link-event.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Prop, Schema, SchemaFactory } from '../../../../lib';
import { Event } from './event.schema';

@Schema({})
export class ClieckLinkEvent implements Event {
export class ClickLinkEvent implements Event {
kind: string;

time: Date;
Expand All @@ -12,5 +12,5 @@ export class ClieckLinkEvent implements Event {
}

export const ClieckLinkEventSchema = SchemaFactory.createForClass(
ClieckLinkEvent,
ClickLinkEvent,
);
4 changes: 2 additions & 2 deletions tests/src/event/schemas/event.schema.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Prop, Schema, SchemaFactory } from '../../../../lib';
import { ClieckLinkEvent } from './click-link-event.schema';
import { ClickLinkEvent } from './click-link-event.schema';
import { SignUpEvent } from './sign-up-event.schema';

@Schema({ discriminatorKey: 'kind' })
export class Event {
@Prop({
type: String,
required: true,
enum: [ClieckLinkEvent.name, SignUpEvent.name],
enum: [ClickLinkEvent.name, SignUpEvent.name],
})
kind: string;

Expand Down

0 comments on commit 3c539d7

Please sign in to comment.