-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
861 additions
and
382 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
apps/backend/src/handlers/codemod-runs/codemod-runs.get.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import type { ApiResponse } from "@codemod-com/api-types"; | ||
import type { UserDataPopulatedRequest } from "@codemod-com/auth"; | ||
import { prisma } from "@codemod-com/database"; | ||
import type { CodemodRun } from "@codemod-com/database"; | ||
import type { RouteHandler } from "fastify"; | ||
import { parsePaginatedGetQuery } from "#schemata/schema.js"; | ||
|
||
export type GetCodemodRunsResponse = ApiResponse<{ | ||
total: number; | ||
data: CodemodRun[]; | ||
}>; | ||
|
||
export const getCodemodRunsHandler: RouteHandler<{ | ||
Reply: GetCodemodRunsResponse; | ||
}> = async (request: UserDataPopulatedRequest) => { | ||
const query = parsePaginatedGetQuery(request.query); | ||
|
||
const userId = request.user?.id; | ||
const [total, codemodRuns] = await Promise.all([ | ||
prisma.codemodRun.count({ | ||
where: { ownerId: userId }, | ||
}), | ||
prisma.codemodRun.findMany({ | ||
where: { ownerId: userId }, | ||
take: query.size, | ||
skip: query.size && query.page ? query.size * (query.page - 1) : 0, | ||
}), | ||
]); | ||
|
||
return { | ||
total, | ||
data: codemodRuns, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.