Skip to content

Commit 90dd13c

Browse files
committed
Split paginate helper for composition
1 parent fc25847 commit 90dd13c

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

src/components/location/location.edgedb.repository.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,6 @@ export class LocationEdgeDBRepository
6767
...this.applyFilter(obj, input),
6868
...this.applyOrderBy(obj, input),
6969
}));
70-
return await this.paginate(all, input);
70+
return await this.paginateAndRun(all, input);
7171
}
7272
}

src/core/edgedb/dto.repository.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,22 @@ export const RepoFor = <
185185
: {};
186186
}
187187

188-
protected async paginate(
188+
protected async paginateAndRun(
189+
listOfAllQuery: $expr_Select<
190+
$.TypeSet<$.ObjectType<DBName<Root>>, $.Cardinality.Many>
191+
>,
192+
input: PaginationInput,
193+
): Promise<PaginatedListType<Dto>> {
194+
const paginated = this.paginate(listOfAllQuery, input);
195+
const query = e.select({
196+
...paginated,
197+
items: e.select(paginated.items, this.hydrate),
198+
});
199+
const result = await this.db.run(query);
200+
return result as any;
201+
}
202+
203+
protected paginate(
189204
listOfAllQuery: $expr_Select<
190205
$.TypeSet<$.ObjectType<DBName<Root>>, $.Cardinality.Many>
191206
>,
@@ -195,18 +210,14 @@ export const RepoFor = <
195210
offset: (input.page - 1) * input.count,
196211
limit: input.count + 1,
197212
}));
198-
const items = e.select(thisPage, (obj: any) => ({
199-
...this.hydrate(obj),
213+
const items = e.select(thisPage, () => ({
200214
limit: input.count,
201215
}));
202-
const query = e.select({
216+
return {
203217
items: items as any,
204218
total: e.count(listOfAllQuery),
205219
hasMore: e.op(e.count(thisPage), '>', input.count),
206-
});
207-
208-
const result = await this.db.run(query);
209-
return result as PaginatedListType<Dto>;
220+
};
210221
}
211222

212223
// endregion
@@ -272,7 +283,7 @@ export const RepoFor = <
272283
...this.applyFilter(obj, input),
273284
...this.applyOrderBy(obj, input),
274285
}));
275-
return await this.paginate(all as any, input);
286+
return await this.paginateAndRun(all as any, input);
276287
}
277288

278289
async create(input: EasyInsertShape<Root>): Promise<Dto> {

0 commit comments

Comments
 (0)