scopsy/node-typescript-starter

Question with InjectorToken

Opened this issue · 0 comments

Hey guys, I have a question regarding the creation of new (business-)objects and the usage of them in within a service.
I have created a new Type "MonthView". Therefore I have an existing colleciton in my mongoDB which is called "monthviews". Now I want to do a simple .find operation in my service. I have created the model like that:
`import { InjectorService, JsonProperty } from 'ts-express-decorators';
import { prop, Typegoose, InstanceType, ModelType } from 'typegoose';
import { MonthViewRepoToken } from '../token-constants';

export class MonthView extends Typegoose {

@prop()
@JsonProperty()
year: string;

@prop()
@JsonProperty()
month: string;

@prop()
@JsonProperty()
day: string;

@prop()
@JsonProperty()
amount: string;

}

export type MonthViewInstance = InstanceType;
export type MonthViewRepo = ModelType;
InjectorService.factory(MonthViewRepoToken, new MonthView().getModelForClass(MonthView));
`

I am a little confused about the last line of code because this crashes my whole application. The login doesn't work any more, the same on signup route. When I comment the line out, then it starts to work again. It seems that the Collection "user" gets overwritten in some strange way. Can you maybe help me to figure that out?

Thanks!