UNCLASSIFIED

Commit df1112e1 authored by hunter.congress's avatar hunter.congress
Browse files

fixed api and unit tests

parent 43c907dd
......@@ -52,16 +52,16 @@ export default {
return HTTP.put(`/courses/${courseId}`, { ...course, selectedInstructors });
},
async addStudent(courseId, student) {
return HTTP.post(`/courses/${courseId}/pending-registrations`, student);
return HTTP.post(`/courses/${courseId}/registrations`, student);
},
async addStudents(courseId, students, pmId) {
async addStudents(courseId, students) {
for (const student of students) {
await this.addStudent(courseId, { userId: student.id, pmId: pmId });
await this.addStudent(courseId, { userId: student.id });
}
},
async addStudentsToCourses(courses, students, pmId) {
for (const { id: courseId } of courses) {
await this.addStudents(courseId, students, pmId);
await this.addPendingStudents(courseId, students, pmId);
}
},
async exportCourses() {
......@@ -98,4 +98,12 @@ export default {
params
);
},
async addPendingStudent(courseId, student) {
return HTTP.post(`/courses/${courseId}/pending-registrations`, student);
},
async addPendingStudents(courseId, students, pmId) {
for (const student of students) {
await this.addPendingStudent(courseId, { userId: student.id, pmId: pmId });
}
},
};
......@@ -70,11 +70,7 @@ export default {
async addSelectedUsersToSelectedCourses() {
this.isAddingBusy = true;
try {
await CourseService.addStudents(
this.courseId,
this.courseMembers,
this.$store.state.user.user.id
);
await CourseService.addStudents(this.courseId, this.courseMembers);
this.$emit("update-students");
} catch (error) {
console.error("!add courses error!", error);
......@@ -94,7 +90,6 @@ export default {
},
cancel() {
this.$emit("close-dialog");
console.log(this.$store.state.user.user.id);
},
},
data() {
......
......@@ -114,7 +114,8 @@ export default {
try {
await CourseService.addStudentsToCourses(
[this.course],
this.selectedMembers
this.selectedMembers,
this.$store.state.user.user.id
);
this.$emit("update-students");
} catch (error) {
......
......@@ -80,6 +80,8 @@ export default {
const errorMessage = error;
this.$store.commit(SET_ERROR_MESSAGE, errorMessage);
this.$store.commit(SET_ERROR_DIALOG, true);
} finally {
this.fetchData();
}
},
},
......
......@@ -53,7 +53,7 @@
v-bind:courseId="currentCourseId"
v-bind:id="item.user.id"
v-bind:pm="item.pm.id"
v-bind:mainMessage="`Your request to add a team member into $props.trainingCourse.name - $props.trainingCourse.startDate - $props.trainingCourse.endDate has been denied due to the following reasons:`"
v-bind:mainMessage="mainMessage"
class="mx-2"
@change="fetchReload"
/>
......@@ -157,6 +157,14 @@ export default {
};
},
async mounted() {
this.mainMesseage =
"Your request to add a team member into " +
this.$props.trainingCourse.name +
" - " +
this.$props.trainingCourse.startDate +
"-" +
this.$props.trainingCourse.endDate +
" has been denied due to the following reasons:";
await this.fetchData();
},
methods: {
......@@ -186,6 +194,7 @@ export default {
}
this.loading = false;
this.fetchingData = false;
console.log(this.mainMessage);
},
async acceptPendingRegistration(userId, pmId) {
try {
......@@ -223,6 +232,17 @@ export default {
currentCourseId() {
return this.trainingCourse.id;
},
mainMessage() {
return (
"Your request to add a team member into" +
this.$props.trainingCourse.name +
" - " +
this.$props.trainingCourse.startDate +
"-" +
this.$props.trainingCourse.endDate +
"has been denied due to the following reasons:"
);
},
},
};
</script>
......
......@@ -407,6 +407,7 @@ export default {
const team = await TeamService.getMyTeam();
if (team && Object.keys(team).length !== 0) {
this.team = await TeamService.getTeam(team[0].id);
console.log(this.team);
isTeamLead = team[0].TeamMember.isTeamLead;
}
}
......
......@@ -593,8 +593,7 @@ export default {
// delay new call
this.fetchData();
this.$refs.trainingAttendance.fetchDebounced();
this.$refs.pendingRequests.fetchDebounced();
this.$refs.addStudentsToCourseDialog.fetchDebounced();
this.$refs.trainingAttendance.fetchDebounced();
},
async updateCourse() {
this.loading = true;
......
......@@ -112,6 +112,15 @@ describe("SelectAddStudentsToCourseDialog", () => {
});
it("addSelectedUsersToSelectedCourses should call addStudentsToCourses", async () => {
const wrapper = shallowMount(SelectAddStudentsToCourseDialog, {
mocks: {
$store: {
state: {
error: {},
user: { user: { id: 1 } },
},
commit: jest.fn(),
},
},
propsData: {
value: [],
selectedMembers: [],
......@@ -139,6 +148,10 @@ describe("SelectAddStudentsToCourseDialog", () => {
},
mocks: {
$store: {
state: {
error: {},
user: { user: { id: 1 } },
},
commit: jest.fn(),
},
},
......@@ -168,6 +181,10 @@ describe("SelectAddStudentsToCourseDialog", () => {
},
mocks: {
$store: {
state: {
error: {},
user: { user: { id: 1 } },
},
commit: jest.fn(),
},
},
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment