Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

debug: add more logs #21

Merged
merged 1 commit into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
};
Loading