src/insight/insight-repo.service.ts
Methods |
|
constructor(insightRepoRepository: Repository
|
|||||||||
|
Defined in src/insight/insight-repo.service.ts:10
|
|||||||||
|
Parameters :
|
| Async addInsightRepo |
addInsightRepo(insightId: number, repoInfo: RepoInfo)
|
|
Defined in src/insight/insight-repo.service.ts:17
|
|
Returns :
unknown
|
| Async findReposById | ||||||
findReposById(insightId: number)
|
||||||
|
Defined in src/insight/insight-repo.service.ts:44
|
||||||
|
Parameters :
Returns :
unknown
|
| Async removeInsightRepo | ||||||
removeInsightRepo(id: number)
|
||||||
|
Defined in src/insight/insight-repo.service.ts:48
|
||||||
|
Parameters :
Returns :
unknown
|
import { BadRequestException, Injectable } from "@nestjs/common";
import { Repository } from "typeorm";
import { InjectRepository } from "@nestjs/typeorm";
import { RepoInfo } from "../repo/dtos/repo-info.dto";
import { RepoService } from "../repo/repo.service";
import { DbInsightRepo } from "./entities/insight-repo.entity";
@Injectable()
export class InsightRepoService {
constructor(
@InjectRepository(DbInsightRepo, "ApiConnection")
private insightRepoRepository: Repository<DbInsightRepo>,
private repoService: RepoService
) {}
async addInsightRepo(insightId: number, repoInfo: RepoInfo) {
if (!repoInfo.id && !repoInfo.fullName) {
throw new BadRequestException("either repo id or repo full name must be provided");
}
let org;
let name;
if (repoInfo.fullName) {
const parts = repoInfo.fullName.split("/");
if (parts.length !== 2) {
throw new BadRequestException("given repo full name is not valid owner/name repo");
}
[org, name] = parts;
}
const repo = await this.repoService.tryFindRepoOrMakeStub({ repoId: repoInfo.id, repoOwner: org, repoName: name });
return this.insightRepoRepository.save({
insight_id: insightId,
repo_id: repo.id,
full_name: repo.full_name,
});
}
async findReposById(insightId: number) {
return this.insightRepoRepository.find({ where: { insight_id: insightId } });
}
async removeInsightRepo(id: number) {
return this.insightRepoRepository.softDelete(id);
}
}