Skip to content

Commit 07da6c1

Browse files
authored
Merge pull request #353 from uwblueprint/annie/schema_refactor
Annie/schema refactor
2 parents c2cf9b0 + 551e00c commit 07da6c1

File tree

283 files changed

+45461
-19912
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

283 files changed

+45461
-19912
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@
1919
- [ ] All of my containers are healthy and not producing any error messages
2020
- [ ] The frontend and backend ports are set to 3000 & 5000, respectively
2121
- [ ] If new packages were installed, I ran yarn install, and there is no package-lock.json file present in the codebase
22+
- [ ] I took note of any changes made outside of my ticket (e.g. refactored common ui component, updated an endpoint, changed the schema, etc.)

RAILWAY_DEPLOYMENT.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,5 @@ Railway respects the ENTRYPOINT, so both environments run `prismaInitAndRun` on
150150
```
151151
4. **Monitor Railway logs** on deployment to verify seeding behavior
152152
5. **Keep system badges in sync** between `prodData.ts` and production database
153+
154+
TODO: Review & update doc

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ Backend: http://localhost:5000/graphql
3939

4040
## Database Interactions
4141
Apply / migrate changes in prisma.schema to the database:
42-
1. Change the DATABASE_URL in the backend .env file to: postgresql://postgres:postgres@**localhost**:5432/mp
43-
2. In your terminal, run `npx prisma migrate dev` in the backend folder and follow the prompts
44-
3. Don’t forget to reset DATABASE_URL back to postgresql://postgres:postgres@**mp_db**:5432/mp
42+
1. First ensure your `mp_db` container is running
43+
2. Change the DATABASE_URL in the backend .env file to: postgresql://postgres:postgres@**localhost**:5432/mp
44+
3. In your terminal, run `npx prisma migrate dev` in the backend folder and follow the prompts
45+
4. Don’t forget to reset DATABASE_URL back to postgresql://postgres:postgres@**mp_db**:5432/mp
4546

4647
Common database commands:
4748
```bash

backend/.eslintrc.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ module.exports = {
2020
"class-methods-use-this": 0,
2121
"import/prefer-default-export": "off",
2222
"no-console": "off",
23+
"import/no-cycle": "off",
24+
"@typescript-eslint/no-explicit-any": "off",
2325
},
2426
ignorePatterns: ["build/*"],
2527
};

backend/Dockerfile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,5 @@ WORKDIR /app
33
COPY . ./
44
RUN apt-get update -y && apt-get install -y openssl
55
RUN yarn install
6-
ARG NODE_ENV
7-
ENV NODE_ENV=$NODE_ENV
86
EXPOSE 5000
9-
ENTRYPOINT ["yarn", "prismaInitAndRun"]
7+
ENTRYPOINT ["yarn", "start"]

backend/constants/days.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { DayOfWeek } from "@prisma/client";
2+
3+
export const orderedDays = [
4+
DayOfWeek.SUNDAY,
5+
DayOfWeek.MONDAY,
6+
DayOfWeek.TUESDAY,
7+
DayOfWeek.WEDNESDAY,
8+
DayOfWeek.THURSDAY,
9+
DayOfWeek.FRIDAY,
10+
DayOfWeek.SATURDAY,
11+
];

backend/constants/roles.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const ADMIN = "admin";
2+
export const RELIEF = "relief";
3+
export const PARTICIPANT = "participant";

backend/constants/systemBadges.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export const LOGIN = "Log In";
2+
export const PERFECT_SCORE_REQUIRED = "Perfect Score (Required Tasks)";
3+
export const PERFECT_SCORE_OPTIONAL = "Perfect Score (Optional Tasks)";
4+
export const MONEY_EARNED = "Money Earned Milestone";
5+
export const PR_LEADER = "PR Leader";
6+
export const INDIVIDUAL_GOAL = "Individual Goals Complete";
7+
export const FIRST_GOAL = "First Goal Set";
8+
export const JACK_OF_ALL_TRADES = "Jack of All Trades";
9+
10+
export const SYSTEM_BADGES = [
11+
LOGIN,
12+
PERFECT_SCORE_REQUIRED,
13+
PERFECT_SCORE_OPTIONAL,
14+
MONEY_EARNED,
15+
PR_LEADER,
16+
INDIVIDUAL_GOAL,
17+
FIRST_GOAL,
18+
JACK_OF_ALL_TRADES,
19+
];

backend/crons/index.ts

Lines changed: 18 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,34 @@
11
import cron from "node-cron";
2-
import expireAdminNotes from "./scripts/expireAdminNotes";
3-
import expireAdminAnnouncements from "./scripts/expireAdminAnnouncements";
4-
import expireLoginStreak from "./scripts/expireLoginStreak";
5-
import createAssignedTasks from "./scripts/createAssignedTask";
6-
import {
7-
sendWeeklyReports,
8-
sendMonthlyReports,
9-
} from "./scripts/sendReportEmails";
2+
import { isLastDayOfMonth } from "date-fns";
3+
import expireNotes from "./scripts/expireNotes";
4+
import expireAnnouncements from "./scripts/expireAnnouncements";
5+
import resetLoginStreak from "./scripts/resetLoginStreak";
6+
import assignRequiredTasks from "./scripts/assignRequiredTasks";
7+
import sendMonthlyReport from "./scripts/sendMonthlyReport";
8+
import sendWeeklyReport from "./scripts/sendWeeklyReport";
109

1110
cron.schedule("0 0 * * * *", async () => {
12-
const res = await expireAdminNotes();
13-
if (res) {
14-
console.log("Deleted expired notes");
15-
} else {
16-
console.log("Could not expire admin notes");
17-
}
11+
await expireNotes();
1812
});
1913

2014
cron.schedule("0 0 0 * * *", async () => {
21-
const res = await expireAdminAnnouncements();
22-
if (res) {
23-
console.log("Expired admin announcements");
24-
} else {
25-
console.log("Could not expire admin announcements");
26-
}
15+
await expireAnnouncements();
2716
});
2817

29-
cron.schedule("0 0 0 * * *", async () => {
30-
const res = await expireLoginStreak();
31-
if (res) {
32-
console.log("Expired login streaks");
33-
} else {
34-
console.log("Could not expire login streaks");
35-
}
18+
cron.schedule("0 59 23 * * *", async () => {
19+
await resetLoginStreak();
3620
});
3721

38-
cron.schedule("0 0 * * 1", async () => {
39-
const res = await createAssignedTasks();
40-
if (res) {
41-
console.log("Created assigned tasks");
42-
} else {
43-
console.log("Could not create assigned tasks");
44-
}
22+
cron.schedule("0 0 0 * * 0", async () => {
23+
await assignRequiredTasks();
4524
});
4625

47-
// Weekly reports - every Monday at 9 AM
48-
cron.schedule("0 9 * * 1", async () => {
49-
const timestamp = new Date().toISOString();
50-
console.log(
51-
`[${timestamp}] Starting weekly report generation and emailing...`
52-
);
53-
54-
const res = await sendWeeklyReports();
55-
if (res) {
56-
console.log(`[${timestamp}] Weekly reports sent successfully`);
57-
} else {
58-
console.log(`[${timestamp}] Could not send weekly reports`);
59-
}
26+
cron.schedule("0 0 23 * * 6", async () => {
27+
await sendWeeklyReport();
6028
});
6129

62-
// Monthly reports - first day of month at 9 AM
63-
cron.schedule("0 9 1 * *", async () => {
64-
const timestamp = new Date().toISOString();
65-
console.log(
66-
`[${timestamp}] Starting monthly report generation and emailing...`
67-
);
68-
69-
const res = await sendMonthlyReports();
70-
if (res) {
71-
console.log(`[${timestamp}] Monthly reports sent successfully`);
72-
} else {
73-
console.log(`[${timestamp}] Could not send monthly reports`);
30+
cron.schedule("0 0 23 * * *", async () => {
31+
if (isLastDayOfMonth(new Date())) {
32+
await sendMonthlyReport();
7433
}
7534
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Task, TaskType } from "@prisma/client";
2+
import db from "../../prisma";
3+
import { assignTasksToAllParticipants } from "../../utils/taskUtils";
4+
5+
// assigns all required tasks to each participant for the current week
6+
async function assignRequiredTasks() {
7+
try {
8+
const requiredTasks: Task[] = await db.task.findMany({
9+
where: { type: TaskType.REQUIRED },
10+
});
11+
assignTasksToAllParticipants(requiredTasks);
12+
console.log("successfully assigned required tasks to participants");
13+
} catch (err) {
14+
console.error(err);
15+
}
16+
}
17+
18+
export default assignRequiredTasks;

0 commit comments

Comments
 (0)