Skip to content

Commit

Permalink
chore(json-api-nestjs): Fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
klerick committed Dec 5, 2024
1 parent 1b61fb3 commit 4c5284f
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
EntityProps,
EntityPropsArray,
EntityRelation,
IsArray,
TypeCast,
TypeOfArray,
UnionToTuple,
Expand Down Expand Up @@ -79,7 +80,7 @@ export enum TypeField {
export type TypeForId = Extract<TypeField, TypeField.number | TypeField.string>;

export type FieldWithType<E extends Entity> = {
[K in EntityProps<E>]: E[K] extends unknown[]
[K in EntityProps<E>]: IsArray<E[K]> extends true
? TypeField.array
: E[K] extends Date
? TypeField.date
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@ export class TypeormUtilsService<E extends Entity> {
const paramsName = this.getParamName(fieldWithAlias);

if (!isTargetField(this._relationFields, fieldName)) {

if (
(operand === FilterOperand.ne || operand === FilterOperand.eq) &&
(valueConditional === 'null' || valueConditional === null)
Expand Down Expand Up @@ -525,7 +524,7 @@ export class TypeormUtilsService<E extends Entity> {
)) {
const [props, type] = ObjectTyped.entries(item)[0];
if (type !== null) {
target[props] = type;
target[props] = type as any;
} else {
target[props] = null as any;
}
Expand Down
4 changes: 1 addition & 3 deletions libs/json-api/json-api-nestjs/src/lib/types/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,4 @@ export type JSONValue =
| { [x: string]: JSONValue }
| Array<JSONValue>;

export type IsArray<T> = T extends unknown[] ? true : false;

export type IsPropertyIsArray<E, P extends EntityProps<E>> = IsArray<E[P]>;
export type IsArray<T> = [Extract<T, unknown[]>] extends [never] ? false : true;
1 change: 1 addition & 0 deletions libs/json-api/json-shared-type/src/types/entity-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export type EntityField =
| boolean
| string[]
| number[]
| null
| Date;

export type EntityProps<T> = {
Expand Down

0 comments on commit 4c5284f

Please sign in to comment.