fixing logbook skip take order by

This commit is contained in:
2026-03-23 20:17:57 -05:00
parent 5de5a165da
commit e7a7b71661
6 changed files with 29 additions and 14 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "api", "name": "api",
"version": "2.1.1", "version": "2.1.2",
"description": "", "description": "",
"author": "", "author": "",
"private": true, "private": true,

View File

@@ -234,14 +234,14 @@ describe('LogService', () => {
const count = 1 const count = 1
const morePages = false 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(); const {entities, total, hasNextPage} = await service.findLogsWithCount();
expect(entities).toEqual(logs); expect(entities).toEqual(logs);
expect(count).toEqual(total); expect(count).toEqual(total);
expect(hasNextPage).toEqual(morePages); expect(hasNextPage).toEqual(morePages);
expect(mockLogRepository.findAndCount).toHaveBeenCalled(); expect(mockQueryBuilder.getManyAndCount).toHaveBeenCalled();
}) })
it('findLogsWithTracks => should find log entries with tracks', async () => { it('findLogsWithTracks => should find log entries with tracks', async () => {
@@ -294,7 +294,7 @@ describe('LogService', () => {
expect(entities).toEqual(logs); expect(entities).toEqual(logs);
expect(count).toEqual(total); expect(count).toEqual(total);
expect(hasNextPage).toEqual(morePages); expect(hasNextPage).toEqual(morePages);
expect(mockLogRepository.findAndCount).toHaveBeenCalled(); expect(mockQueryBuilder.getManyAndCount).toHaveBeenCalled();
}) })
it('update => should update a log entry', async () => { it('update => should update a log entry', async () => {

View File

@@ -25,11 +25,22 @@ export class LogService {
} }
async findLogsWithCount(skip?: number, take?: number): Promise<Logs> { async findLogsWithCount(skip?: number, take?: number): Promise<Logs> {
const [entities, total] = await this.logRepository.findAndCount({ // const [entities, total] = await this.logRepository.findAndCount({
take, // take,
skip, // skip,
relations: ['pilot', 'tracks'] // 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 { return {
entities, entities,

View File

@@ -1,7 +1,7 @@
{ {
"name": "client", "name": "client",
"private": true, "private": true,
"version": "2.1.1", "version": "2.1.2",
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",

View File

@@ -380,13 +380,13 @@ const Logbook: React.FC<unknown> = () => {
setPageIndex setPageIndex
} = table; } = table;
const getLogbookEntries = async (pageIndex?: number, pageSize?: number) => { const getLogbookEntries = async (pageIndex: number, pageSize: number) => {
try { try {
dispatch({ type: 'SET_IS_LOADING', payload: true }); dispatch({ type: 'SET_IS_LOADING', payload: true });
const response: AxiosResponse = await httpClient.get(`api/logs`, { const response: AxiosResponse = await httpClient.get(`api/logs`, {
params: { params: {
skip: pageIndex, skip: pageIndex * pageSize,
take: pageSize take: pageSize
} }
}); });
@@ -527,6 +527,10 @@ const Logbook: React.FC<unknown> = () => {
dispatch({ type: 'SET_PAGES', payload: pages }) dispatch({ type: 'SET_PAGES', payload: pages })
}, [state.totalEntries, state.pagination?.pageSize]) }, [state.totalEntries, state.pagination?.pageSize])
useEffect(() => {
console.log(state.pagination)
}, [state.pagination])
return ( return (
<> <>
<div className={`${screenSize === ScreenSize.SM ? 'mr-4 ml-4' : 'mr-10 ml-10'} grid grid-cols-12`}> <div className={`${screenSize === ScreenSize.SM ? 'mr-4 ml-4' : 'mr-10 ml-10'} grid grid-cols-12`}>
@@ -569,7 +573,7 @@ const Logbook: React.FC<unknown> = () => {
> >
<option value={10}>10</option> <option value={10}>10</option>
<option value={25}>25</option> <option value={25}>25</option>
<option value={3}>50</option> <option value={50}>50</option>
<option value={state.totalEntries}>All</option> <option value={state.totalEntries}>All</option>
</select> </select>
</label> </label>

View File

@@ -1,6 +1,6 @@
{ {
"name": "@noahspan/flying", "name": "@noahspan/flying",
"version": "2.1.1", "version": "2.1.2",
"scripts": { "scripts": {
"start": "node api/dist/main", "start": "node api/dist/main",
"format": "prettier --write \"**/src/**/*.ts\" \"**/test/**/*.ts\"", "format": "prettier --write \"**/src/**/*.ts\" \"**/test/**/*.ts\"",