File size: 1,046 Bytes
f5957a1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { Injectable, Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { SslCertificate } from '../entities/ssl-certificate.entity';

@Injectable()
export class SslService {
  private readonly logger = new Logger(SslService.name);

  constructor(
    @InjectRepository(SslCertificate)
    private sslRepo: Repository<SslCertificate>,
  ) {}

  async getCertificates() {
    const data = await this.sslRepo.find({
      order: { validUntil: 'ASC' },
    });
    return { data };
  }

  async getCertificateDetails(id: number) {
    const cert = await this.sslRepo.findOne({ where: { certId: id } });
    if (!cert) {
      return { message: `SSL certificate #${id} not found` };
    }
    return { data: cert };
  }

  async getExpiringCertificates() {
    const data = await this.sslRepo
      .createQueryBuilder('ssl')
      .where("ssl.status IN ('expiring_soon', 'expired')")
      .orderBy('ssl.valid_until', 'ASC')
      .getMany();

    return { data };
  }
}