Commit 467a5732 authored by nanahira's avatar nanahira

search

parent b3fbeaf0
Pipeline #7913 passed with stages
in 1 minute and 47 seconds
...@@ -2,7 +2,7 @@ import { IdNameBase } from './IdNameBase.entity'; ...@@ -2,7 +2,7 @@ import { IdNameBase } from './IdNameBase.entity';
import { IdNameDescWise } from '../interfaces/wises'; import { IdNameDescWise } from '../interfaces/wises';
import { EntityDescription } from '../decorators/extended'; import { EntityDescription } from '../decorators/extended';
import { SelectQueryBuilder } from 'typeorm'; import { SelectQueryBuilder } from 'typeorm';
import { applyQueryPropertyLike } from '../utility/query'; import { applyQueryPropertySearch } from '../utility/query';
export class IdNameDescBase extends IdNameBase implements IdNameDescWise { export class IdNameDescBase extends IdNameBase implements IdNameDescWise {
@EntityDescription() @EntityDescription()
...@@ -13,6 +13,6 @@ export class IdNameDescBase extends IdNameBase implements IdNameDescWise { ...@@ -13,6 +13,6 @@ export class IdNameDescBase extends IdNameBase implements IdNameDescWise {
entityName: string, entityName: string,
) { ) {
super.applyQuery(qb, entityName); super.applyQuery(qb, entityName);
applyQueryPropertyLike(this, qb, entityName, 'desc'); applyQueryPropertySearch(this, qb, entityName, 'desc');
} }
} }
...@@ -2,7 +2,7 @@ import { ManualNameBase } from './ManualNameBase.entity'; ...@@ -2,7 +2,7 @@ import { ManualNameBase } from './ManualNameBase.entity';
import { StringIdNameDescWise } from '../interfaces/wises'; import { StringIdNameDescWise } from '../interfaces/wises';
import { EntityDescription } from '../decorators/extended'; import { EntityDescription } from '../decorators/extended';
import { SelectQueryBuilder } from 'typeorm'; import { SelectQueryBuilder } from 'typeorm';
import { applyQueryPropertyLike } from '../utility/query'; import { applyQueryPropertySearch } from '../utility/query';
export class ManualNameDescBase export class ManualNameDescBase
extends ManualNameBase extends ManualNameBase
...@@ -16,6 +16,6 @@ export class ManualNameDescBase ...@@ -16,6 +16,6 @@ export class ManualNameDescBase
entityName: string, entityName: string,
) { ) {
super.applyQuery(qb, entityName); super.applyQuery(qb, entityName);
applyQueryPropertyLike(this, qb, entityName, 'desc'); applyQueryPropertySearch(this, qb, entityName, 'desc');
} }
} }
...@@ -29,3 +29,19 @@ export function applyQueryPropertyLike<T extends TimeBase>( ...@@ -29,3 +29,19 @@ export function applyQueryPropertyLike<T extends TimeBase>(
}); });
} }
} }
export function applyQueryPropertySearch<T extends TimeBase>(
obj: T,
qb: SelectQueryBuilder<T>,
entityName: string,
...fields: (keyof T)[]
) {
for (const field of fields) {
if (obj[field] == null) {
continue;
}
qb.andWhere(`${entityName}.${field} like ('%' || :${field} || '%')`, {
[field]: obj[field],
});
}
}
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