Skip to content

Commit 02de70a

Browse files
Merge branch 'main' into david/fix-file-upload-for-events
2 parents cad8362 + b26d9c9 commit 02de70a

Some content is hidden

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

55 files changed

+1470
-359
lines changed

.env.sample

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ POSTGRES_DATABASE=
1313
POSTGRES_PASSWORD=
1414
POSTGRES_USER=
1515
SISTEMA_PASSWORD=
16-
SISTEMA_EMAIL_DOMAIN=
16+
SISTEMA_EMAIL_DOMAIN=
17+
CRON_SECRET=

.github/workflows/cron-job.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@ name: Send Email Reminders for Missing Lessons
22

33
on:
44
schedule:
5-
- cron: '0 0 * * *' # Runs every day at 00:00 UTC
5+
- cron: '0 0 * * *'
66
workflow_dispatch:
77

88
jobs:
99
call-api:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- name: Log current time
13-
run: date -u # Logs the current UTC time
13+
run: date -u
1414

1515
- name: Call reminders API
16-
run: curl -X GET "${{ secrets.NEXT_PUBLIC_PROD_URL }}/api/reminders"
16+
run: |
17+
curl -X GET "${{ secrets.NEXT_PUBLIC_PROD_URL }}/api/reminders" \
18+
-H "Authorization: Bearer ${{ secrets.CRON_SECRET }}"

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# Sistema Tacet
2+
23
## Absence Calendar
4+
35
<img width="1728" alt="image" src="https://github.com/user-attachments/assets/7b6022b8-48a7-4192-9916-b1c3ef912780" />
46

57
## Admin Dashboard
8+
69
<img width="1728" alt="image" src="https://github.com/user-attachments/assets/642d3ff0-dbc0-44f0-80e0-f2fbbecaa916" />
710

811
## Setup

app/api/declareAbsence/route.ts

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
1-
import { NextResponse } from 'next/server';
21
import { prisma } from '@utils/prisma';
2+
import { NextResponse } from 'next/server';
33

