diff --git a/api/package.json b/api/package.json index 0bf812f..b288dab 100644 --- a/api/package.json +++ b/api/package.json @@ -1,6 +1,6 @@ { "name": "api", - "version": "2.1.1", + "version": "2.1.2", "description": "", "author": "", "private": true, diff --git a/api/src/log/log.service.spec.ts b/api/src/log/log.service.spec.ts index 0d50b25..56025c6 100644 --- a/api/src/log/log.service.spec.ts +++ b/api/src/log/log.service.spec.ts @@ -234,14 +234,14 @@ describe('LogService', () => { const count = 1 const morePages = false - jest.spyOn(mockLogRepository, 'findAndCount').mockReturnValue([logs, count, morePages]); + jest.spyOn(mockQueryBuilder, 'getManyAndCount').mockReturnValue([logs, count, morePages]); const {entities, total, hasNextPage} = await service.findLogsWithCount(); expect(entities).toEqual(logs); expect(count).toEqual(total); expect(hasNextPage).toEqual(morePages); - expect(mockLogRepository.findAndCount).toHaveBeenCalled(); + expect(mockQueryBuilder.getManyAndCount).toHaveBeenCalled(); }) it('findLogsWithTracks => should find log entries with tracks', async () => { @@ -294,7 +294,7 @@ describe('LogService', () => { expect(entities).toEqual(logs); expect(count).toEqual(total); expect(hasNextPage).toEqual(morePages); - expect(mockLogRepository.findAndCount).toHaveBeenCalled(); + expect(mockQueryBuilder.getManyAndCount).toHaveBeenCalled(); }) it('update => should update a log entry', async () => { diff --git a/api/src/log/log.service.ts b/api/src/log/log.service.ts index ee88ae6..ae877c8 100644 --- a/api/src/log/log.service.ts +++ b/api/src/log/log.service.ts @@ -25,11 +25,22 @@ export class LogService { } async findLogsWithCount(skip?: number, take?: number): Promise { - const [entities, total] = await this.logRepository.findAndCount({ - take, - skip, - relations: ['pilot', 'tracks'] - }) + // const [entities, total] = await this.logRepository.findAndCount({ + // take, + // skip, + // order: { + // date: 'DESC' + // }, + // relations: ['pilot', 'tracks'] + // }) + + const [entities, total] = await this.logRepository + .createQueryBuilder('logs') + .innerJoinAndSelect('logs.pilot', 'pilot') + .orderBy('logs.date', 'DESC') + .skip(skip) + .take(take) + .getManyAndCount() return { entities, diff --git a/client/package.json b/client/package.json index 45f3745..467d679 100644 --- a/client/package.json +++ b/client/package.json @@ -1,7 +1,7 @@ { "name": "client", "private": true, - "version": "2.1.1", + "version": "2.1.2", "type": "module", "scripts": { "dev": "vite", diff --git a/client/src/components/logbook/Logbook.tsx b/client/src/components/logbook/Logbook.tsx index 7216fd3..5d122f7 100644 --- a/client/src/components/logbook/Logbook.tsx +++ b/client/src/components/logbook/Logbook.tsx @@ -380,13 +380,13 @@ const Logbook: React.FC = () => { setPageIndex } = table; - const getLogbookEntries = async (pageIndex?: number, pageSize?: number) => { + const getLogbookEntries = async (pageIndex: number, pageSize: number) => { try { dispatch({ type: 'SET_IS_LOADING', payload: true }); const response: AxiosResponse = await httpClient.get(`api/logs`, { params: { - skip: pageIndex, + skip: pageIndex * pageSize, take: pageSize } }); @@ -527,6 +527,10 @@ const Logbook: React.FC = () => { dispatch({ type: 'SET_PAGES', payload: pages }) }, [state.totalEntries, state.pagination?.pageSize]) + useEffect(() => { + console.log(state.pagination) + }, [state.pagination]) + return ( <>
@@ -569,7 +573,7 @@ const Logbook: React.FC = () => { > - + diff --git a/package.json b/package.json index a437f1d..a6edfa3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@noahspan/flying", - "version": "2.1.1", + "version": "2.1.2", "scripts": { "start": "node api/dist/main", "format": "prettier --write \"**/src/**/*.ts\" \"**/test/**/*.ts\"",