import { Count , CountSchema , Filter , repository , Where , } from '@loopback/repository' ; import { del , get , getModelSchemaRef , getWhereSchemaFor , param , patch , 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' ; import { Message } from '../models' ; import { MessageRepository } from '../repositories' ; const basePath = '/messages/{id}/messages' ; export class MessageMessageController { constructor ( @ repository ( MessageRepository ) protected messageRepository ) { } @ authenticate ( STRATEGY . BEARER ) @ authorize ( { permissions : [ PermissionKey . ViewMessage ] } ) @ get ( basePath , { security : OPERATION_SECURITY_SPEC , responses : { [ STATUS_CODE . OK ] : { description : 'Array of Message has many Message' , content : { [ CONTENT_TYPE . JSON ] : { schema : { type : 'array' , items : getModelSchemaRef ( Message ) } , } , } , } , } , } ) async find ( @ param . path . string ( 'id' ) id , @ param . query . object ( 'filter' ) filter ? ) { return this . messageRepository . messages ( id ) . find ( filter ) ; } @ authenticate ( STRATEGY . BEARER ) @ authorize ( { permissions : [ PermissionKey . CreateMessage ] } ) @ post ( basePath , { security : OPERATION_SECURITY_SPEC , responses : { [ STATUS_CODE . OK ] : { description : 'Message model instance' , content : { [ CONTENT_TYPE . JSON ] : { schema : getModelSchemaRef ( Message ) } } , } , } , } ) async create ( @ param . path . string ( 'id' ) id , @ requestBody ( { security : OPERATION_SECURITY_SPEC , content : { [ CONTENT_TYPE . JSON ] : { schema : getModelSchemaRef ( Message , { title : 'NewMessageInMessage' , exclude : [ 'id' ] , optional : [ 'parentMessageId' ] , } ) , } , } , } ) message ) { return this . messageRepository . messages ( id ) . create ( message ) ; } @ authenticate ( STRATEGY . BEARER ) @ authorize ( { permissions : [ PermissionKey . UpdateMessage ] } ) @ patch ( basePath , { security : OPERATION_SECURITY_SPEC , responses : { [ STATUS_CODE . OK ] : { description : 'Message.Message PATCH success count' , content : { [ CONTENT_TYPE . JSON ] : { schema : CountSchema } } , } , } , } ) async patch ( @ param . path . string ( 'id' ) id , @ requestBody ( { content : { [ CONTENT_TYPE . JSON ] : { schema : getModelSchemaRef ( Message , { partial : true } ) , } , } , } ) message , @ param . query . object ( 'where' , getWhereSchemaFor ( Message ) ) where ? ) { return this . messageRepository . messages ( id ) . patch ( message , where ) ; } @ authenticate ( STRATEGY . BEARER ) @ authorize ( { permissions : [ PermissionKey . DeleteMessage ] } ) @ del ( basePath , { security : OPERATION_SECURITY_SPEC , responses : { [ STATUS_CODE . OK ] : { description : 'Message.Message DELETE success count' , content : { [ CONTENT_TYPE . JSON ] : { schema : CountSchema } } , } , } , } ) async delete ( @ param . path . string ( 'id' ) id , @ param . query . object ( 'where' , getWhereSchemaFor ( Message ) ) where ? ) { return this . messageRepository . messages ( id ) . delete ( where ) ; } }