@@ -2,7 +2,7 @@ import {AxiosStatic} from "axios"
2
2
import { IRElementType , IRElementStatus , PermissionEnum } from "@/store/modules/IRElements/types"
3
3
import { convertToSnakeCase } from '@/utils/elementUtils'
4
4
5
- const IRElementAPIPaths : { [ key in IRElementType ] ?: string } = {
5
+ const IRElementAPIPaths : { [ key in IRElementType ] ?: string } = {
6
6
[ IRElementType . Alertgroup ] : "/alertgroup" ,
7
7
[ IRElementType . Event ] : "/event" ,
8
8
[ IRElementType . Alert ] : "/alert" ,
@@ -142,14 +142,15 @@ export default (axios: AxiosStatic) => ({
142
142
} )
143
143
} ,
144
144
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 > {
146
146
return axios ( {
147
147
url : '/file/' ,
148
148
method : 'POST' ,
149
149
headers : {
150
150
'Content-Type' : 'multipart/form-data' ,
151
151
'target_type' : targetType ,
152
152
'target_id' : targetId ,
153
+ 'description' : description
153
154
} ,
154
155
withCredentials : true ,
155
156
data : formData
@@ -195,6 +196,26 @@ export default (axios: AxiosStatic) => ({
195
196
} )
196
197
} ,
197
198
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
+
198
219
async undeleteElementById ( elementId : number , elementType : IRElementType , keep_id : boolean = true ) {
199
220
const path = IRElementAPIPaths [ elementType ] + '/undelete'
200
221
return axios ( {
@@ -615,6 +636,18 @@ export default (axios: AxiosStatic) => ({
615
636
} )
616
637
} ,
617
638
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
+
618
651
async removeEntityClass ( entityId :number , entityClassesToRemove :any ) : Promise < any > {
619
652
return axios ( {
620
653
url : `/entity/${ entityId } /entity_class/remove` ,
@@ -742,4 +775,57 @@ export default (axios: AxiosStatic) => ({
742
775
withCredentials : true
743
776
} )
744
777
} ,
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