|
| 1 | +import { Controller, Get } from "routing-controllers"; |
| 2 | +import { OpenAPI, ResponseSchema } from "routing-controllers-openapi"; |
| 3 | +import { Service } from "typedi"; |
| 4 | + |
| 5 | +import { GithubService } from "../github/service"; |
| 6 | +import { GetMilestonesResponseDto } from "./types"; |
| 7 | + |
| 8 | +@Service() |
| 9 | +@Controller("/Milestones") |
| 10 | +export class MilestoneController { |
| 11 | + constructor(private readonly githubService: GithubService) {} |
| 12 | + |
| 13 | + @Get("/dzcode") |
| 14 | + @OpenAPI({ |
| 15 | + summary: "Return a list of milestones for all dzcode.io repo", |
| 16 | + }) |
| 17 | + @ResponseSchema(GetMilestonesResponseDto) |
| 18 | + public async getMilestones(): Promise<GetMilestonesResponseDto> { |
| 19 | + const githubMilestones = await this.githubService.listRepositoryMilestones({ |
| 20 | + owner: "dzcode-io", |
| 21 | + repo: "dzcode.io", |
| 22 | + }); |
| 23 | + return { |
| 24 | + // @TODO-ZM: sort milestones based on: status:closed by closedAt,and status:open: dueAt, createdAt |
| 25 | + milestones: githubMilestones.map((githubMilestone) => ({ |
| 26 | + id: `${githubMilestone.number}`, |
| 27 | + title: githubMilestone.title, |
| 28 | + description: githubMilestone.description, |
| 29 | + url: githubMilestone.html_url, |
| 30 | + status: githubMilestone.state, |
| 31 | + closedIssuesCount: githubMilestone.closed_issues, |
| 32 | + openIssuesCount: githubMilestone.open_issues, |
| 33 | + createdAt: githubMilestone.created_at, |
| 34 | + closedAt: githubMilestone.closed_at || undefined, |
| 35 | + dueAt: githubMilestone.due_on || undefined, |
| 36 | + })), |
| 37 | + }; |
| 38 | + } |
| 39 | +} |
0 commit comments