Commit 0dd313b2 authored by nanahira's avatar nanahira

revert

parent 1feaf24b
...@@ -23,15 +23,14 @@ import { ConsoleLogger } from '@nestjs/common'; ...@@ -23,15 +23,14 @@ import { ConsoleLogger } from '@nestjs/common';
import { camelCase } from 'typeorm/util/StringUtils'; import { camelCase } from 'typeorm/util/StringUtils';
import _ from 'lodash'; import _ from 'lodash';
import { ClassType } from './utility/insert-field'; import { ClassType } from './utility/insert-field';
import { RecursiveKeyOf } from './utility/recursive-key-of';
export type EntityId<T extends { id: any }> = T['id']; export type EntityId<T extends { id: any }> = T['id'];
export interface RelationDef<T> { export interface RelationDef {
name: T; name: string;
inner?: boolean; inner?: boolean;
} }
export const Inner = <T>(name: T): RelationDef<T> => { export const Inner = (name: string): RelationDef => {
return { name, inner: true }; return { name, inner: true };
}; };
...@@ -40,7 +39,7 @@ export type ValidCrudEntity<T> = Record<string, any> & { ...@@ -40,7 +39,7 @@ export type ValidCrudEntity<T> = Record<string, any> & {
} & Partial<QueryWise<T> & DeletionWise & EntityHooks & PageSettingsFactory>; } & Partial<QueryWise<T> & DeletionWise & EntityHooks & PageSettingsFactory>;
export interface CrudOptions<T extends ValidCrudEntity<T>> { export interface CrudOptions<T extends ValidCrudEntity<T>> {
relations?: (RecursiveKeyOf<T> | RelationDef<RecursiveKeyOf<T>>)[]; relations?: (string | RelationDef)[];
extraGetQuery?: (qb: SelectQueryBuilder<T>) => void; extraGetQuery?: (qb: SelectQueryBuilder<T>) => void;
hardDelete?: boolean; hardDelete?: boolean;
} }
...@@ -53,10 +52,7 @@ export class CrudBase<T extends ValidCrudEntity<T>> { ...@@ -53,10 +52,7 @@ export class CrudBase<T extends ValidCrudEntity<T>> {
readonly entityPaginatedReturnMessageDto = PaginatedReturnMessageDto( readonly entityPaginatedReturnMessageDto = PaginatedReturnMessageDto(
this.entityClass, this.entityClass,
); );
readonly entityRelations: ( readonly entityRelations: (string | RelationDef)[];
| RecursiveKeyOf<T>
| RelationDef<RecursiveKeyOf<T>>
)[];
readonly extraGetQuery: (qb: SelectQueryBuilder<T>) => void; readonly extraGetQuery: (qb: SelectQueryBuilder<T>) => void;
readonly log = new ConsoleLogger(`${this.entityClass.name}Service`); readonly log = new ConsoleLogger(`${this.entityClass.name}Service`);
...@@ -195,10 +191,7 @@ export class CrudBase<T extends ValidCrudEntity<T>> { ...@@ -195,10 +191,7 @@ export class CrudBase<T extends ValidCrudEntity<T>> {
return camelCase(this.entityName); return camelCase(this.entityName);
} }
_applyRelationToQuery( _applyRelationToQuery(qb: SelectQueryBuilder<T>, relation: RelationDef) {
qb: SelectQueryBuilder<T>,
relation: RelationDef<RecursiveKeyOf<T>>,
) {
const { name } = relation; const { name } = relation;
const relationUnit = name.split('.'); const relationUnit = name.split('.');
const base = const base =
...@@ -216,7 +209,7 @@ export class CrudBase<T extends ValidCrudEntity<T>> { ...@@ -216,7 +209,7 @@ export class CrudBase<T extends ValidCrudEntity<T>> {
_applyRelationsToQuery(qb: SelectQueryBuilder<T>) { _applyRelationsToQuery(qb: SelectQueryBuilder<T>) {
for (const relation of this.entityRelations) { for (const relation of this.entityRelations) {
if (typeof relation === 'string') { if (typeof relation === 'string') {
this._applyRelationToQuery(qb, { name: relation as any }); this._applyRelationToQuery(qb, { name: relation });
} else { } else {
this._applyRelationToQuery(qb, relation); this._applyRelationToQuery(qb, relation);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment