fixed moodle logic
This commit is contained in:
@@ -1,37 +1,44 @@
|
||||
import axios from "axios";
|
||||
|
||||
export const enrollUserInCourse = async (
|
||||
courseid: number | string,
|
||||
userid: number | string,
|
||||
) => {
|
||||
const { data: enrollmentResponse } = await axios.get(
|
||||
`${process.env.NEXT_PUBLIC_MOODLE_URL}/webservice/rest/server.php`,
|
||||
{
|
||||
params: {
|
||||
wstoken: process.env.MOODLE_TOKEN,
|
||||
wsfunction: "enrol_manual_enrol_users",
|
||||
moodlewsrestformat: "json",
|
||||
enrolments: [
|
||||
{
|
||||
roleid: 5,
|
||||
userid: typeof userid === "string" ? parseInt(userid) : userid,
|
||||
courseid:
|
||||
typeof courseid === "string" ? parseInt(courseid) : courseid,
|
||||
},
|
||||
],
|
||||
export const enrollUserInCourse = async (courseid: number | string, userid: number | string) => {
|
||||
try {
|
||||
const { data: enrollmentResponse } = await axios.get(
|
||||
`${process.env.NEXT_PUBLIC_MOODLE_URL}/webservice/rest/server.php`,
|
||||
{
|
||||
auth: {
|
||||
username: "moodleuser",
|
||||
password: "Xo1SXaLYBa7Yb6WW",
|
||||
},
|
||||
params: {
|
||||
wstoken: process.env.MOODLE_API_TOKEN,
|
||||
wsfunction: "enrol_manual_enrol_users",
|
||||
moodlewsrestformat: "json",
|
||||
enrolments: [
|
||||
{
|
||||
roleid: 5,
|
||||
userid: typeof userid === "string" ? parseInt(userid) : userid,
|
||||
courseid: typeof courseid === "string" ? parseInt(courseid) : courseid,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
);
|
||||
if (enrollmentResponse !== null) console.error(enrollmentResponse);
|
||||
return enrollmentResponse;
|
||||
);
|
||||
return enrollmentResponse;
|
||||
} catch (error) {
|
||||
return new Error("Failed to enroll user in course");
|
||||
}
|
||||
};
|
||||
|
||||
export const getMoodleUserById = async (id: string) => {
|
||||
const { data: user } = await axios.get(
|
||||
`${process.env.NEXT_PUBLIC_MOODLE_URL}/webservice/rest/server.php`,
|
||||
{
|
||||
auth: {
|
||||
username: "moodleuser",
|
||||
password: "Xo1SXaLYBa7Yb6WW",
|
||||
},
|
||||
params: {
|
||||
wstoken: process.env.MOODLE_TOKEN,
|
||||
wstoken: process.env.MOODLE_API_TOKEN,
|
||||
wsfunction: "core_user_get_users_by_field",
|
||||
moodlewsrestformat: "json",
|
||||
field: "idnumber",
|
||||
@@ -42,6 +49,7 @@ export const getMoodleUserById = async (id: string) => {
|
||||
},
|
||||
},
|
||||
);
|
||||
console.log("Moodle User", user);
|
||||
const u = user[0];
|
||||
return (
|
||||
(u as {
|
||||
|
||||
Reference in New Issue
Block a user