import { Count , CountSchema , Filter , FilterExcludingWhere , repository , Where , } from '@loopback/repository' ; import { get , getModelSchemaRef , param , post , requestBody } from '@loopback/rest' ; import { CONTENT_TYPE , OPERATION_SECURITY_SPEC , STATUS_CODE , } from '@sourceloop/core' ; import { authenticate , STRATEGY } from 'loopback4-authentication' ; import { authorize } from 'loopback4-authorization' ; import { PermissionKey } from '../enums/permission-key.enum' ; import { AuditLog } from '../models' ; import { AuditLogRepository } from '../repositories' ; const basePath = '/audit-logs' ; export class AuditController { constructor ( @ repository ( AuditLogRepository ) public auditLogRepository ) { } @ authenticate ( STRATEGY . BEARER ) @ authorize ( { permissions : [ PermissionKey . CreateAudit ] } ) @ post ( basePath , { security : OPERATION_SECURITY_SPEC , responses : { [ STATUS_CODE . OK ] : { description : 'AuditLog model instance' , content : { [ CONTENT_TYPE . JSON ] : { schema : getModelSchemaRef ( AuditLog ) } } , } , } , } ) async create ( @ requestBody ( { content : { [ CONTENT_TYPE . JSON ] : { schema : getModelSchemaRef ( AuditLog , { title : 'NewAuditLog' , exclude : [ 'id' ] , } ) , } , } , } ) auditLog ) { return this . auditLogRepository . create ( auditLog ) ; } @ authenticate ( STRATEGY . BEARER ) @ authorize ( { permissions : [ PermissionKey . ViewAudit ] } ) @ get ( `${ basePath }/count` , { security : OPERATION_SECURITY_SPEC , responses : { [ STATUS_CODE . OK ] : { description : 'AuditLog model count' , content : { [ CONTENT_TYPE . JSON ] : { schema : CountSchema } } , } , } , } ) async count ( @ param . where ( AuditLog ) where ? ) { return this . auditLogRepository . count ( where ) ; } @ authenticate ( STRATEGY . BEARER ) @ authorize ( { permissions : [ PermissionKey . ViewAudit ] } ) @ get ( basePath , { security : OPERATION_SECURITY_SPEC , responses : { [ STATUS_CODE . OK ] : { description : 'Array of AuditLog model instances' , content : { [ CONTENT_TYPE . JSON ] : { schema : { type : 'array' , items : getModelSchemaRef ( AuditLog , { includeRelations : true } ) , } , } , } , } , } , } ) async find ( @ param . filter ( AuditLog ) filter ? ) { return this . auditLogRepository . find ( filter ) ; } @ authenticate ( STRATEGY . BEARER ) @ authorize ( { permissions : [ PermissionKey . ViewAudit ] } ) @ get ( `${ basePath }/{id}` , { security : OPERATION_SECURITY_SPEC , responses : { [ STATUS_CODE . OK ] : { description : 'AuditLog model instance' , content : { [ CONTENT_TYPE . JSON ] : { schema : getModelSchemaRef ( AuditLog , { includeRelations : true } ) , } , } , } , } , } ) async findById ( @ param . path . string ( 'id' ) id , @ param . filter ( AuditLog , { exclude : 'where' } ) filter ? ) { return this . auditLogRepository . findById ( id , filter ) ; } }