vtb-appit 0.0.81 → 0.0.83

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/appit.js +31 -2
  2. package/package.json +1 -1
package/appit.js CHANGED
@@ -813,9 +813,38 @@ class Appit {
813
813
  return await this.request('PUT', `excursions/${id}`, data);
814
814
  }
815
815
 
816
+ // async createTravel(data)
817
+ // {
818
+ // return await this.request('POST', `travels`, data);
819
+ // }
816
820
  async createTravel(data)
817
821
  {
818
- return await this.request('POST', `travels`, data);
822
+ const formData = new FormData();
823
+
824
+ Object.keys(data).forEach(key => {
825
+ if(key === 'file') return;
826
+ formData.append(key, data[key]);
827
+ });
828
+
829
+ if(data.file) {
830
+ formData.append('files[id][]', '');
831
+ formData.append('files[title][]', data.title);
832
+ formData.append('files[file][]', fs.createReadStream(data.file));
833
+ }
834
+ let response = false;
835
+ try {
836
+ response = await axios.post('https://portal.appit4travel.com/api/v1/travels', formData, {
837
+ headers: {
838
+ 'Content-Type': `multipart/form-data ${formData.getBoundary()}`,
839
+ Authorization: 'Bearer ' + this.token
840
+ },
841
+ });
842
+
843
+ console.log('Travel posted successfully:', response.data);
844
+ } catch (error) {
845
+ console.log('error');
846
+ }
847
+ return response.data;
819
848
  }
820
849
 
821
850
  async updateTravel(id, data)
@@ -1026,4 +1055,4 @@ class Appit {
1026
1055
  }
1027
1056
  }
1028
1057
 
1029
- module.exports = { Appit };
1058
+ module.exports = { Appit };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vtb-appit",
3
- "version": "0.0.81",
3
+ "version": "0.0.83",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {},