@@ -41,6 +41,7 @@ import { IoTDeviceService } from "@services/device-management/iot-device.service
4141import { AuditLog } from "@services/audit-log.service" ;
4242import { ActionType } from "@entities/audit-log-entry" ;
4343import { ApiAuth } from "@auth/swagger-auth-decorator" ;
44+ import { AppendCopiedDeviceDto } from "@dto/append-copied-device.dto" ;
4445
4546@ApiTags ( "IoT-Device, PayloadDecoder and DataTarget Connection" )
4647@Controller ( "iot-device-payload-decoder-data-target-connection" )
@@ -205,6 +206,33 @@ export class IoTDevicePayloadDecoderDataTargetConnectionController {
205206 }
206207 }
207208
209+ @Put ( "appendCopiedDevice/:id" )
210+ @ApplicationAdmin ( )
211+ @ApiNotFoundResponse ( {
212+ description : "If the id of the entity doesn't exist" ,
213+ } )
214+ @ApiBadRequestResponse ( {
215+ description : "If one or more of the id's are invalid references." ,
216+ } )
217+ async appendCopiedDevice (
218+ @Req ( ) req : AuthenticatedRequest ,
219+ @Param ( "id" , new ParseIntPipe ( ) ) id : number ,
220+ @Body ( ) dto : AppendCopiedDeviceDto
221+ ) : Promise < IoTDevicePayloadDecoderDataTargetConnection > {
222+ try {
223+ const newIotDevice = await this . iotDeviceService . findOne ( dto . deviceId ) ;
224+ checkIfUserHasAccessToApplication ( req , newIotDevice . application . id , ApplicationAccessScope . Write ) ;
225+
226+ const result = await this . service . appendCopiedDevice ( id , newIotDevice , req . user . userId ) ;
227+
228+ AuditLog . success ( ActionType . UPDATE , IoTDevicePayloadDecoderDataTargetConnection . name , req . user . userId , result . id ) ;
229+ return result ;
230+ } catch ( err ) {
231+ AuditLog . fail ( ActionType . UPDATE , IoTDevicePayloadDecoderDataTargetConnection . name , req . user . userId , id ) ;
232+ throw err ;
233+ }
234+ }
235+
208236 @Delete ( ":id" )
209237 @ApplicationAdmin ( )
210238 @ApiNotFoundResponse ( {
0 commit comments