Skip to content

Commit

Permalink
pager fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelszczerbicki committed Feb 1, 2018
1 parent 69628e0 commit 0c88930
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/app/channel/channel.dao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class ChannelDao {

getHistory(channelId: string, user: string, page: Page) {
return this.mongo.findOne<Channel>({_id: new ObjectID(channelId), users: user},
{projection: {history: {'$slice': [page.skip(), page.size]}}});
{projection: {history: {'$slice': [(page.page - 1) * page.size, page.size]}}});
}

async getOrCreate(channel: Channel): Promise<Channel> {
Expand Down
4 changes: 2 additions & 2 deletions src/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ export class Index {
}

@Event(CHANNEL_HISTORY)
async channelHistory(@Args() request: HistoryRequest, @Socket() socket: SocketIO.Socket) {
socket.emit(CHANNEL_HISTORY, (await this.channelService.channelHistory(request.channelId, request.pager, socket.id))!.history);
async channelHistory(@Args() req: HistoryRequest, @Socket() socket: SocketIO.Socket) {
socket.emit(CHANNEL_HISTORY, (await this.channelService.channelHistory(req.channelId, req.pager, socket.id))!.history);
}

@Event(CONVERSATIONS)
Expand Down
10 changes: 3 additions & 7 deletions src/app/page/page.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
export class Page {
constructor(public page: number, public size: number) {
}

skip() {
return (this.page - 1) * this.size;
}
export interface Page {
page: number;
size: number;
}

0 comments on commit 0c88930

Please sign in to comment.