benjamin658 / typeorm-cursor-pagination

Cursor-based pagination works with TypeORM Query Builder.
MIT License
186 stars 40 forks source link

Can not cursor pagination with alias name #39

Closed anhtuan3996 closed 3 years ago

anhtuan3996 commented 3 years ago

I used the alias names for the entities. I can not use the cursor.

This is my code: ` const queryBuilder = await getConnection() .getRepository(User) .createQueryBuilder('users'); // .where('id = :id', { id: 4 });

const paginator = buildPaginator({
  entity: User,
  alias: 'users',
  paginationKeys: ['id'],
  query: {
    limit: 2,
    order: 'ASC',
  },
});
const firstPage = await paginator.paginate(queryBuilder);

const nextPagePaginator = buildPaginator({
  entity: User,
  alias: 'users',
  paginationKeys: ['id'],
  query: {
    limit: 1,
    afterCursor: firstPage.cursor.afterCursor as string,
  },
});

const nextPageResult = await nextPagePaginator.paginate(
  queryBuilder.clone(),
);

return nextPageResult;

Error: [Nest] 134 - 08/10/2021, 3:30:57 AM ERROR [ExceptionsHandler] Cannot read property 'name' of undefined TypeError: Cannot read property 'name' of undefined at Paginator.getEntityPropertyType (/usr/src/app/node_modules/typeorm-cursor-pagination/src/Paginator.ts:198:74) at /usr/src/app/node_modules/typeorm-cursor-pagination/src/Paginator.ts:189:25 at Array.forEach () at Paginator.decode (/usr/src/app/node_modules/typeorm-cursor-pagination/src/Paginator.ts:187:13) at Paginator.appendPagingQuery (/usr/src/app/node_modules/typeorm-cursor-pagination/src/Paginator.ts:115:35) at Paginator. (/usr/src/app/node_modules/typeorm-cursor-pagination/src/Paginator.ts:76:33) at Generator.next () at /usr/src/app/node_modules/typeorm-cursor-pagination/lib/Paginator.js:8:71 at new Promise () at __awaiter (/usr/src/app/node_modules/typeorm-cursor-pagination/lib/Paginator.js:4:12) at Paginator.paginate (/usr/src/app/node_modules/typeorm-cursor-pagination/lib/Paginator.js:42:16)

`

anhtuan3996 commented 3 years ago

I found the issue because my entity extend BaseEntity from "typeorm"