Compare commits

..

5 Commits

8 changed files with 35 additions and 93 deletions

View File

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

View File

@@ -62,7 +62,7 @@ export class LogInterceptor implements NestInterceptor {
const logs = publicData.slice(0, 5)
return {
entities: logs,
entities: publicData,
total: data.total,
hasNextPage: false
};
@@ -71,6 +71,7 @@ export class LogInterceptor implements NestInterceptor {
return publicData
}
}
})
);

View File

@@ -19,8 +19,6 @@ describe('LogService', () => {
createQueryBuilder: jest.fn().mockReturnThis(),
innerJoinAndSelect: jest.fn().mockReturnThis(),
orderBy: jest.fn().mockReturnThis(),
skip: jest.fn().mockReturnThis(),
take: jest.fn().mockReturnThis(),
getManyAndCount: jest.fn()
}
@@ -234,14 +232,14 @@ describe('LogService', () => {
const count = 1
const morePages = false
jest.spyOn(mockQueryBuilder, 'getManyAndCount').mockReturnValue([logs, count, morePages]);
jest.spyOn(mockLogRepository, 'findAndCount').mockReturnValue([logs, count, morePages]);
const {entities, total, hasNextPage} = await service.findLogsWithCount();
expect(entities).toEqual(logs);
expect(count).toEqual(total);
expect(hasNextPage).toEqual(morePages);
expect(mockQueryBuilder.getManyAndCount).toHaveBeenCalled();
expect(mockLogRepository.findAndCount).toHaveBeenCalled();
})
it('findLogsWithTracks => should find log entries with tracks', async () => {
@@ -294,7 +292,7 @@ describe('LogService', () => {
expect(entities).toEqual(logs);
expect(count).toEqual(total);
expect(hasNextPage).toEqual(morePages);
expect(mockQueryBuilder.getManyAndCount).toHaveBeenCalled();
expect(mockLogRepository.findAndCount).toHaveBeenCalled();
})
it('update => should update a log entry', async () => {

View File

@@ -25,22 +25,11 @@ export class LogService {
}
async findLogsWithCount(skip?: number, take?: number): Promise<Logs> {
// 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()
const [entities, total] = await this.logRepository.findAndCount({
take,
skip,
relations: ['pilot', 'tracks']
})
return {
entities,
@@ -54,9 +43,7 @@ export class LogService {
.createQueryBuilder('logs')
.innerJoinAndSelect('logs.tracks', 'track')
.innerJoinAndSelect('logs.pilot', 'pilot')
.orderBy('logs.date', 'DESC')
.skip(skip)
.take(take)
.orderBy('date')
.getManyAndCount();
return {

View File

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

View File

@@ -380,13 +380,13 @@ const Logbook: React.FC<unknown> = () => {
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 * pageSize,
skip: pageIndex,
take: pageSize
}
});
@@ -527,10 +527,6 @@ const Logbook: React.FC<unknown> = () => {
dispatch({ type: 'SET_PAGES', payload: pages })
}, [state.totalEntries, state.pagination?.pageSize])
useEffect(() => {
console.log(state.pagination)
}, [state.pagination])
return (
<>
<div className={`${screenSize === ScreenSize.SM ? 'mr-4 ml-4' : 'mr-10 ml-10'} grid grid-cols-12`}>
@@ -573,7 +569,7 @@ const Logbook: React.FC<unknown> = () => {
>
<option value={10}>10</option>
<option value={25}>25</option>
<option value={50}>50</option>
<option value={3}>50</option>
<option value={state.totalEntries}>All</option>
</select>
</label>

View File

@@ -17,31 +17,11 @@ import { Pilot } from './Pilot.interface';
import Alert from '../alert/Alert';
import { useOidc } from '../../auth/oidcConfig';
interface ActionsProps {
id: string;
}
const Pilots: React.FC<unknown> = () => {
const [state, dispatch] = useReducer(reducer, initialState);
const { userRole } = useUserRole();
const { screenSize } = useBreakpoints();
const { isUserLoggedIn } = useOidc();
const Actions = ({ id }: ActionsProps) => {
return (
<div className='dropdown dropdown-end'>
<div tabIndex={0} role='button' className='btn btn-ghost'><FontAwesomeIcon icon={faEllipsisVertical} /></div>
<ul tabIndex={-1} className="dropdown-content menu bg-base-100 rounded-box z-1 w-52 p-2 shadow-sm border border-base-300">
{isUserLoggedIn && userRole === UserRole.WRITE &&
<li><a onClick={() => onOpenClosePilotForm(FormMode.EDIT, id)}><FontAwesomeIcon icon={faPen} />Edit</a></li>
}
<li><a onClick={() => onOpenClosePilotForm(FormMode.VIEW, id)}><FontAwesomeIcon icon={faEye} />View</a></li>
{isUserLoggedIn && userRole === UserRole.WRITE &&
<li><a onClick={() => onDeletePilot(id)}><FontAwesomeIcon icon={faTrash} />Delete</a></li>
}
</ul>
</div>
)
}
const getPilots = async () => {
try {
@@ -154,7 +134,18 @@ const Pilots: React.FC<unknown> = () => {
},
cell: (info: CellContext<Pilot, unknown>) => {
return (
<Actions id={info.row.original.id} />
<div className='dropdown dropdown-end'>
<div tabIndex={0} role='button' className='btn btn-ghost'><FontAwesomeIcon icon={faEllipsisVertical} /></div>
<ul tabIndex={-1} className="dropdown-content menu bg-base-100 rounded-box z-1 w-52 p-2 shadow-sm border border-base-300">
{isUserLoggedIn && userRole === UserRole.WRITE &&
<li><a onClick={() => onOpenClosePilotForm(FormMode.EDIT, info.row.original.id)}><FontAwesomeIcon icon={faPen} />Edit</a></li>
}
<li><a onClick={() => onOpenClosePilotForm(FormMode.VIEW, info.row.original.id)}><FontAwesomeIcon icon={faEye} />View</a></li>
{isUserLoggedIn && userRole === UserRole.WRITE &&
<li><a onClick={() => onDeletePilot(info.row.original.id)}><FontAwesomeIcon icon={faTrash} />Delete</a></li>
}
</ul>
</div>
)
}
}
@@ -181,11 +172,11 @@ const Pilots: React.FC<unknown> = () => {
return (
<>
<div className={`${screenSize === ScreenSize.SM ? 'mr-4 ml-4' : 'mr-10 ml-10'} grid grid-cols-12`}>
<div className='prose max-w-none col-span-6 mt-5 mb-5' >
<div className='mr-10 ml-10 grid grid-cols-12'>
<div className='prose max-w-none col-span-10 mt-5 mb-5' >
<h1>Pilots</h1>
</div>
<div className='col-span-6 justify-self-end self-center'>
<div className='col-span-2 justify-self-end self-center'>
{!state.isLoading && userRole === UserRole.WRITE &&
<button
className='btn btn-primary'
@@ -268,40 +259,9 @@ const Pilots: React.FC<unknown> = () => {
</table>
</div>
}
{state.pilots.length > 0 && screenSize === ScreenSize.SM &&
<div className='col-span-12'>
<>
{table.getRowModel().rows.map((row) => {
return (
<div className='card bg-base-100 border border-base-300 mb-5'>
<div className={`card-body ${screenSize === ScreenSize.SM || screenSize === ScreenSize.MD ? 'p-4' : ''}`} key={row.id}>
<div className={`grid grid-cols-12 gap-3`}>
<>
{row.getVisibleCells().map((cell) => {
return (
<>
{cell.column.columnDef.header !== 'Actions' &&
<>
<div className='col-span-10 self-center'>
<span>{flexRender(cell.column.columnDef.cell, cell.getContext())}</span>
</div>
<div className='col-span-2'>
<Actions id={row.original.id} />
</div>
</>
}
</>
)
})}
</>
</div>
</div>
</div>
)
})}
</>
</div>
}
{/* {state.pilots.length > 0 && screenSize === ScreenSize.SM &&
<PilotCard pilots={state.pilots} onDelete={onDeletePilot} onOpenCloseForm={onOpenClosePilotForm} />
} */}
</div>
{state.isFormOpen && (
<PilotForm

View File

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