-
Notifications
You must be signed in to change notification settings - Fork 0
/
internships.service.ts
111 lines (96 loc) 路 3.46 KB
/
internships.service.ts
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import { BaseService } from "./base.service";
import { injectable } from "inversify";
import { User, ApiResponseDto, Internship, InternshipStatusType, Defaults } from "thesis-dais-internship-manager-core";
/**
* The internships service
*
* @extends {BaseService}
*/
@injectable()
export class InternshipsService extends BaseService {
/**
* Get all internships
*/
getAll(): Promise<ApiResponseDto<Array<Internship>>> {
return this.getVerb(Defaults.collectionsName.internships);
}
/**
* Create a new internship
*
* @param {Internship} internship The new internship
*/
create(internship: Internship): Promise<ApiResponseDto<Internship>> {
return this.postVerb(Defaults.collectionsName.internships, internship);
}
/**
* Update an existing internship
*
* @param {Internship} internship The internship to update
*/
update(internship: Internship): Promise<ApiResponseDto<Internship>> {
return this.putVerb(Defaults.collectionsName.internships, internship);
}
/**
* Return an internship by its identifier
*
* @param {string} id The internship identifier
*/
getById(id: string): Promise<ApiResponseDto<Internship>> {
return this.getVerb(`${Defaults.collectionsName.internships}/${id}`);
}
/**
* Return all the internships created by the given company id
*
* @param {string} id The company id
*/
getByCompanyOwnerId(id: string): Promise<ApiResponseDto<Array<Internship>>> {
return this.getVerb(`${Defaults.collectionsName.internships}/getByCompanyOwnerId/${id}`);
}
/**
* Return the list of all approved internships
*/
getApproved(): Promise<ApiResponseDto<Array<Internship>>> {
return this.getVerb(`${Defaults.collectionsName.internships}/getApproved`);
}
/**
* Return the list of all not approved internships
*/
getNotApproved(): Promise<ApiResponseDto<Array<Internship>>> {
return this.getVerb(`${Defaults.collectionsName.internships}/getNotApproved`);
}
/**
* Delete an internship by its identifier
*
* @param {string} id The internship identifier
*/
delete(id: string): Promise<ApiResponseDto<boolean>> {
return this.deleteVerb(`${Defaults.collectionsName.internships}/${id}`);
}
/**
* Get all the available state based on the current token role
* @param {InternshipStatusType} newState The current state
*/
async getAvailableStates(newState: InternshipStatusType): Promise<Array<{ text: string, value: InternshipStatusType }>> {
const result = await this.getVerb(`${Defaults.collectionsName.internships}/status/${newState}`);
if (result && result.isOk)
return result.data;
return [];
}
/**
* Update the status af an internship following the state machine transition function
*
* @param {string} internshipId The internship identifier
* @param {InternshipStatusType} newState The new state
* @param {string} [rejectReason] The reject reason (if the new state is Rejected)
*/
async updateStatus(
internshipId: string,
newState: InternshipStatusType,
rejectReason?: string): Promise<ApiResponseDto<Internship>> {
return this.putVerb(`${Defaults.collectionsName.internships}/status`, {
id: internshipId,
status: newState,
rejectReason: rejectReason
});
}
}