diff --git a/src/hasura/mentor.ts b/src/hasura/mentor.ts index 26bac780..24779f2c 100644 --- a/src/hasura/mentor.ts +++ b/src/hasura/mentor.ts @@ -163,86 +163,6 @@ export const update_mentor_info_available = async (uuid: string, available: bool return query.update_mentor_info_by_pk?.available ?? null; } -//export const update_mentor_info_description = async (mentor_uuid: string, achievement: string, background: string, field: string, intro: string) => { -// const query: any = await client.request( -// gql` -// mutation UpdateMentorInfoDescription( -// $mentor_uuid: uuid! -// $achievement: String = "" -// $background: String = "" -// $field: String = "" -// $intro: String = "" -// ) { -// update_mentor_info_by_pk( -// pk_columns: { mentor_uuid: $mentor_uuid } -// _set: { -// achievement: $achievement -// background: $background -// field: $field -// intro: $intro -// } -// ) { -// mentor_uuid -// } -// } -// `, -// { -// mentor_uuid: mentor_uuid, -// achievement: achievement, -// background: background, -// field: field, -// intro: intro, -// } -// ); -// return query.update_mentor_info_by_pk?.mentor_uuid ?? null; -//} - -//export const update_contest_notice: any = async (id: string, updateFields: Partial<{ title: string; content: string; files: string }>) => { -// const setFields: any = {}; -// if (updateFields.title) setFields.title = updateFields.title; -// if (updateFields.content) setFields.content = updateFields.content; -// if (updateFields.files) setFields.files = updateFields.files; -// -// if (Object.keys(setFields).length === 0) { -// console.error("At least update one feature"); -// return undefined; -// } -// -// const variableString = Object.keys(setFields) -// .map(key=>`$${key}`) -// .join(', '); -// -// const setString = Object.keys(setFields) -// .map(key => `${key}: $${key}`) -// .join(', '); -// -// const mutation = gql` -// mutation UpdateContestNotice($id: uuid!, ${variableString}) { -// update_contest_notice_by_pk(pk_columns: { id: $id }, _set: { ${setString} }) { -// id -// title -// content -// files -// } -// } -// `; -// -// const variables:{[key:string]:any} = { -// id:id -// } -// if(setFields.title) variables.title = setFields.title; -// if(setFields.content) variables.content = setFields.content; -// if(setFields.files) variables.files = setFields.files; -// -// -// try { -// const response: any = await client.request(mutation, variables); -// return response.update_contest_notice_by_pk?.id ?? undefined; -// } catch (error) { -// console.error('Error updating contest notice', error); -// throw error; -// } -//}; export const update_mentor_info_description = async (mentor_uuid: string,updateFields: Partial<{achievement: string, background: string, field: string, intro: string}>) => { if(Object.keys(updateFields).length === 0) return null; const setFields: any = {}; diff --git a/src/hasura/notice.ts b/src/hasura/notice.ts index afe7d28e..0e0e9f86 100644 --- a/src/hasura/notice.ts +++ b/src/hasura/notice.ts @@ -1,80 +1,5 @@ import { gql } from "graphql-request"; import { client } from ".."; -// These graphql statements do not actually return id, instead they return nothing. -//export const update_notice = async (id: string, title: string, content: string, files: string, notice_type: string) => { -// const query: any = await client.request( -// gql` -// mutation UpdateNotice( -// $id: uuid! -// $title: String! -// $content: String! -// $files: String! -// $notice_type: String! -// ) { -// update_info_notice( -// where: { id: { _eq: $id } } -// _set: { -// title: $title -// content: $content -// files: $files -// notice_type: $notice_type -// } -// ) { -// returning { -// id -// } -// } -// } -// `, -// { -// id: id, -// title: title, -// content: content, -// files: files, -// notice_type: notice_type -// } -// ); -// return query.update_info_notice?.id ?? null; -//} -//export const update_mentor_info_description = async (mentor_uuid: string,updateFields: Partial<{achievement: string, background: string, field: string, intro: string}>) => { -// if(Object.keys(updateFields).length === 0) return null; -// const setFields: any = {}; -// if(updateFields.achievement) setFields.achievement = updateFields.achievement; -// if(updateFields.background) setFields.background = updateFields.background; -// if(updateFields.field) setFields.field = updateFields.field; -// if(updateFields.intro) setFields.intro = updateFields.intro; -// const variablesString = Object.keys(setFields) -// .map(key => `$${key} : String`) -// .join('\n'); -// const setString = Object.keys(setFields) -// .map(key => `${key}: $${key}`) -// .join('\n'); -// const mutation = gql` -// mutation UpdateMentorInfoDescription($mentor_uuid: uuid! -// ${variablesString}) { -// update_mentor_info_by_pk(pk_columns: {mentor_uuid: $mentor_uuid } -// _set: { ${setString} } -// ) { -// mentor_uuid -// } -// } -// `; -// console.log(mutation); -// const variables: {[key: string]: any} = { -// mentor_uuid: mentor_uuid, -// achievement: updateFields.achievement, -// background: updateFields.background, -// field: updateFields.field, -// intro: updateFields.intro -// }; -// try { -// const response: any = await client.request(mutation, variables); -// return response.update_mentor_info_by_pk?.mentor_uuid ?? null; -// } catch (error) { -// console.error('Error updating mentor info', error); -// throw error; -// } -//} export const update_notice = async (id: string, updateFields: Partial<{title: string, content: string, files: string, notice_type: string}>) => { if(Object.keys(updateFields).length === 0) return null; const setFields: any = {}; diff --git a/src/routes/application.ts b/src/routes/application.ts index 3b67290d..5ae2e499 100644 --- a/src/routes/application.ts +++ b/src/routes/application.ts @@ -321,11 +321,11 @@ router.post("/chat/update/status",authenticate(["counselor","teacher"]), async ( try { const id : string = req.body.applyid; const status : boolean = req.body.chat_status; - if(!id || status === undefined){ + if(!id || status === undefined || status === null){ return res.status(456).send("Error: Invalid parameters provided"); } const chat_status = await MentHasFunc.update_mentor_application_chat_status(id, status); - if(chat_status === null){ + if(chat_status === null || chat_status === undefined){ return res.status(455).send("Error: Application does not exist"); } if(chat_status === true){ diff --git a/src/routes/mentor.ts b/src/routes/mentor.ts index a6695c04..b0332586 100644 --- a/src/routes/mentor.ts +++ b/src/routes/mentor.ts @@ -21,7 +21,7 @@ router.post("/update/available", authenticate(["counselor", "teacher"]), async ( try { const uuid: string = req.body.uuid; const available: boolean = req.body.available; - if (!uuid || available === undefined) { + if (!uuid || available === undefined || available === null) { return res.status(422).send("422 Unprocessable Entity: Missing credentials"); } const mentor_available = await MentHasFunc.update_mentor_info_available(uuid, available);