Skip to content

db_query.mjs

up2108272 edited this page May 9, 2024 · 4 revisions

db_query.mjs

Basic information

  • requests and sends information to database

export function submitUser(id, fname, mname, lname, email, role)

export function submitUser(id, fname, mname, lname, email, role) {
    let payload = [id, fname, mname, lname, email, role];
    fetch('/new-user', {
        method: 'POST',
        headers: {
        'Content-Type': 'application/json',
        },
        body: JSON.stringify(payload),
    });

    console.log("SENDING " + JSON.stringify(payload));
}
  • Requests to create user in database

getProfileData(uidInput, callback)

export function getProfileData(uidInput, callback) {
    let payload = [uidInput];
    fetch('/get-profile', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json'
        },
        body: JSON.stringify(payload)
    })
    .then(res => res.json())
    .then(res => {
        callback(res);
    })
}
  • Requests user data from server
  • Returns via callback

export function updateUserProfile(uid, column, newValue)

export function updateUserProfile(uid, column, newValue) {
    let payload = [uid, column, newValue];
    fetch('/update-user', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json'
        },
        body: JSON.stringify(payload)
    });
}
  • Requests server to update a value of a users profile

export function uploadQuiz(uid, quizTitle, quizData)

export function uploadQuiz(uid, quizTitle, quizData) {
    let payload = [uid, quizTitle, quizData];
    console.log(payload);
    fetch('/upload-quiz', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json'
        },
        body: JSON.stringify(payload)
    })
}
  • Requests server to create a quiz in the database

export function createClass(lecturer_id, className, joinCode)

export function createClass(lecturer_id, className, joinCode) {
    let payload = [lecturer_id, className, joinCode];
    fetch('/create-class', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json'
        },
        body: JSON.stringify(payload)
    })
}
  • Requests to server to create a class in database

export function getClass(lecturer_id, callback)

export function getClass(lecturer_id, callback) {
    let payload = [lecturer_id];
    fetch("/get-classes-lecturer", {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json'
        },
        body: JSON.stringify(payload)
    })
    .then((res) => res.json())
    .then((resData) =>{
        callback(resData);
    })
}
  • Requests server to retrieve all classes created by a lecturer
  • Returned via callback

export function getQuizzes(lecturerId, callback)

export function getQuizzes(lecturerId, callback) {
    let payload = [lecturerId];
    fetch("/get-quizzes-from-lecturer", {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json'
        },
        body: JSON.stringify(payload)
    })
    .then((res) => res.json())
    .then((resData) =>{
        callback(resData);
    })
}
  • Requests server to retrieve all quizzes created by a lecturer
  • Returned via callback

export function joinClass(studentId, joinCode)

export function joinClass(studentId, joinCode) {
    let payload = [studentId, joinCode];
    console.log(payload);
    fetch("/join-class", {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json'
        },
        body: JSON.stringify(payload)
    })
    .then((res) => res.json())
    .then((resData) =>{
        console.log(resData);
    })
}
  • Requests to server to add a student to a class via join code

Clone this wiki locally