Skip to content

Commit

Permalink
refactor: deprecated prismaCall and remove old comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Paulijuz committed Jan 23, 2025
1 parent eb026f2 commit bcf5234
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/services/career/companies/read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const readCompanyPage = ServiceMethod({
z.object({
name: z.string().optional(),
}),
), // Created from ReadPageInput<number, CompanyCursor, CompanyDetails>
),
auther: readCompanyAuther,
dynamicAuthFields: () => ({}),
method: async ({ prisma, params }) => await prisma.company.findMany({
Expand Down
2 changes: 1 addition & 1 deletion src/services/career/jobAds/read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export const readInactiveJobAdsPage = ServiceMethod({
name: z.string().nullable(),
type: z.nativeEnum(JobType).nullable(),
}),
), // Created from ReadPageInput<number, JobAdInactiveCursor, JobAdInactiveDetails>
),
auther: readJobAdAuther,
dynamicAuthFields: () => ({}),
method: async ({ prisma, params }): Promise<SimpleJobAd[]> => {
Expand Down
2 changes: 1 addition & 1 deletion src/services/dots/read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const readDotsPage = ServiceMethod({
userId: z.number().nullable(),
onlyActive: z.boolean(),
}),
), // Created from ReadPageInput<number, DotCursor, DotDetails> TODO: Maybe refactor to be more reusable?
),
method: async ({ prisma, params }) => (await prisma.dotWrapper.findMany({
...cursorPageingSelection(params.paging.page),
where: {
Expand Down
11 changes: 10 additions & 1 deletion src/services/prismaCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ const errorMessagesMap: { [key: string]: [ServerErrorCode, string] } = {

/**
* A function that translates prisma calls into ServerErorrs if they throw errors
*
* THIS FUNCTION HAS BEEN DEPRECATED IN FAVOR OF prismaErrorWrapper
*
* @deprecated
* @param call - A async prisma function to call.
* @returns
*/
Expand All @@ -27,7 +31,12 @@ export async function prismaCall<T>(call: () => T | Promise<T>): Promise<T> {
}
}

// Gjør ikke denne funksjonen akkurat det samme som prismaCall???
/**
* A function that wraps a prisma call in a try catch block and throws a ServerError if it fails.
*
* @param call - The function to be wrapped
* @returns
*/
export async function prismaErrorWrapper<T>(
call: () => Promise<T>,
) {
Expand Down
19 changes: 0 additions & 19 deletions src/services/users/read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,25 +141,6 @@ export async function readUserOrNull(where: readUserWhere): Promise<User | null>
return await prismaCall(() => prisma.user.findFirst({ where }))
}

// export async function readUserProfile(username: string): Promise<Profile> {
// const defaultProfileImage = await readSpecialImage('DEFAULT_PROFILE_IMAGE')
// const user = await prismaCall(() => prisma.user.findUniqueOrThrow({
// where: { username: username.toLowerCase() },
// select: {
// ...userFilterSelection,
// bio: true,
// image: true,
// },
// })).then(u => ({
// ...u,
// image: u.image || defaultProfileImage
// }))
// const memberships = await readMembershipsOfUser(user.id)
// const permissions = await readPermissionsOfUser(user.id)

// return { user, memberships, permissions }
// }

export const readUserProfile = ServiceMethod({
paramsSchema: z.object({
username: z.string(),
Expand Down

0 comments on commit bcf5234

Please sign in to comment.