forked from bcgov/sbc-auth
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask.services.ts
More file actions
78 lines (69 loc) · 2.81 KB
/
task.services.ts
File metadata and controls
78 lines (69 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import { Task, TaskFilterParams, TaskList } from '@/models/Task'
import { TaskRelationshipStatus, TaskType } from '@/util/constants'
import { AxiosResponse } from 'axios'
import ConfigHelper from '@/util/config-helper'
import { axios } from '@/util/http-util'
export default class TaskService {
public static async getTaskById (taskId: number | string): Promise<AxiosResponse<Task>> {
return axios.get(`${ConfigHelper.getAuthAPIUrl()}/tasks/${taskId}`)
}
public static async fetchTasks (taskFilter?: TaskFilterParams): Promise<AxiosResponse<TaskList>> {
const params = new URLSearchParams()
if (taskFilter.relationshipStatus) {
params.append('relationshipStatus', taskFilter.relationshipStatus)
}
if (taskFilter.statuses) {
taskFilter.statuses.forEach(status =>
params.append('status', status))
}
if (taskFilter.type) {
params.append('type', taskFilter.type)
}
if (taskFilter.pageNumber) {
params.append('page', taskFilter.pageNumber.toString())
}
if (taskFilter.pageLimit) {
params.append('limit', taskFilter.pageLimit.toString())
}
if (taskFilter.name) {
params.append('name', taskFilter.name)
}
if (taskFilter.startDate) {
params.append('startDate', taskFilter.startDate)
}
if (taskFilter.endDate) {
params.append('endDate', taskFilter.endDate)
}
if (taskFilter.modifiedBy) {
params.append('modifiedBy', taskFilter.modifiedBy)
}
if (taskFilter.action) {
params.append('action', taskFilter.action)
}
return axios.get(`${ConfigHelper.getAuthAPIUrl()}/tasks`, { params })
}
static async approvePendingTask (task:any): Promise<AxiosResponse> {
const taskId = task.id
return axios.put(`${ConfigHelper.getAuthAPIUrl()}/tasks/${taskId}`,
{ relationshipStatus: TaskRelationshipStatus.ACTIVE })
}
static async rejectPendingTask (taskId:any, remarks:string[] = []): Promise<AxiosResponse> {
return axios.put(`${ConfigHelper.getAuthAPIUrl()}/tasks/${taskId}`,
{ remarks, relationshipStatus: TaskRelationshipStatus.REJECTED })
}
static async onHoldPendingTask (taskId, remarks:string[]): Promise<AxiosResponse> {
return axios.put(`${ConfigHelper.getAuthAPIUrl()}/tasks/${taskId}`,
{ status: TaskRelationshipStatus.HOLD, remarks, relationshipStatus: TaskRelationshipStatus.PENDING_STAFF_REVIEW })
}
public static async getQsApplicantForTaskReview (accountId: number | string, type: TaskType): Promise<AxiosResponse> {
const apiKey = ConfigHelper.getMhrAPIKey()
const headers = {
'x-apikey': apiKey,
'Account-Id': accountId
}
const url = type === TaskType.MHR_MANUFACTURERS
? `${ConfigHelper.getMhrAPIUrl()}/manufacturers`
: `${ConfigHelper.getMhrAPIUrl()}/qualified-suppliers`
return axios.get(url, { headers })
}
}