Skip to content

Commit

Permalink
feat(error) : error 처리추가
Browse files Browse the repository at this point in the history
  • Loading branch information
gitdog01 committed Jan 1, 2024
1 parent 3d788ad commit de76cf4
Showing 1 changed file with 34 additions and 17 deletions.
51 changes: 34 additions & 17 deletions src/routes/v1/index.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
import express from 'express';
import axios from 'axios';
import { getUser } from '@/services/user';
import express from "express";
import axios from "axios";
import { getUser } from "@/services/user";
import {
getUserCommits,
getUserRepoStars,
getFriendsCount,
} from '@/services/index';
import { getRepoCommits } from '@/services/commit';
} from "@/services/index";

const router = express.Router();

router.get('/callback', async (req, res) => {
router.get("/callback", async (req, res) => {
const { code } = req.query;

const result = await axios({
method: 'post',
method: "post",
url: `https://github.com/login/oauth/access_token`,
headers: {
accept: 'application/json',
accept: "application/json",
},
data: {
client_id: Bun.env.CLIENT_ID,
Expand All @@ -34,31 +33,49 @@ router.get('/callback', async (req, res) => {
res.json(true);
});

router.get('/data', async (req, res) => {
router.get("/data", async (req, res) => {
const { accessToken } = req.query;

if (!accessToken) {
// 401 error
res.status(401).json({
message: "accessToken이 없습니다.",
});
return;
}

if (typeof accessToken !== "string") {
// 400 error
res.status(400).json({
message: "accessToken의 타입이 올바르지 않습니다.",
});
return;
}

const user = await getUser(accessToken);
const userName = user.login;

const commits = await getUserCommits(accessToken, userName, {
since: '2023-01-01T00:00:00Z',
until: '2024-01-01T00:00:00Z',
since: "2023-01-01T00:00:00Z",
until: "2024-01-01T00:00:00Z",
per_page: 100,
});

console.log(commits);

const starCount = await getUserRepoStars(accessToken, userName);
const { followerCount, followingCount } = await getFriendsCount(accessToken);

const mostUsedLanguage = ['JavaScript', 'TypeScript', 'Python']; // string[]
const moreThan = 'high'; // high, middle, low
const mostUsedLanguage = ["JavaScript", "TypeScript", "Python"]; // string[]
const moreThan = "high"; // high, middle, low
const commitCount = 1234; // number
const commitDate = '월요일'; // 월요일, 화요일, 수요일, 목요일, 금요일, 토요일, 일요일
const commitDate = "월요일"; // 월요일, 화요일, 수요일, 목요일, 금요일, 토요일, 일요일
const mostCommunication = {
// 여기 줄때 github profile 주소도 주면 좋지 않을까 ?
name: 'bsy1141', // string
image: 'https://avatars.githubusercontent.com/u/60652298?v=4', // string
name: "bsy1141", // string
image: "https://avatars.githubusercontent.com/u/60652298?v=4", // string
};
const mbti = 'INFP'; // string
const mbti = "INFP"; // string

res.json({
commits,
Expand Down

0 comments on commit de76cf4

Please sign in to comment.