44
export async function POST(req: Request) {
55
try {
66
const body = await req.json();
7-
console.log(body);
7+
8+
const {
9+
lessonDate,
10+
reasonOfAbsence,
11+
notes,
12+
absentTeacherId,
13+
substituteTeacherId,
14+
locationId,
15+
subjectId,
16+
roomNumber,
17+
lessonPlanFile,
18+
} = body;
819

920
if (
10-
!body.lessonDate ||
11-
!body.reasonOfAbsence ||
12-
!body.absentTeacherId ||
13-
!body.locationId ||
14-
!body.subjectId
21+
!lessonDate ||
22+
!reasonOfAbsence ||
23+
!absentTeacherId ||
24+
!locationId ||
25+
!subjectId
1526
) {
1627
console.log('Missing required fields');
1728
return NextResponse.json(
@@ -23,28 +34,28 @@ export async function POST(req: Request) {
2334
const newAbsence = await prisma.$transaction(async (prisma) => {
2435
let lessonPlanId: number | null = null;
2536

26-
if (body.lessonPlanFile) {
37+
if (lessonPlanFile) {
2738
const lessonPlan = await prisma.lessonPlanFile.create({
2839
data: {
29-
name: body.lessonPlanFile.name,
30-
url: body.lessonPlanFile.url,
31-
size: body.lessonPlanFile.size,
40+
name: lessonPlanFile.name,
41+
url: lessonPlanFile.url,
42+
size: lessonPlanFile.size,
3243
},
3344
});
3445
lessonPlanId = lessonPlan.id;
3546
}
3647

3748
const absence = await prisma.absence.create({
3849
data: {
39-
lessonDate: new Date(body.lessonDate),
50+
lessonDate: new Date(lessonDate),
4051
lessonPlanId,
41-
reasonOfAbsence: body.reasonOfAbsence,
42-
notes: body.notes || null,
43-
absentTeacherId: body.absentTeacherId,
44-
substituteTeacherId: body.substituteTeacherId || null,
45-
locationId: body.locationId,
46-
subjectId: body.subjectId,
47-
roomNumber: body.roomNumber || null,
52+
reasonOfAbsence: reasonOfAbsence,
53+
notes: notes || null,
54+
absentTeacherId: absentTeacherId,
55+
substituteTeacherId: substituteTeacherId || null,
56+
locationId: locationId,
57+
subjectId: subjectId,
58+
roomNumber: roomNumber || null,
4859
},
4960
});
5061

app/api/editAbsence/route.ts

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import { prisma } from '@utils/prisma';
2+
import { NextResponse } from 'next/server';
3+
4+
export async function PUT(req: Request) {
5+
try {
6+
const body = await req.json();
7+
const { id, lessonPlanFile, ...fields } = body;
8+
9+
if (!id) {
10+
return NextResponse.json(
11+
{ error: 'Missing absence ID' },
12+
{ status: 400 }
13+
);
14+
}
15+
16+
const updatedAbsence = await prisma.$transaction(async (tx) => {
17+
const existing = await tx.absence.findUnique({
18+
where: { id },
19+
include: { lessonPlan: true },
20+
});
21+
22+
if (!existing) {
23+
throw new Error(`Absence with ID ${id} not found.`);
24+
}
25+
26+
const dataToUpdate: any = {};
27+
28+
if ('lessonDate' in fields)
29+
dataToUpdate.lessonDate = new Date(fields.lessonDate);
30+
if ('reasonOfAbsence' in fields)
31+
dataToUpdate.reasonOfAbsence = fields.reasonOfAbsence;
32+
if ('notes' in fields) dataToUpdate.notes = fields.notes || null;
33+
if ('absentTeacherId' in fields)
34+
dataToUpdate.absentTeacherId = fields.absentTeacherId;
35+
if ('substituteTeacherId' in fields)
36+
dataToUpdate.substituteTeacherId = fields.substituteTeacherId || null;
37+
if ('locationId' in fields) dataToUpdate.locationId = fields.locationId;
38+
if ('subjectId' in fields) dataToUpdate.subjectId = fields.subjectId;
39+
if ('roomNumber' in fields)
40+
dataToUpdate.roomNumber = fields.roomNumber || null;
41+
42+
if (lessonPlanFile) {
43+
if (existing.lessonPlanId) {
44+
await tx.absence.update({
45+
where: { id },
46+
data: { lessonPlanId: null },
47+
});
48+
await tx.lessonPlanFile.delete({
49+
where: { id: existing.lessonPlanId },
50+
});
51+
}
52+
53+
const newLessonPlan = await tx.lessonPlanFile.create({
54+
data: {
55+
name: lessonPlanFile.name,
56+
url: lessonPlanFile.url,
57+
size: lessonPlanFile.size,
58+
},
59+
});
60+
61+
dataToUpdate.lessonPlanId = newLessonPlan.id;
62+
}
63+
64+
const updated = await tx.absence.update({
65+
where: { id },
66+
data: dataToUpdate,
67+
});
68+
69+
return updated;
70+
});
71+
72+
return NextResponse.json(updatedAbsence, { status: 200 });
73+
} catch (err) {
74+
console.error('Error in PUT /api/editAbsence:', err.message || err);
75+
return NextResponse.json(
76+
{ error: 'Internal Server Error', details: err.message },
77+
{ status: 500 }
78+
);
79+
}
80+
}

app/api/filter/locations/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { prisma } from '@utils/prisma';
2-
import { NextRequest, NextResponse } from 'next/server';
32
import { Location } from '@utils/types';
3+
import { NextRequest, NextResponse } from 'next/server';
44

55
export async function GET(req: NextRequest) {
66
try {

app/api/filter/subjects/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { prisma } from '@utils/prisma';
2-
import { NextRequest, NextResponse } from 'next/server';
32
import { SubjectAPI } from '@utils/types';
3+
import { NextRequest, NextResponse } from 'next/server';
44

55
export async function GET(req: NextRequest) {
66
try {

app/api/getAbsenceDates/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { YearlyAbsenceData } from '@utils/types';
12
import { NextResponse } from 'next/server';
23
import { getAbsenceYearRanges } from './absenceDates';
3-
import { YearlyAbsenceData } from '@utils/types';
44

55
export async function GET() {
66
try {

app/api/locations/[id]/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { NextRequest, NextResponse } from 'next/server';
21
import { prisma } from '@utils/prisma';
2+
import { NextRequest, NextResponse } from 'next/server';
33

44
export async function PATCH(
55
request: NextRequest,

app/api/locations/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { NextRequest, NextResponse } from 'next/server';
21
import { prisma } from '@utils/prisma';
2+
import { NextRequest, NextResponse } from 'next/server';
33

44
export async function GET() {
55
try {

0 commit comments

Comments
 (0)