Skip to content

Commit

Permalink
more logs (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShubhamPalriwala authored Mar 5, 2024
1 parent 0f4d15c commit f249f24
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/enrollment/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { DatabaseError } from "@/types/errors";
import { TRepository } from "@/types/repository";
import { Prisma } from "@prisma/client";

import { getRepositoryById } from "../repository/service";
import { getUser } from "../user/service";
import { validateInputs } from "../utils/validate";

/**
Expand Down Expand Up @@ -36,6 +38,12 @@ export const createEnrollment = async (enrollmentData: TEnrollmentInput): Promis
data: enrollmentData,
});

const user = await getUser(enrollmentData.userId);
console.log("user", user);

const repository = await getRepositoryById(enrollmentData.repositoryId);
console.log("repository", repository);

console.log("new enrollment created", enrollment);

return enrollment;
Expand Down
24 changes: 24 additions & 0 deletions lib/repository/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,27 @@ export const getRepositoryByGithubId = async (githubId: number) => {
throw error;
}
};

export const getRepositoryById = async (id: string) => {
try {
const repository = await db.repository.findFirst({
where: {
id,
},
include: {
installation: {
include: {
memberships: true,
},
},
},
});
return repository;
} catch (error) {
if (error instanceof Prisma.PrismaClientKnownRequestError) {
console.error("An error occurred while fetching repository:", error.message);
throw new Error("Database error occurred");
}
throw error;
}
};

0 comments on commit f249f24

Please sign in to comment.