|
| 1 | +import { Injectable } from '@nestjs/common'; |
| 2 | +import { InjectRepository } from '@nestjs/typeorm'; |
| 3 | +import { Exploit, Vulnerability } from 'src/entities'; |
| 4 | +import { Repository } from 'typeorm'; |
| 5 | + |
| 6 | +@Injectable() |
| 7 | +export class ExploitsService { |
| 8 | + constructor( |
| 9 | + @InjectRepository(Vulnerability) |
| 10 | + private vulnRepository: Repository<Vulnerability>, |
| 11 | + @InjectRepository(Exploit) |
| 12 | + private exploitRepository: Repository<Exploit>, |
| 13 | + ) {} |
| 14 | + |
| 15 | + async findVulnerability(cveId:string){ |
| 16 | + const vulnerability=await this.vulnRepository.findOne({ |
| 17 | + where:{ |
| 18 | + cveId:cveId |
| 19 | + } |
| 20 | + }) |
| 21 | + return vulnerability; |
| 22 | + } |
| 23 | + |
| 24 | + async create(createExploitDto: any) { |
| 25 | + |
| 26 | + var cves = createExploitDto.cve_id.split(','); |
| 27 | + for (var cve of cves){ |
| 28 | + const currentCve=cve.trim() |
| 29 | + console.log(currentCve); |
| 30 | + const exploit =this.exploitRepository.create({ |
| 31 | + cveId:currentCve, |
| 32 | + name:createExploitDto.name, |
| 33 | + source:createExploitDto.source, |
| 34 | + sourceUrl:createExploitDto.source_url, |
| 35 | + description:createExploitDto.description, |
| 36 | + fileContent:createExploitDto.file_content?createExploitDto.file_content:null, |
| 37 | + isRepo:createExploitDto.is_repo, |
| 38 | + datePublished:createExploitDto.date_published, |
| 39 | + exampleFile:createExploitDto.file_name, |
| 40 | + author:createExploitDto.author, |
| 41 | + downloadFailed:false, |
| 42 | + ignore:false, |
| 43 | + fixed:false, |
| 44 | + dateCreated:null |
| 45 | + }); |
| 46 | + await this.exploitRepository.save(exploit) |
| 47 | + |
| 48 | + } |
| 49 | + return 'This action adds a new exploit'; |
| 50 | + |
| 51 | + } |
| 52 | + |
| 53 | + findAll() { |
| 54 | + return `This action returns all exploits`; |
| 55 | + } |
| 56 | + |
| 57 | + findOne(id: number) { |
| 58 | + return `This action returns a #${id} exploit`; |
| 59 | + } |
| 60 | + |
| 61 | + update(id: number, updateExploitDto: any) { |
| 62 | + return `This action updates a #${id} exploit`; |
| 63 | + } |
| 64 | + |
| 65 | + remove(id: number) { |
| 66 | + return `This action removes a #${id} exploit`; |
| 67 | + } |
| 68 | +} |
0 commit comments