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>
28 lines
667 B
TypeScript
28 lines
667 B
TypeScript
import { graphql } from '@octokit/graphql';
|
|
|
|
import { insertMany } from '@/database/database';
|
|
import { githubStarsModel } from '@/database/model';
|
|
import { Repository } from '@/github-sync/contributors/types';
|
|
|
|
export const fetchAndSaveGithubStars = async (
|
|
query: typeof graphql,
|
|
): Promise<void> => {
|
|
const { repository } = await query<Repository>(`
|
|
query {
|
|
repository(owner: "twentyhq", name: "twenty") {
|
|
stargazers {
|
|
totalCount
|
|
}
|
|
}
|
|
}
|
|
`);
|
|
|
|
const numberOfStars = repository.stargazers.totalCount;
|
|
|
|
await insertMany(githubStarsModel, [
|
|
{
|
|
numberOfStars,
|
|
},
|
|
]);
|
|
};
|