Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 51 additions & 86 deletions src/hasura/honor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ export const query_user_role = async (uuid: string) => {
}
}
`,
{ uuid: uuid }
{ uuid: uuid },
);
return query.users_by_pk?.role ?? "anonymous";
}
};

export const query_honor_application = async (id: string) => {
const query: any = await client.request(
Expand All @@ -27,122 +27,84 @@ export const query_honor_application = async (id: string) => {
attachment_url
year
status
transcript_url
}
}
`,
{ id: id }
{ id: id },
);
return query.honor_application_by_pk ?? null;
}
};

export const insert_honor_application = async (
student_uuid: string,
honor: string,
statement: string,
attachment_url: string | undefined,
year: number
transcript_url: string | undefined,
year: number,
) => {
const object: Record<string, unknown> = {
student_uuid: student_uuid,
honor: honor,
statement: statement,
year: year,
};
if (attachment_url !== undefined) {
object.attachment_url = attachment_url;
}
if (transcript_url !== undefined) {
object.transcript_url = transcript_url;
}

const query: any = await client.request(
gql`
mutation InsertHonorApplication(
$student_uuid: uuid!
$honor: String!
$statement: String!
$attachment_url: String
$year: Int!
$object: honor_application_insert_input!
) {
insert_honor_application_one(
object: {
student_uuid: $student_uuid
honor: $honor
statement: $statement
attachment_url: $attachment_url
year: $year
}
) {
insert_honor_application_one(object: $object) {
id
}
}
`,
{
student_uuid: student_uuid,
honor: honor,
statement: statement,
attachment_url: attachment_url,
year: year
}
{ object: object },
);
return query.insert_honor_application_one?.id ?? null;
}

export const update_honor_application_with_attachment = async (
id: string,
honor: string,
statement: string,
attachment_url: string,
) => {
const query: any = await client.request(
gql`
mutation UpdateMentorApplication(
$id: uuid!
$honor: String!
$statement: String!
$attachment_url: String!
) {
update_honor_application_by_pk(
pk_columns: {id: $id}
_set: {
honor: $honor
statement: $statement
attachment_url: $attachment_url
}
) {
id
}
}
`,
{
id: id,
honor: honor,
statement: statement,
attachment_url: attachment_url
}
);
return query.update_honor_application_by_pk?.id ?? null;
}

};

export const update_honor_application = async (
id: string,
honor: string,
statement: string,
attachment_url?: string,
transcript_url?: string,
) => {
const set: Record<string, unknown> = {
honor: honor,
statement: statement,
};
if (attachment_url !== undefined) {
set.attachment_url = attachment_url;
}
if (transcript_url !== undefined) {
set.transcript_url = transcript_url;
}

const query: any = await client.request(
gql`
mutation UpdateMentorApplication(
mutation UpdateHonorApplication(
$id: uuid!
$honor: String!
$statement: String!
$set: honor_application_set_input!
) {
update_honor_application_by_pk(
pk_columns: {id: $id}
_set: {
honor: $honor
statement: $statement
}
) {
update_honor_application_by_pk(pk_columns: { id: $id }, _set: $set) {
id
}
}
`,
{
id: id,
honor: honor,
statement: statement,
}
{ id: id, set: set },
);
return query.update_honor_application_by_pk?.id ?? null;
}
};

export const delete_honor_application = async (id: string) => {
const query: any = await client.request(
Expand All @@ -153,24 +115,27 @@ export const delete_honor_application = async (id: string) => {
}
}
`,
{ id: id }
{ id: id },
);
return query.delete_honor_application_by_pk?.id ?? null;
}
};

export const update_honor_application_status = async (id: string, status: string) => {
export const update_honor_application_status = async (
id: string,
status: string,
) => {
const query: any = await client.request(
gql`
mutation UpdateMentorApplicationStatus($id: uuid!, $status: String!) {
update_honor_application_by_pk(
pk_columns: {id: $id}
pk_columns: { id: $id }
_set: { status: $status }
) {
id
}
}
`,
{ id: id, status: status }
{ id: id, status: status },
);
return query.update_honor_application_by_pk?.id ?? null;
}
};
Loading
Loading