Skip to content

Commit

Permalink
fix myEvents logic
Browse files Browse the repository at this point in the history
  • Loading branch information
spencerpogo committed Jan 23, 2022
1 parent 008c986 commit be5e85c
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions api/src/resolvers/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import {
} from "type-graphql";
import { getRepository } from "typeorm";
import { v4 as uuidv4 } from "uuid";
import { timestampToDate } from "../dates.js";
import { dateToTimestamp } from "../dates.js";
import {
genGithubLoginURL,
getGitHubInfo,
LoginError,
tokenFromCode,
} from "../githubAuth.js";
import { isAuthed, mustAuth } from "../middleware/isAuth.js";
import { EventType } from "../models/Event.js";
import { Event, EventType, toEventType } from "../models/Event.js";
import { User } from "../models/User";
import { MyContext } from "../types";

Expand Down Expand Up @@ -115,21 +115,21 @@ export class UserResolver {
async myEvents(
@Ctx() ctx: MyContext,
@Arg("limit") limit: number,
@Arg("cursor", { nullable: true }) cursor: number
): Promise<Event[]> {
const cursorDate = timestampToDate(cursor);
console.log({ cursorDate });
@Arg("cursor", { nullable: true }) cursor: Date
): Promise<EventType[]> {
// todo: support multiple directions
const qb = getRepository(Event)
.createQueryBuilder("e")
.where("e.userId = :userId", { userId: ctx.req.session.userId })
.orderBy("start", "DESC")
.take(Math.min(limit, 50));

if (!isNaN(cursor)) {
qb.where("e.start = :cursor", { cursor });
if (cursor) {
const cursorTs = dateToTimestamp(cursor);
console.log({ cursor, cursorTs, nan: isNaN(cursorTs) });
if (!isNaN(cursorTs)) qb.where("e.start > :cursor", { cursor: cursorTs });
}

return await qb.getMany();
return (await qb.getMany()).map((e) => toEventType(e));
}
}

0 comments on commit be5e85c

Please sign in to comment.