import { BaseAPI } from '../common/BaseApi'; import { UnlApiConfig } from '../models'; import { ImdfFile } from './models/ImdfFile'; import { ImdfFeatureType } from './models/ImdfFeatureType'; import { Venue } from './models/Venue'; /** * VenuesApi class contains all the methods related to imdf venues. * @class VenuesApi * @extends {BaseAPI} */ export default class VenuesApi extends BaseAPI { constructor(configuration: UnlApiConfig) { super(configuration); } /** * Upload the archive which contains the imdf files. * * @param {string} projectId Id of the project where the imdf venue is uploaded. * @param {File} imdfArchive Zip archive to be uploaded. * @return {Promise} A promise that, in case of success, returns the venue object representing the uploaded entity. * @memberof VenuesApi */ public uploadImdfArchive(projectId: string, imdfArchive: File): Promise { const pathParamMap = { project_id: projectId, }; let formData = new FormData(); formData.append('file', imdfArchive); return this.restClient.post('projects/{project_id}/imdf', pathParamMap, formData, true); } /** * Download an imdf venue archive. * * @param {string} projectId Id of the project the venue is belonging to. * @param {string} venueId Id of the requested venue. * @return {Promise} A promise that, in case of success, returns the zip file representing the requested archive. * @memberof VenuesApi */ public downloadImdfArchive(projectId: string, venueId: string): Promise { const pathParamMap = { project_id: projectId, venue_id: venueId, }; return this.restClient.get( 'projects/{project_id}/imdf/{venue_id}/zip', pathParamMap, undefined, true ); } /** * Get the imdf files associated to a venue. The requested file types are not specified, all the files will be returned. * * @param {string} projectId Id of the project to get the files from. * @param {string} venueId Id of the venue the files are belonging to. * @param {ImdfFileType} includedFeatureTypes The list of feature types to be included in the response. If missing, all the files will be included. * @return {Promise} A promise that, in case of success, returns the requested ImdfFile object. * @memberof VenuesApi */ public getImdfFeatures( projectId: string, venueId: string, includedFeatureTypes?: ImdfFeatureType[] ): Promise { const pathParamMap = { project_id: projectId, venue_id: venueId, }; const queryParams = { type: includedFeatureTypes?.join() }; return this.restClient.get( 'projects/{project_id}/imdf/{venue_id}', pathParamMap, queryParams ); } /** * Get an ImdfFile which is part of an imdf venue. * * @param {string} projectId Id of the project the venue is belonging to. * @param {string} venueId Id of the venue the file is belonging to. * @param {ImdfFileType} featureType Type of the requested file. * @return {Promise} A promise that, in case of success, returns the requested ImdfFile object. * @memberof VenuesApi */ public getImdfFeature( projectId: string, venueId: string, featureType: ImdfFeatureType ): Promise { const pathParamMap = { project_id: projectId, venue_id: venueId, type: featureType, }; return this.restClient.get( 'projects/{project_id}/imdf/{venue_id}/types/{type}', pathParamMap ); } /** * Update an imdf venue archive. * * @param {string} projectId Id of the project the venue is belonging to. * @param {string} venueId Id of the venue to be updated. * @param {File} imdfArchive Zip archive representing the updated venue. * @return {Promise} A promise that, in case of success, returns the venue object representing the updated entity. * @memberof VenuesApi */ public updateImdfArchive(projectId: string, venueId: string, imdfArchive: File): Promise { const pathParamMap = { project_id: projectId, venue_id: venueId, }; let formData = new FormData(); formData.append('file', imdfArchive); return this.restClient.put( 'projects/{project_id}/imdf/{venue_id}/zip', pathParamMap, formData, true ); } /** * Update an ImdfFile which is part of an imdf venue. * * @param {string} projectId Id of the project the venue is belonging to. * @param {string} venueId Id of the venue whose ImdfFile is updated. * @param {ImdfFeatureType} featureType Type of the updated ImdfFile. * @param {GeoJSON.Feature} feature Updated feature. * @return {Promise} A promise that, in case of success, returns the updated ImdfFile object. * @memberof VenuesApi */ public updateImdfFeature( projectId: string, venueId: string, featureType: ImdfFeatureType, feature: GeoJSON.Feature ): Promise { const pathParamMap = { project_id: projectId, venue_id: venueId, type: featureType, }; return this.restClient.put( 'projects/{project_id}/imdf/{venue_id}/types/{type}', pathParamMap, { geojson: feature } ); } /** * Delete an imdf venue. * * @param {string} projectId Id of the project the venue is belonging to. * @param {string} venueId Id of the venue to be deleted. * @return {Promise} A promise that, in case of success, returns the venue object representing the deleted entity. * @memberof VenuesApi */ public delete(projectId: string, venueId: string): Promise { const pathParamMap = { project_id: projectId, venue_id: venueId, }; return this.restClient.delete('projects/{project_id}/imdf/{venue_id}', pathParamMap); } }