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 30 | 1x 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];
}
}
|