]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - shared/extra-utils/users/user-subscriptions.ts
replace numbers with typed http status codes (#3409)
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / users / user-subscriptions.ts
index 7148fbfca98e00e4fe923bdbb2697b2ab3a55914..edc7a3562fdb32e6a7982ad553fae18cb2b69889 100644 (file)
@@ -1,6 +1,7 @@
 import { makeDeleteRequest, makeGetRequest, makePostBodyRequest } from '../requests/requests'
+import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
 
-function addUserSubscription (url: string, token: string, targetUri: string, statusCodeExpected = 204) {
+function addUserSubscription (url: string, token: string, targetUri: string, statusCodeExpected = HttpStatusCode.NO_CONTENT_204) {
   const path = '/api/v1/users/me/subscriptions'
 
   return makePostBodyRequest({
@@ -12,7 +13,14 @@ function addUserSubscription (url: string, token: string, targetUri: string, sta
   })
 }
 
-function listUserSubscriptions (url: string, token: string, sort = '-createdAt', statusCodeExpected = 200) {
+function listUserSubscriptions (parameters: {
+  url: string
+  token: string
+  sort?: string
+  search?: string
+  statusCodeExpected?: number
+}) {
+  const { url, token, sort = '-createdAt', search, statusCodeExpected = HttpStatusCode.OK_200 } = parameters
   const path = '/api/v1/users/me/subscriptions'
 
   return makeGetRequest({
@@ -20,11 +28,14 @@ function listUserSubscriptions (url: string, token: string, sort = '-createdAt',
     path,
     token,
     statusCodeExpected,
-    query: { sort }
+    query: {
+      sort,
+      search
+    }
   })
 }
 
-function listUserSubscriptionVideos (url: string, token: string, sort = '-createdAt', statusCodeExpected = 200) {
+function listUserSubscriptionVideos (url: string, token: string, sort = '-createdAt', statusCodeExpected = HttpStatusCode.OK_200) {
   const path = '/api/v1/users/me/subscriptions/videos'
 
   return makeGetRequest({
@@ -36,7 +47,7 @@ function listUserSubscriptionVideos (url: string, token: string, sort = '-create
   })
 }
 
-function getUserSubscription (url: string, token: string, uri: string, statusCodeExpected = 200) {
+function getUserSubscription (url: string, token: string, uri: string, statusCodeExpected = HttpStatusCode.OK_200) {
   const path = '/api/v1/users/me/subscriptions/' + uri
 
   return makeGetRequest({
@@ -47,7 +58,7 @@ function getUserSubscription (url: string, token: string, uri: string, statusCod
   })
 }
 
-function removeUserSubscription (url: string, token: string, uri: string, statusCodeExpected = 204) {
+function removeUserSubscription (url: string, token: string, uri: string, statusCodeExpected = HttpStatusCode.NO_CONTENT_204) {
   const path = '/api/v1/users/me/subscriptions/' + uri
 
   return makeDeleteRequest({
@@ -58,7 +69,7 @@ function removeUserSubscription (url: string, token: string, uri: string, status
   })
 }
 
-function areSubscriptionsExist (url: string, token: string, uris: string[], statusCodeExpected = 200) {
+function areSubscriptionsExist (url: string, token: string, uris: string[], statusCodeExpected = HttpStatusCode.OK_200) {
   const path = '/api/v1/users/me/subscriptions/exist'
 
   return makeGetRequest({