Make Github stars dynamic and improve database init (#5000)
I extracted the init database logic into its own file. You can now run it with yarn database:init. Added database entry for GitHub stars. Do you want me to remove the init route or is it used for something else ? --------- Co-authored-by: Ady Beraud <a.beraud96@gmail.com> Co-authored-by: Félix Malfait <felix.malfait@gmail.com>
This commit is contained in:
26
packages/twenty-website/src/app/api/github-stars/route.tsx
Normal file
26
packages/twenty-website/src/app/api/github-stars/route.tsx
Normal file
@ -0,0 +1,26 @@
|
||||
import { desc } from 'drizzle-orm';
|
||||
|
||||
import { findOne } from '@/database/database';
|
||||
import { githubStarsModel } from '@/database/model';
|
||||
import { formatNumberOfStars } from '@/shared-utils/formatNumberOfStars';
|
||||
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
const githubStars = await findOne(
|
||||
githubStarsModel,
|
||||
desc(githubStarsModel.timestamp),
|
||||
);
|
||||
|
||||
const formattedGithubNumberOfStars = formatNumberOfStars(
|
||||
githubStars[0].numberOfStars,
|
||||
);
|
||||
|
||||
return Response.json(formattedGithubNumberOfStars);
|
||||
} catch (error: any) {
|
||||
return new Response(`Github stars error: ${error?.message}`, {
|
||||
status: 500,
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user