-
Notifications
You must be signed in to change notification settings - Fork 939
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: Airtable & GS endpoints to use responses return objects #1592
Conversation
The latest updates on your projects. Learn more about Vercel for Git 鈫楋笌 2 Ignored Deployments
|
Thank you for following the naming conventions for pull request titles! 馃檹 |
responses.jsIt's a good practice to centralize the error handling and response generation in APIs. This will make the code more maintainable and readable. In the PR, the error handling and response generation are scattered across different routes. It would be better to create a separate utility for generating responses and handling errors. // Create a new file responses.js
export const responses = {
successResponse: (data) => {
return NextResponse.json({ data }, { status: 200 });
},
badRequestResponse: (message) => {
return NextResponse.json({ error: message }, { status: 400 });
},
notAuthenticatedResponse: () => {
return NextResponse.json({ error: "Invalid session" }, { status: 400 });
},
unauthorizedResponse: () => {
return NextResponse.json({ error: "You don't have access to environment" }, { status: 401 });
},
notFoundResponse: (message, data) => {
return NextResponse.json({ error: message, data }, { status: 404 });
},
internalServerErrorResponse: (message) => {
return NextResponse.json({ error: message }, { status: 500 });
},
}; integration/service.jsThe creation and update of the integration are repeated in the code. It would be better to create a separate function for this operation to avoid code duplication and enhance readability. // Create a new function in the integration service
export const createOrUpdateIntegration = async (environmentId, integration) => {
return await prisma.integration.upsert({
where: {
type_environmentId: {
environmentId,
type: integration.type,
},
},
update: {
...integration,
environment: { connect: { id: environmentId } },
},
create: {
...integration,
environment: { connect: { id: environmentId } },
},
});
}; Multiple filesThe variable name // Replace all occurrences of AIR_TABLE_CLIENT_ID with AIRTABLE_CLIENT_ID
const client_id = AIRTABLE_CLIENT_ID; airtable.tsThe fetchTables function is currently returning the entire response object. It would be better to return only the data property of the response to reduce the amount of data being transferred. // Refactor the fetchTables function
export const fetchTables = async (environmentId: string, baseId: string) => {
const res = await fetch(`/api/v1/integrations/airtable/tables?baseId=${baseId}`, {
method: "GET",
headers: { environmentId: environmentId },
cache: "no-store",
});
const resJson = await res.json();
return resJson.data as Promise<TIntegrationAirtableTables>;
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Dhruwang thank you for the changes 馃槉馃檹
What does this PR do?
Fixes 1458
Type of change
How should this be tested?
Checklist
Required
pnpm build
console.logs
git pull origin main
Appreciated