Skip to content
Snippets Groups Projects
Commit e3e5c3a6 authored by David Schimmel's avatar David Schimmel
Browse files

New: Creat api connection library (coscine/issues#210)

parent 491d4ff8
No related branches found
No related tags found
2 merge requests!2Product/190 common libraries,!1Topic/210 common libraries
......@@ -14,7 +14,7 @@
["@semantic-release/npm", {
"preset": "eslint",
"tarballDir": "dist",
"npmPublish": false
"npmPublish": true
}],
["@semantic-release/git", {
"preset": "eslint",
......
......
{
"name": "@{Provider}/{RepositoryName}",
"version": "1.0.0",
"name": "@coscine/api-connection",
"version": "0.0.1",
"description": "",
"main": "index.js",
"scripts": {
......@@ -47,9 +47,11 @@
},
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org/",
"tag": "latest"
},
"dependencies": {
"@types/node": "^10.12.30"
"@types/node": "^10.12.30",
"axios": "^0.19.0"
}
}
\ No newline at end of file
Source Code gets put here
\ No newline at end of file
import axios from 'axios';
import project from './requests/project-api';
import projectRole from './requests/project-role-api';
import resource from './requests/resource-api';
import resourceType from './requests/resource-type-api';
import role from './requests/role-api';
import subproject from './requests/subproject-api';
import user from './requests/user-api';
const headerKey = 'Authorization';
let hostName = window.location.hostname;
if (hostName.indexOf(':') !== -1) {
if (hostName.indexOf('https://') !== -1) {
hostName = hostName.replace('https://', '');
}
hostName = hostName.substr(0, hostName.indexOf(':'));
}
export default {
getHostName() {
return hostName;
},
setHeader() {
axios.defaults.headers.common[headerKey] = 'Bearer ' + (coscine as any).authorization.bearer;
},
defaultOnCatch(error: any) {
// TODO: Do something with the error
// tslint:disable-next-line: no-console
console.log(error);
},
};
declare var coscine: {
authorization: {
bearer: string,
}
};
declare var _spPageContextInfo: any;
\ No newline at end of file
import apiConnection from '../api-connection';
import axios from 'axios';
function getProjectApiUrl() {
return 'https://' + apiConnection.getHostName() + '/coscine/api/Coscine.Api.Project/Project/';
}
export default {
storeProject(body: any, thenHandler: any, catchHandler: any) {
apiConnection.setHeader();
axios
.post(getProjectApiUrl(), body)
.then(thenHandler)
.catch(catchHandler);
},
getResources(parentId: string, thenHandler: any, catchHandler: any) {
apiConnection.setHeader();
axios
.get(getProjectApiUrl() + parentId + '/resources')
.then(thenHandler)
.catch(catchHandler);
},
getProjects(thenHandler: any, catchHandler: any) {
apiConnection.setHeader();
axios
.get(getProjectApiUrl())
.then(thenHandler)
.catch(catchHandler);
}
}
\ No newline at end of file
import apiConnection from '../api-connection';
import axios from 'axios';
function getProjectRoleApiUrl() {
return 'https://' + apiConnection.getHostName() + '/coscine/api/Coscine.Api.Project/ProjectRole/';
}
export default {
getProjectRoles(parentId: string, thenHandler: any, catchHandler: any) {
apiConnection.setHeader();
axios
.get(getProjectRoleApiUrl() + parentId + '/')
.then(thenHandler)
.catch(catchHandler);
},
setProjectRole(body: any, thenHandler: any, catchHandler: any) {
apiConnection.setHeader();
axios
.post(getProjectRoleApiUrl(), body)
.then(thenHandler)
.catch(catchHandler);
},
deleteUser(parentId: any, userId: any, roleId: any, thenHandler: any, catchHandler: any) {
apiConnection.setHeader();
axios
.delete(getProjectRoleApiUrl() + 'project/' + parentId + '/user/' + userId + '/role/' + roleId)
.then(thenHandler)
.catch(catchHandler);
},
}
\ No newline at end of file
import apiConnection from '../api-connection';
import axios from 'axios';
function getResourceApiUrl() {
return 'https://' + apiConnection.getHostName() + '/coscine/api/Coscine.Api.Project/Resource/';
}
export default {
storeResource(parentId: string, body: any, thenHandler: any, catchHandler: any) {
apiConnection.setHeader();
axios
.post(getResourceApiUrl() + 'Project/' + parentId, body)
.then(thenHandler)
.catch(catchHandler);
}
}
\ No newline at end of file
import apiConnection from '../api-connection';
import axios from 'axios';
function getResourceTypeApiUrl() {
return 'https://' + apiConnection.getHostName() + '/coscine/api/Coscine.Api.Project/ResourceType/';
}
export default {
getResourceTypes(thenHandler: any, catchHandler: any) {
apiConnection.setHeader();
axios
.get(getResourceTypeApiUrl())
.then(thenHandler)
.catch(catchHandler);
},
}
\ No newline at end of file
import apiConnection from '../api-connection';
import axios from 'axios';
function getRoleApiUrl() {
return 'https://' + hostName + '/coscine/api/Coscine.Api.Project/Role/';
}
export default {
getRoles(thenHandler: any, catchHandler: any) {
apiConnection.setHeader();
axios
.get(getRoleApiUrl())
.then(thenHandler)
.catch(catchHandler);
},
}
\ No newline at end of file
import apiConnection from '../api-connection';
import axios from 'axios';
function getSubProjectApiUrl() {
return 'https://' + apiConnection.getHostName() + '/coscine/api/Coscine.Api.Project/SubProject/';
}
export default {
getSubProjects(parentId: string, thenHandler: any, catchHandler: any) {
apiConnection.setHeader();
axios
.get(getSubProjectApiUrl() + parentId + '/')
.then(thenHandler)
.catch(catchHandler);
},
}
\ No newline at end of file
import apiConnection from '../api-connection';
import axios from 'axios';
function getUserApiUrl() {
return 'https://' + apiConnection.getHostName() + '/coscine/api/Coscine.Api.User/User/';
}
export default {
queryUsers(query: string, parentId: string, thenHandler: any, catchHandler: any) {
apiConnection.setHeader();
axios
.get(getUserApiUrl() + 'query/' + query + '/project/' + parentId + '/')
.then(thenHandler)
.catch(catchHandler);
},
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment