Skip to content

Commit

Permalink
Merge pull request #876 from acm-ucr/shahdivyank/trigger_based_status…
Browse files Browse the repository at this point in the history
…_update

Shahdivyank/trigger based status update
  • Loading branch information
shahdivyank authored Nov 12, 2023
2 parents a1a9512 + f8cb9e2 commit 43da0fd
Show file tree
Hide file tree
Showing 23 changed files with 175 additions and 164 deletions.
17 changes: 0 additions & 17 deletions cypress/e2e/admin/admins/Actions.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,6 @@ describe("Admin Actions", () => {
);
});

it("Pending First 5 Entries", () => {
five.forEach((admin) =>
cy.get(`[data-cy="${admin.uid}"]`).find('[data-cy="checkbox"]').click()
);

cy.action({
tag: "pending",
page: "admins",
});
five.forEach((admin) =>
cy
.get(`[data-cy="${admin.uid}"]`)
.find('[data-cy="0-tag"]')
.should("exist")
);
});

it("Reject First 5 Entries", () => {
five.forEach((admin) =>
cy.get(`[data-cy="${admin.uid}"]`).find('[data-cy="checkbox"]').click()
Expand Down
20 changes: 0 additions & 20 deletions cypress/e2e/admin/committees/Actions.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,6 @@ describe("Committee Actions", () => {
);
});

it("Pending First 5 Entries", () => {
five.forEach((committee) =>
cy
.get(`[data-cy="${committee.uid}"]`)
.find('[data-cy="checkbox"]')
.click()
);

cy.action({
tag: "pending",
page: "committees",
});
five.forEach((committee) =>
cy
.get(`[data-cy="${committee.uid}"]`)
.find('[data-cy="0-tag"]')
.should("exist")
);
});

it("Reject First 5 Entries", () => {
five.forEach((committee) =>
cy
Expand Down
18 changes: 0 additions & 18 deletions cypress/e2e/admin/judges/Actions.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,6 @@ describe("Judges Actions", () => {
);
});

it("Pending First 5 Entries", () => {
five.forEach((judge) =>
cy.get(`[data-cy="${judge.uid}"]`).find('[data-cy="checkbox"]').click()
);

cy.action({
tag: "pending",
page: "judges",
});

five.forEach((judge) =>
cy
.get(`[data-cy="${judge.uid}"]`)
.find('[data-cy="0-tag"]')
.should("exist")
);
});

it("Delete First 5 Entries", () => {
five.forEach((judge) =>
cy.get(`[data-cy="${judge.uid}"]`).find('[data-cy="checkbox"]').click()
Expand Down
17 changes: 0 additions & 17 deletions cypress/e2e/admin/mentors/Actions.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,6 @@ describe("Mentors Actions", () => {
);
});

it("Pending First 5 Entries", () => {
five.forEach((mentor) =>
cy.get(`[data-cy="${mentor.uid}"]`).find('[data-cy="select"]').click()
);
cy.action({
tag: "pending",
page: "mentors",
});

five.forEach((mentor) =>
cy
.get(`[data-cy="${mentor.uid}"]`)
.find('[data-cy="0-tag"]')
.should("exist")
);
});

it("Delete First 5 Entries", () => {
five.forEach((mentor) =>
cy.get(`[data-cy="${mentor.uid}"]`).find('[data-cy="select"]').click()
Expand Down
20 changes: 0 additions & 20 deletions cypress/e2e/admin/participants/Actions.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,6 @@ describe("Participants Actions", () => {
);
});

it("Pending First 5 Entries", () => {
five.forEach((participant) =>
cy
.get(`[data-cy="${participant.uid}"]`)
.find('[data-cy="checkbox"]')
.click()
);
cy.action({
tag: "pending",
page: "participants",
});

five.forEach((participant) =>
cy
.get(`[data-cy="${participant.uid}"]`)
.find('[data-cy="0-tag"]')
.should("exist")
);
});

it("Delete First 5 Entries", () => {
five.forEach((participant) =>
cy
Expand Down
18 changes: 0 additions & 18 deletions cypress/e2e/admin/teams/Actions.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,6 @@ describe("Teams Actions", () => {
);
});

it("Pending First 5 Entries", () => {
five.forEach((team) =>
cy.get(`[data-cy="${team.uid}"]`).find('[data-cy="checkbox"]').click()
);

cy.action({
tag: "pending",
page: "teams",
});

five.forEach((team) =>
cy
.get(`[data-cy="${team.uid}"]`)
.find('[data-cy="0-tag"]')
.should("exist")
);
});

it("Delete First 5 Entries", () => {
five.forEach((team) =>
cy.get(`[data-cy="${team.uid}"]`).find('[data-cy="checkbox"]').click()
Expand Down
18 changes: 0 additions & 18 deletions cypress/e2e/admin/volunteers/Actions.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,6 @@ describe("Volunteers Actions", () => {
);
});

it("Pending First 5 Entries", () => {
five.forEach((volunteer) =>
cy.get(`[data-cy="${volunteer.uid}"]`).find('[data-cy="select"]').click()
);

cy.action({
tag: "pending",
page: "volunteers",
});

five.forEach((volunteer) =>
cy
.get(`[data-cy="${volunteer.uid}"]`)
.find('[data-cy="0-tag"]')
.should("exist")
);
});

it("Delete First 5 Entries", () => {
five.forEach((volunteer) =>
cy.get(`[data-cy="${volunteer.uid}"]`).find('[data-cy="select"]').click()
Expand Down
23 changes: 23 additions & 0 deletions src/app/api/admins/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from "firebase/firestore";
import { authenticate } from "@/utils/auth";
import { AUTH } from "@/data/dynamic/admin/Admins";
import SG from "@/utils/sendgrid";

export async function POST(req) {
const res = NextResponse;
Expand All @@ -33,6 +34,16 @@ export async function POST(req) {
timestamp: Timestamp.now(),
"roles.admins": 0,
});

SG.send({
to: user.email,
template_id: process.env.SENDGRID_CONFIRMATION_TEMPLATE,
dynamic_template_data: {
name: user.name,
position: "ADMIN",
},
});

return res.json({ message: "OK" }, { status: 200 });
} catch (err) {
return res.json(
Expand Down Expand Up @@ -111,6 +122,18 @@ export async function PUT(req) {
await updateDoc(doc(db, "users", object.uid), {
"roles.admins": status,
});

SG.send({
to: object.email,
template_id:
status === 1
? process.env.SENDGRID_ACCEPTANCE_TEMPLATE
: process.env.SENDGRID_REJECTION_TEMPLATE,
dynamic_template_data: {
name: object.name,
position: "ADMIN",
},
});
}
});

Expand Down
23 changes: 23 additions & 0 deletions src/app/api/committees/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from "firebase/firestore";
import { authenticate } from "@/utils/auth";
import { AUTH } from "@/data/dynamic/admin/Committees";
import SG from "@/utils/sendgrid";

export async function POST(req) {
const res = NextResponse;
Expand All @@ -34,8 +35,18 @@ export async function POST(req) {
"roles.committees": 0,
});

SG.send({
to: user.email,
template_id: process.env.SENDGRID_CONFIRMATION_TEMPLATE,
dynamic_template_data: {
name: user.name,
position: "COMMITTEE",
},
});

return res.json({ message: "OK" }, { status: 200 });
} catch (err) {
console.log(err.response.body.errors);
return res.json(
{ message: `Internal Server Error: ${err}` },
{ status: 500 }
Expand Down Expand Up @@ -114,6 +125,18 @@ export async function PUT(req) {
await updateDoc(doc(db, "users", object.uid), {
"roles.committees": status,
});

SG.send({
to: object.email,
template_id:
status === 1
? process.env.SENDGRID_ACCEPTANCE_TEMPLATE
: process.env.SENDGRID_REJECTION_TEMPLATE,
dynamic_template_data: {
name: object.name,
position: "COMMITTEE",
},
});
}
});

Expand Down
23 changes: 23 additions & 0 deletions src/app/api/judges/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from "firebase/firestore";
import { authenticate } from "@/utils/auth";
import { AUTH } from "@/data/dynamic/admin/Judges";
import SG from "@/utils/sendgrid";

export async function POST(req) {
const res = NextResponse;
Expand All @@ -37,6 +38,16 @@ export async function POST(req) {
timestamp: Timestamp.now(),
"roles.judges": 0,
});

SG.send({
to: user.email,
template_id: process.env.SENDGRID_CONFIRMATION_TEMPLATE,
dynamic_template_data: {
name: user.name,
position: "JUDGE",
},
});

return res.json({ message: "OK" }, { status: 200 });
} catch (err) {
return res.json(
Expand Down Expand Up @@ -114,6 +125,18 @@ export async function PUT(req) {
await updateDoc(doc(db, "users", object.uid), {
"roles.judges": status,
});

SG.send({
to: object.email,
template_id:
status === 1
? process.env.SENDGRID_ACCEPTANCE_TEMPLATE
: process.env.SENDGRID_REJECTION_TEMPLATE,
dynamic_template_data: {
name: object.name,
position: "JUDGE",
},
});
}
});

Expand Down
22 changes: 22 additions & 0 deletions src/app/api/mentors/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ export async function POST(req) {
"roles.mentors": 0,
availability: availability,
});

SG.send({
to: user.email,
template_id: process.env.SENDGRID_CONFIRMATION_TEMPLATE,
dynamic_template_data: {
name: user.name,
position: "MENTOR",
},
});

return res.json({ message: "OK" }, { status: 200 });
} catch (err) {
return res.json(
Expand Down Expand Up @@ -125,6 +135,18 @@ export async function PUT(req) {
await updateDoc(doc(db, "users", object.uid), {
"roles.mentors": status,
});

SG.send({
to: object.email,
template_id:
status === 1
? process.env.SENDGRID_ACCEPTANCE_TEMPLATE
: process.env.SENDGRID_REJECTION_TEMPLATE,
dynamic_template_data: {
name: object.name,
position: "MENTOR",
},
});
}
});

Expand Down
23 changes: 23 additions & 0 deletions src/app/api/participants/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from "firebase/firestore";
import { authenticate } from "@/utils/auth";
import { AUTH } from "@/data/dynamic/admin/Participants";
import SG from "@/utils/sendgrid";

export async function POST(req) {
const res = NextResponse;
Expand Down Expand Up @@ -41,6 +42,16 @@ export async function POST(req) {
diet: diet,
resume: resume,
});

SG.send({
to: user.email,
template_id: process.env.SENDGRID_CONFIRMATION_TEMPLATE,
dynamic_template_data: {
name: user.name,
position: "PARTICIPANT",
},
});

return res.json({ message: "OK" }, { status: 200 });
} catch (err) {
return res.json(
Expand Down Expand Up @@ -144,6 +155,18 @@ export async function PUT(req) {
await updateDoc(doc(db, "users", object.uid), {
"roles.participants": status,
});

SG.send({
to: object.email,
template_id:
status === 1
? process.env.SENDGRID_ACCEPTANCE_TEMPLATE
: process.env.SENDGRID_REJECTION_TEMPLATE,
dynamic_template_data: {
name: object.name,
position: "PARTICIPANT",
},
});
}
});

Expand Down
Loading

0 comments on commit 43da0fd

Please sign in to comment.