@@ -2,7 +2,7 @@ import {AxiosStatic} from "axios"
22import { IRElementType , IRElementStatus , PermissionEnum } from "@/store/modules/IRElements/types"
33import { convertToSnakeCase } from '@/utils/elementUtils'
44
5- const IRElementAPIPaths : { [ key in IRElementType ] ?: string } = {
5+ const IRElementAPIPaths : { [ key in IRElementType ] ?: string } = {
66 [ IRElementType . Alertgroup ] : "/alertgroup" ,
77 [ IRElementType . Event ] : "/event" ,
88 [ IRElementType . Alert ] : "/alert" ,
@@ -142,14 +142,15 @@ export default (axios: AxiosStatic) => ({
142142 } )
143143 } ,
144144
145- async submitFile ( formData :FormData , targetType :string , targetId :string ) : Promise < any > {
145+ async submitFile ( formData : FormData , targetType : string , targetId : string , description : string | null = null ) : Promise < any > {
146146 return axios ( {
147147 url : '/file/' ,
148148 method : 'POST' ,
149149 headers : {
150150 'Content-Type' : 'multipart/form-data' ,
151151 'target_type' : targetType ,
152152 'target_id' : targetId ,
153+ 'description' : description
153154 } ,
154155 withCredentials : true ,
155156 data : formData
@@ -195,6 +196,26 @@ export default (axios: AxiosStatic) => ({
195196 } )
196197 } ,
197198
199+ async updateFileById ( fileId : number , filename : string | null , description : string | null ) {
200+ const path = 'file' + '/' + fileId
201+ const data : any = { }
202+ if ( filename ) {
203+ data [ "filename" ] = filename
204+ }
205+ if ( description ) {
206+ data [ "description" ] = description
207+ }
208+ return axios ( {
209+ url : path ,
210+ method : 'PUT' ,
211+ headers : {
212+ 'Content-Type' : 'application/json'
213+ } ,
214+ withCredentials : true ,
215+ data : data
216+ } )
217+ } ,
218+
198219 async undeleteElementById ( elementId : number , elementType : IRElementType , keep_id : boolean = true ) {
199220 const path = IRElementAPIPaths [ elementType ] + '/undelete'
200221 return axios ( {
@@ -615,6 +636,18 @@ export default (axios: AxiosStatic) => ({
615636 } )
616637 } ,
617638
639+ async addEntityTag ( entityId :number , tagToAdd :any ) : Promise < any > {
640+ return axios ( {
641+ url : `/entity/${ entityId } /tag` ,
642+ method : 'POST' ,
643+ headers : {
644+ 'Content-Type' : 'application/json'
645+ } ,
646+ withCredentials :true ,
647+ data : { 'id' : tagToAdd }
648+ } )
649+ } ,
650+
618651 async removeEntityClass ( entityId :number , entityClassesToRemove :any ) : Promise < any > {
619652 return axios ( {
620653 url : `/entity/${ entityId } /entity_class/remove` ,
@@ -742,4 +775,57 @@ export default (axios: AxiosStatic) => ({
742775 withCredentials : true
743776 } )
744777 } ,
745- } ) ;
778+
779+ async upvoteElement ( elementID : number , elementType : IRElementType , abortController : AbortController ) : Promise < any > {
780+ return axios ( {
781+ url : `${ IRElementAPIPaths [ elementType ] } /${ elementID } /upvote` ,
782+ method : 'POST' ,
783+ withCredentials : true ,
784+ signal : abortController ?. signal
785+ } )
786+ } ,
787+
788+ async downvoteElement ( elementID : number , elementType : IRElementType , abortController : AbortController ) : Promise < any > {
789+ return axios ( {
790+ url : `${ IRElementAPIPaths [ elementType ] } /${ elementID } /downvote` ,
791+ method : 'POST' ,
792+ withCredentials : true ,
793+ signal : abortController ?. signal
794+ } )
795+ } ,
796+
797+ async favoriteElement ( elementID : number , elementType : IRElementType , abortController : AbortController ) : Promise < any > {
798+ return axios ( {
799+ url : `${ IRElementAPIPaths [ elementType ] } /${ elementID } /favorite` ,
800+ method : 'POST' ,
801+ withCredentials : true ,
802+ signal : abortController ?. signal
803+ } )
804+ } ,
805+
806+ async subscribeElement ( elementID : number , elementType : IRElementType , abortController : AbortController ) : Promise < any > {
807+ return axios ( {
808+ url : `notification/subscribe` ,
809+ method : 'POST' ,
810+ withCredentials : true ,
811+ data : {
812+ target_type : convertToSnakeCase ( elementType ) ,
813+ target_id : elementID
814+ } ,
815+ signal : abortController ?. signal
816+ } )
817+ } ,
818+
819+ async unsubscribeElement ( elementID : number , elementType : IRElementType , abortController : AbortController ) : Promise < any > {
820+ return axios ( {
821+ url : `notification/unsubscribe` ,
822+ method : 'POST' ,
823+ withCredentials : true ,
824+ data : {
825+ target_type : convertToSnakeCase ( elementType ) ,
826+ target_id : elementID
827+ } ,
828+ signal : abortController ?. signal
829+ } )
830+ } ,
831+ } ) ;
0 commit comments