Skip to content

Commit

Permalink
removed comments and modified null check
Browse files Browse the repository at this point in the history
  • Loading branch information
konpoku committed Oct 27, 2024
1 parent fd9c482 commit 6adf96e
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 158 deletions.
80 changes: 0 additions & 80 deletions src/hasura/mentor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down
75 changes: 0 additions & 75 deletions src/hasura/notice.ts
Original file line number Diff line number Diff line change
@@ -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 = {};
Expand Down
4 changes: 2 additions & 2 deletions src/routes/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
2 changes: 1 addition & 1 deletion src/routes/mentor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 6adf96e

Please sign in to comment.