Skip to content

Commit

Permalink
feat: integrated file upload api
Browse files Browse the repository at this point in the history
Integrated file upload api

BUN-88
  • Loading branch information
b3aton authored and kris liu committed Jul 20, 2022
1 parent 0b2fcb6 commit 3c5b855
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
16 changes: 16 additions & 0 deletions apps/storefront/src/shared/service/b2b/api/global.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { B3Request } from '../../request/b3Fetch'

interface UploadFileData {
file: File,
type?: string
}

export const uploadB2BFile = (data: UploadFileData) => {
const { file, type = '' } = data

const formData = new FormData()
formData.append('mediaFile', file)
formData.append('requestType', type) // companyAttachedFile,quoteAttachedFile

return B3Request.fileUpload('/api/v2/media/upload', formData)
}
5 changes: 5 additions & 0 deletions apps/storefront/src/shared/service/b2b/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import {
getB2BCountries,
} from './graphql/register'

import {
uploadB2BFile,
} from './api/global'

import {
createBCCompanyUser,
} from './api/register'
Expand All @@ -15,4 +19,5 @@ export {
getB2BCompanyUserInfo,
getB2BCountries,
createBCCompanyUser,
uploadB2BFile,
}
8 changes: 8 additions & 0 deletions apps/storefront/src/shared/service/request/b3Fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,12 @@ export const B3Request = {
...config,
})
},
fileUpload: function fileUpload<T, Y>(path: string, formData: T, config?: Y) {
return request(`https://dev-v2.bundleb2b.net/api${path}`, {
method: 'POST',
body: formData,
headers: {},
...config,
})
},
}

0 comments on commit 3c5b855

Please sign in to comment.