1
0
mirror of https://github.com/sasjs/adapter.git synced 2025-12-15 18:54:36 +00:00

feat: add deleteFolder function

This commit is contained in:
Yury Shkoda
2020-09-07 09:07:25 +03:00
parent 29d9df5792
commit 7ee9335183

View File

@@ -376,6 +376,8 @@ export class SASViyaApiClient {
if (!parentFolderUri && parentFolderPath) {
parentFolderUri = await this.getFolderUri(parentFolderPath, accessToken)
if (!parentFolderUri) {
if (isForced) this.isForceDeploy = true
console.log(`Parent folder is not present: ${parentFolderPath}`)
const newParentFolderPath = parentFolderPath.substring(
@@ -399,17 +401,11 @@ export class SASViyaApiClient {
parentFolderUri = `/folders/folders/${parentFolder.id}`
} else if (isForced && accessToken && !this.isForceDeploy) {
this.isForceDeploy = true
const recycleBin = await this.getRecycleBin(accessToken)
const recycleBinUri = recycleBin?.id || ''
const oldFolderName = parentFolderPath?.split('/').pop() || ''
const parentFolderId = parentFolderUri?.split('/').pop() || ''
await this.moveFolder(
parentFolderId,
recycleBinUri,
oldFolderName,
accessToken
)
await this.deleteFolder(parentFolderId, oldFolderName, accessToken)
const newParentFolderPath = parentFolderPath.substring(
0,
@@ -1179,6 +1175,24 @@ export class SASViyaApiClient {
return folder
}
private async deleteFolder(
folderId: string,
folderName: string,
accessToken: string
) {
const recycleBin = await this.getRecycleBin(accessToken)
const recycleBinId = recycleBin?.id as string
const movedFolder = await this.moveFolder(
folderId,
recycleBinId,
folderName,
accessToken
)
return movedFolder
}
setCsrfTokenLocal = (csrfToken: CsrfToken) => {
this.csrfToken = csrfToken
this.setCsrfToken(csrfToken)