Skip to content

Commit

Permalink
refactor(): Remove ORM specific query service decorators
Browse files Browse the repository at this point in the history
  • Loading branch information
doug-martin committed May 9, 2020
1 parent 282c421 commit cd09abe
Show file tree
Hide file tree
Showing 15 changed files with 33 additions and 68 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import * as nestjsCommon from '@nestjs/common';
import { QueryService, InjectQueryService, getQueryServiceToken } from '../../src';

describe('@InjectQueryService', () => {
const injectSpy = jest.spyOn(nestjsCommon, 'Inject');

class TestEntity {}

it('call inject with the correct key', () => {
// @ts-ignore
// eslint-disable-next-line @typescript-eslint/no-unused-vars
class Test {
constructor(@InjectQueryService(TestEntity) readonly service: QueryService<TestEntity>) {}
}
expect(injectSpy).toBeCalledTimes(1);
expect(injectSpy).toBeCalledWith(getQueryServiceToken(TestEntity));
});
});
5 changes: 5 additions & 0 deletions packages/core/src/decorators/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Class } from '../common';

export function getQueryServiceToken<DTO>(DTOClass: Class<DTO>): string {
return `${DTOClass.name}QueryService`;
}
2 changes: 2 additions & 0 deletions packages/core/src/decorators/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { getQueryServiceToken } from './helpers';
export { InjectQueryService } from './inject-query-service.decorator';
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Inject } from '@nestjs/common';
import { Class } from '../common';
import { getQueryServiceToken } from './helpers';

export const InjectQueryService = <DTO>(entity: Class<DTO>): ParameterDecorator => Inject(getQueryServiceToken(entity));
9 changes: 2 additions & 7 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
/* eslint-disable import/export */
export * from './interfaces';
export * from './common';
export {
QueryService,
AssemblerQueryService,
RelationQueryService,
QueryServiceRelation,
getQueryServiceToken,
} from './services';
export { InjectQueryService, getQueryServiceToken } from './decorators';
export { QueryService, AssemblerQueryService, RelationQueryService, QueryServiceRelation } from './services';
export { transformFilter, transformQuery, transformSort, QueryFieldMap } from './helpers';
export {
ClassTransformerAssembler,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/services/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { QueryService, getQueryServiceToken } from './query.service';
export { QueryService } from './query.service';
export { AssemblerQueryService } from './assembler-query.service';
export { RelationQueryService, QueryServiceRelation } from './relation-query.service';
4 changes: 0 additions & 4 deletions packages/core/src/services/query.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,3 @@ export function QueryService<DTO>(DTOClass: Class<DTO>) {
return Injectable()(cls);
};
}

export function getQueryServiceToken<DTO>(DTOClass: Class<DTO>): string {
return `${DTOClass.name}QueryService`;
}

This file was deleted.

1 change: 0 additions & 1 deletion packages/query-sequelize/src/decorators/index.ts

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion packages/query-sequelize/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export { SequelizeQueryService } from './services';
export { InjectSequelizeQueryService } from './decorators';
export { NestjsQuerySequelizeModule } from './module';

This file was deleted.

1 change: 0 additions & 1 deletion packages/query-typeorm/src/decorators/index.ts

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion packages/query-typeorm/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export { TypeOrmQueryService, TypeOrmQueryServiceOpts } from './services';
export { InjectTypeOrmQueryService } from './decorators';
export { NestjsQueryTypeOrmModule } from './module';

0 comments on commit cd09abe

Please sign in to comment.