234 lines
6.0 KiB
JavaScript
234 lines
6.0 KiB
JavaScript
import HttpClient from '../api/HttpClient'
|
|
import router from '../router'
|
|
import store from '../store/index'
|
|
|
|
//Request in order to retrieve all contracts and print in table
|
|
//Backend: extra roles check. Allow admin, verwaltung, employee.
|
|
//REST: GET /contracts
|
|
//Auth: provide auth token in request
|
|
//OnError: redirect to page /error?message=somemessage&code=404
|
|
export async function getContracts(authToken) {
|
|
return HttpClient.get('contracts', {
|
|
headers: {
|
|
Authorization: 'Bearer ' + store.state.keycloak.keycloak.token
|
|
}
|
|
}) //TODO: provide here auth header
|
|
.then(resp => {
|
|
return resp.data
|
|
})
|
|
.catch(error => {
|
|
router.push('/error?message=' + error.message + '&code=' + error.code)
|
|
})
|
|
}
|
|
|
|
//REST: GET /contracts
|
|
//Auth: provide auth token in request
|
|
//OnError: redirect to page /error?message=somemessage&code=404
|
|
export async function getOpenContracts() {
|
|
return HttpClient.get('contracts/open', {
|
|
headers: {
|
|
Authorization: 'Bearer ' + store.state.keycloak.keycloak.token
|
|
}
|
|
}) //TODO: provide here auth header
|
|
.then(resp => {
|
|
return resp.data
|
|
})
|
|
.catch(error => {
|
|
router.push('/error?message=' + error.message + '&code=' + error.code)
|
|
})
|
|
}
|
|
|
|
//Request in order to retrieve specific contract using ID
|
|
//Backend: extra roles check. Allow admin, verwaltung, employee.
|
|
//REST: GET /contract?id=someId
|
|
//Auth: provide auth token in request
|
|
//OnError: redirect to page /error?message=somemessage&code=404
|
|
export async function getContractById(identifier, authToken) {
|
|
return HttpClient.get('/contract', {
|
|
params: { id: identifier },
|
|
headers: {
|
|
Authorization: 'Bearer ' + store.state.keycloak.keycloak.token
|
|
}
|
|
})
|
|
.then(resp => {
|
|
//TODO: send also auth token with request
|
|
return resp.data
|
|
})
|
|
.catch(error => {
|
|
console.error(error)
|
|
router.push('/error?message=' + error.message + '&code=' + error.code)
|
|
})
|
|
}
|
|
|
|
export async function applyContract(contractID, prefRole, userName, userPhone, userEmail) {
|
|
return HttpClient.post(
|
|
'/contract/apply',
|
|
{
|
|
id: contractID,
|
|
role: prefRole,
|
|
name: userName,
|
|
phone: userPhone,
|
|
email: userEmail
|
|
},
|
|
{
|
|
headers: {
|
|
Authorization: 'Bearer ' + store.state.keycloak.keycloak.token
|
|
}
|
|
}
|
|
)
|
|
.then(resp => {
|
|
//TODO: send also auth token with request
|
|
return resp.data
|
|
})
|
|
.catch(error => {
|
|
console.error(error)
|
|
router.push('/error?message=' + error.message + '&code=' + error.code)
|
|
})
|
|
}
|
|
|
|
export async function misapply(contractID) {
|
|
return HttpClient.post(
|
|
'/contract/' + contractID + '/misapply',
|
|
{
|
|
id: contractID,
|
|
email: store.state.keycloak.keycloak.tokenParsed.email
|
|
},
|
|
{
|
|
headers: {
|
|
Authorization: 'Bearer ' + store.state.keycloak.keycloak.token
|
|
}
|
|
}
|
|
)
|
|
.then(resp => {
|
|
//TODO: send also auth token with request
|
|
return resp.data
|
|
})
|
|
.catch(error => {
|
|
console.error(error)
|
|
router.push('/error?message=' + error.message + '&code=' + error.code)
|
|
})
|
|
}
|
|
|
|
export async function createContract(contractId, contractName, contractClient, contractPassword) {
|
|
return HttpClient.post(
|
|
'/contract/create',
|
|
{
|
|
id: contractId,
|
|
name: contractName,
|
|
client: contractClient,
|
|
password: contractPassword
|
|
},
|
|
{
|
|
headers: {
|
|
Authorization: 'Bearer ' + store.state.keycloak.keycloak.token
|
|
}
|
|
}
|
|
)
|
|
}
|
|
|
|
export async function deleteContract(contractId) {
|
|
return HttpClient.delete('/contract/delete?id=' + contractId, {
|
|
headers: {
|
|
Authorization: 'Bearer ' + store.state.keycloak.keycloak.token
|
|
}
|
|
})
|
|
.then(resp => {
|
|
//TODO: send also auth token with request
|
|
return resp.data
|
|
})
|
|
.catch(error => {
|
|
console.error(error)
|
|
router.push('/error?message=' + error.message + '&code=' + error.code)
|
|
})
|
|
}
|
|
|
|
export async function saveComment(comment, contractId) {
|
|
return HttpClient.post('/contract/' + contractId + '/comments', comment, {
|
|
headers: {
|
|
Authorization: 'Bearer ' + store.state.keycloak.keycloak.token
|
|
}
|
|
})
|
|
}
|
|
|
|
export async function moveToNextStep(contractId) {
|
|
return HttpClient.post(
|
|
'/contract/nextstep?id=' + contractId,
|
|
{},
|
|
{
|
|
headers: {
|
|
Authorization: 'Bearer ' + store.state.keycloak.keycloak.token
|
|
}
|
|
}
|
|
)
|
|
}
|
|
|
|
export async function getStatuses(contractId) {
|
|
return HttpClient.get('/statuses', {
|
|
headers: {
|
|
Authorization: 'Bearer ' + store.state.keycloak.keycloak.token
|
|
}
|
|
})
|
|
.then(resp => {
|
|
//TODO: send also auth token with request
|
|
return resp.data
|
|
})
|
|
.catch(error => {
|
|
console.error(error)
|
|
router.push('/error?message=' + error.message + '&code=' + error.code)
|
|
})
|
|
}
|
|
|
|
export async function postChangeStatus(contractId, newStatus) {
|
|
//TODO: send also auth token with request
|
|
return HttpClient.post(
|
|
'/contract/status',
|
|
{
|
|
id: contractId,
|
|
status: newStatus
|
|
},
|
|
{
|
|
headers: {
|
|
Authorization: 'Bearer ' + store.state.keycloak.keycloak.token
|
|
}
|
|
}
|
|
)
|
|
}
|
|
|
|
export async function getAmountOfStatuses(token) {
|
|
return HttpClient.get('/statuses/amount', {
|
|
headers: {
|
|
Authorization: 'Bearer ' + store.state.keycloak.keycloak.token
|
|
}
|
|
})
|
|
.then(resp => {
|
|
//TODO: send also auth token with request
|
|
return resp.data
|
|
})
|
|
.catch(error => {
|
|
console.error(error)
|
|
router.push('/error?message=' + error.message + '&code=' + error.code)
|
|
})
|
|
}
|
|
|
|
export async function setupContract(conractId, data) {
|
|
return HttpClient.put(
|
|
'/contract/' + conractId + '/setup',
|
|
{
|
|
data
|
|
},
|
|
{
|
|
headers: {
|
|
Authorization: 'Bearer ' + store.state.keycloak.keycloak.token
|
|
}
|
|
}
|
|
)
|
|
.then(resp => {
|
|
//TODO: send also auth token with request
|
|
return resp.data
|
|
})
|
|
.catch(error => {
|
|
console.error(error)
|
|
router.push('/error?message=' + error.message + '&code=' + error.code)
|
|
})
|
|
}
|