-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TU-13737] fix sonar-project paths p5
- Loading branch information
Showing
2 changed files
with
82 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,89 @@ | ||
import { Typeform } from './typeform-types' | ||
import {Typeform} from './typeform-types' | ||
|
||
export class Images { | ||
constructor(private _http: Typeform.HTTPClient) {} | ||
|
||
public add(args: { | ||
image?: string | ||
url?: string | ||
fileName: string | ||
}): Promise<Typeform.Image> { | ||
const { image, url, fileName } = args | ||
constructor(private _http: Typeform.HTTPClient) { | ||
} | ||
|
||
return this._http.request({ | ||
method: 'post', | ||
url: `/images`, | ||
data: { | ||
image, | ||
file_name: fileName, | ||
url, | ||
}, | ||
}) | ||
} | ||
public add(args: { | ||
image?: string | ||
url?: string | ||
fileName: string | ||
}): Promise<Typeform.Image> { | ||
const {image, url, fileName} = args | ||
|
||
public delete(args: { id: string }): Promise<null> { | ||
const { id } = args | ||
return this._http.request({ | ||
method: 'post', | ||
url: `/images`, | ||
data: { | ||
image, | ||
file_name: fileName, | ||
url, | ||
}, | ||
}) | ||
} | ||
|
||
return this._http.request({ | ||
method: 'delete', | ||
url: `/images/${id}`, | ||
}) | ||
} | ||
public delete(args: { id: string }): Promise<null> { | ||
const {id} = args | ||
|
||
public get(args: { | ||
id: string | ||
size?: string | ||
backgroundSize?: string | ||
choiceSize?: string | ||
}): Promise<Typeform.Image> { | ||
const { id, size, backgroundSize, choiceSize } = args | ||
const requestQuery: Typeform.Request = { | ||
method: 'get', | ||
url: `/images/${id}`, | ||
headers: { | ||
Accept: 'application/json', | ||
}, | ||
return this._http.request({ | ||
method: 'delete', | ||
url: `/images/${id}`, | ||
}) | ||
} | ||
|
||
const choiceImageSizes = [ | ||
'default', | ||
'thumbnail', | ||
'supersize', | ||
'supermobile', | ||
'supersizefit', | ||
'supermobilefit', | ||
] | ||
public get(args: { | ||
id: string | ||
size?: string | ||
backgroundSize?: string | ||
choiceSize?: string | ||
}): Promise<Typeform.Image> { | ||
const {id, size, backgroundSize, choiceSize} = args | ||
const requestQuery: Typeform.Request = { | ||
method: 'get', | ||
url: `/images/${id}`, | ||
headers: { | ||
Accept: 'application/json', | ||
}, | ||
} | ||
|
||
if (size) { | ||
if (['default', 'thumbnail', 'mobile'].includes(size)) { | ||
requestQuery.url += `/image/${size}` | ||
} else { | ||
throw new Error(`Image size doesn't exist`) | ||
} | ||
} else if (backgroundSize) { | ||
if ( | ||
['default', 'thumbnail', 'mobile', 'tablet'].includes(backgroundSize) | ||
) { | ||
requestQuery.url += `/background/${backgroundSize}` | ||
} else { | ||
throw new Error(`Image background size doesn't exist`) | ||
} | ||
} else if (choiceSize) { | ||
if (choiceImageSizes.includes(choiceSize)) { | ||
requestQuery.url += `/choice/${choiceSize}` | ||
} else { | ||
throw new Error(`Image choice size doesn't exist`) | ||
} | ||
} | ||
const choiceImageSizes = [ | ||
'default', | ||
'thumbnail', | ||
'supersize', | ||
'supermobile', | ||
'supersizefit', | ||
'supermobilefit', | ||
] | ||
|
||
return this._http.request(requestQuery) | ||
} | ||
if (size) { | ||
if (['default', 'thumbnail', 'mobile'].includes(size)) { | ||
requestQuery.url += `/image/${size}` | ||
} else { | ||
throw new Error(`Image size doesn't exist`) | ||
} | ||
} else if (backgroundSize) { | ||
if ( | ||
['default', 'thumbnail', 'mobile', 'tablet'].includes(backgroundSize) | ||
) { | ||
requestQuery.url += `/background/${backgroundSize}` | ||
} else { | ||
throw new Error(`Image background size doesn't exist`) | ||
} | ||
} else if (choiceSize) { | ||
if (choiceImageSizes.includes(choiceSize)) { | ||
requestQuery.url += `/choice/${choiceSize}` | ||
} else { | ||
throw new Error(`Image choice size doesn't exist`) | ||
} | ||
} | ||
|
||
public list(): Promise<Typeform.Image[]> { | ||
return this._http.request({ | ||
method: 'get', | ||
url: '/images', | ||
}) | ||
} | ||
return this._http.request(requestQuery) | ||
} | ||
|
||
public list(): Promise<Typeform.Image[]> { | ||
return this._http.request({ | ||
method: 'get', | ||
url: '/images', | ||
}) | ||
} | ||
} |