All files / src/repositories/scan attachment.repository.ts

58.33% Statements 7/12
100% Branches 0/0
0% Functions 0/3
50% Lines 5/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 301x 1x 1x   1x   1x                                              
import {inject} from '@loopback/core';
import {BaseCrudRepository} from '../base-crud.repository.base';
import {LogChainDataSource} from '../../datasources';
 
import {Attachment, AttachmentRelations} from '../../models/scan/attachment.model';
 
export class AttachmentRepository extends BaseCrudRepository<
  Attachment,
  typeof Attachment.prototype.id,
  AttachmentRelations
> {
  constructor(@inject('datasources.logchain') dataSource: LogChainDataSource) {
    super(Attachment, dataSource);
  }
 
  async findByPmo(pmoId: number): Promise<Attachment[]> {
    const result = await this.execute(`SELECT * FROM attachment WHERE pmo_id = $1`, [pmoId]);
 
    return result as Attachment[];
  }
 
  async createAttachment(data: {pmo_id: number; type: string; file_url: string}): Promise<Attachment> {
    const result = await this.execute(
      `INSERT INTO attachment (pmo_id, type, file_url, created_at) VALUES ($1, $2, $3, NOW()) RETURNING *`,
      [data.pmo_id, data.type, data.file_url],
    ) as Attachment[];
    return result[0];
  }
}