Commit cf6ca4d1 authored by nanahira's avatar nanahira

add QueryEqualZeroNullable

parent 0dd313b2
......@@ -4,6 +4,7 @@ import {
applyQueryProperty,
applyQueryPropertyLike,
applyQueryPropertySearch,
applyQueryPropertyZeroNullable,
} from '../utility';
export const QueryCondition = (cond: QueryCond) =>
......@@ -11,3 +12,6 @@ export const QueryCondition = (cond: QueryCond) =>
export const QueryEqual = () => QueryCondition(applyQueryProperty);
export const QueryLike = () => QueryCondition(applyQueryPropertyLike);
export const QuerySearch = () => QueryCondition(applyQueryPropertySearch);
export const QueryEqualZeroNullable = () =>
QueryCondition(applyQueryPropertyZeroNullable);
......@@ -44,3 +44,22 @@ export function applyQueryPropertySearch<T>(
});
}
}
export function applyQueryPropertyZeroNullable<T>(
obj: T,
qb: SelectQueryBuilder<T>,
entityName: string,
...fields: (keyof T & string)[]
) {
for (const field of fields) {
if (obj[field] === undefined) {
// Nothing
} else if ([0, '0'].indexOf(obj[field] as any) !== -1) {
qb.andWhere(`${entityName}.${field} IS NULL`);
} else {
qb.andWhere(`${entityName}.${field} = :${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