Skip to content

Commit b5806da

Browse files
author
KoLiBer
committed
fix: change return type in models method, filter mixin
1 parent 4ba581c commit b5806da

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

src/repositories/filter.repository.ts

+9-10
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ export function FilterRepositoryMixin<
7171
>(config: {
7272
models: (
7373
context: InvocationContext,
74-
models: DataObject<T>[]
75-
) => Promise<(DataObject<T> | undefined)[]>;
74+
entities: DataObject<T>[]
75+
) => Promise<DataObject<T>[]>;
7676
where: (context: InvocationContext, where: Where<T>) => Promise<Where<T>>;
7777
fields: (
7878
context: InvocationContext,
@@ -99,11 +99,10 @@ export function FilterRepositoryMixin<
9999
Array.from(arguments)
100100
);
101101

102-
const mappedEntities: any[] = (
103-
await config.models(filterContext, entities || [])
104-
).filter((entity) => entity);
105-
106-
return await super.createAll(mappedEntities, options);
102+
return await super.createAll(
103+
await config.models(filterContext, entities || []),
104+
options
105+
);
107106
};
108107

109108
/**
@@ -236,17 +235,17 @@ export function FilterRepositoryMixin<
236235
Array.from(arguments)
237236
);
238237

239-
const mappedModel = (
238+
const mappedData = (
240239
await config.models(filterContext, [data])
241240
)[0];
242-
if (!mappedModel) {
241+
if (!mappedData) {
243242
return {
244243
count: 0,
245244
};
246245
}
247246

248247
return await super.updateAll(
249-
mappedModel,
248+
mappedData,
250249
await config.where(filterContext, where || {}),
251250
options
252251
);

test/unit/create.test.ts

Whitespace-only changes.

test/unit/test.repository.ts

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import { FilterRepositoryMixin } from "../../src";
1212
import { User } from "./test.model";
1313

1414
export class UserRepository extends FilterRepositoryMixin<User, string, {}>({
15+
models: async (context, entities) =>
16+
entities.filter((entity) => entity.username != "userX"),
1517
where: async (context, where) => ({
1618
and: [{ username: { neq: "user1" } }, where],
1719
}),

0 commit comments

Comments
 (0)