Compare commits
9 Commits
4ac4be0368
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 6928d22783 | |||
| 9d27dfeeb7 | |||
| f726c740d4 | |||
| 20541b6cc8 | |||
| 42406e853c | |||
| bd36faa033 | |||
| a3b753a5f7 | |||
| d8c018e3ef | |||
| 996e74c742 |
@@ -0,0 +1,21 @@
|
|||||||
|
name: Deploy API
|
||||||
|
on: workflow_dispatch
|
||||||
|
|
||||||
|
environment:
|
||||||
|
name: Rainbow
|
||||||
|
runner: rianbow-1
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
Build-Api:
|
||||||
|
environment: Rainbow
|
||||||
|
steps:
|
||||||
|
- name: Check out repo
|
||||||
|
uses: actions/checkout@v7
|
||||||
|
- run: cd packages/api
|
||||||
|
- run: pnpm install --prod
|
||||||
|
- run: tsc -p .
|
||||||
|
- name: Publish Artifact
|
||||||
|
uses: actions/upload-artifact@v7
|
||||||
|
with:
|
||||||
|
path: ./dist
|
||||||
|
retention-days: 2S
|
||||||
@@ -4,7 +4,7 @@ import "dotenv/config";
|
|||||||
import { defineConfig, env } from "prisma/config";
|
import { defineConfig, env } from "prisma/config";
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
schema: "prisma/schema.prisma",
|
schema: "prisma/schema",
|
||||||
migrations: {
|
migrations: {
|
||||||
path: "prisma/migrations",
|
path: "prisma/migrations",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,79 +0,0 @@
|
|||||||
generator client {
|
|
||||||
provider = "prisma-client"
|
|
||||||
output = "../src/generated/prisma"
|
|
||||||
}
|
|
||||||
|
|
||||||
datasource db {
|
|
||||||
provider = "postgresql"
|
|
||||||
}
|
|
||||||
|
|
||||||
model Member {
|
|
||||||
id String @id @default(dbgenerated("uuidv7()")) @db.Uuid
|
|
||||||
vorname String? @db.VarChar
|
|
||||||
nachname String? @db.VarChar
|
|
||||||
geburtsdatum DateTime? @db.Date
|
|
||||||
geburtsort String? @db.VarChar
|
|
||||||
geschlecht String? @db.VarChar
|
|
||||||
passnummer String? @db.VarChar
|
|
||||||
verein Boolean?
|
|
||||||
graduierung String? @db.VarChar
|
|
||||||
letztePruefung DateTime? @db.Date
|
|
||||||
kontakt String? @db.VarChar
|
|
||||||
kuendigungzum DateTime? @db.Date
|
|
||||||
marker Boolean?
|
|
||||||
creationDate DateTime? @default(now()) @db.Date
|
|
||||||
}
|
|
||||||
|
|
||||||
model session {
|
|
||||||
sid String @id @db.VarChar
|
|
||||||
sess Json @db.Json
|
|
||||||
expire DateTime @db.Timestamp(6)
|
|
||||||
|
|
||||||
@@index([expire], map: "IDX_session_expire")
|
|
||||||
}
|
|
||||||
|
|
||||||
enum Topic {
|
|
||||||
TEST
|
|
||||||
EVENTS
|
|
||||||
}
|
|
||||||
|
|
||||||
model FoundEvents {
|
|
||||||
id String @id @default(dbgenerated("uuidv7()")) @db.Uuid
|
|
||||||
source String @db.VarChar
|
|
||||||
url String @db.VarChar
|
|
||||||
foundDate DateTime @default(now()) @db.Date
|
|
||||||
eventDate String? @db.VarChar
|
|
||||||
title String? @db.VarChar
|
|
||||||
description String? @db.VarChar
|
|
||||||
attachedFiles FoundEventAttachments[]
|
|
||||||
}
|
|
||||||
|
|
||||||
model FoundEventAttachments {
|
|
||||||
id String @id @default(dbgenerated("uuidv7()")) @db.Uuid
|
|
||||||
title String @db.VarChar
|
|
||||||
url String @db.VarChar
|
|
||||||
event FoundEvents @relation(fields: [eventId], references: [id])
|
|
||||||
eventId String @db.Uuid
|
|
||||||
}
|
|
||||||
|
|
||||||
model PushSubscription {
|
|
||||||
id String @id @default(dbgenerated("uuidv7()")) @db.Uuid
|
|
||||||
endpoint String @db.VarChar
|
|
||||||
expirationTime Float?
|
|
||||||
p256dh String @db.VarChar
|
|
||||||
auth String @db.VarChar
|
|
||||||
|
|
||||||
userId String @db.VarChar
|
|
||||||
user User @relation(fields: [userId], references: [id])
|
|
||||||
|
|
||||||
topic Topic
|
|
||||||
topicConfiguration Json? @db.JsonB
|
|
||||||
clientId String @db.Uuid
|
|
||||||
lastNotified DateTime? @db.Date
|
|
||||||
}
|
|
||||||
|
|
||||||
model User {
|
|
||||||
id String @db.VarChar @id
|
|
||||||
subscriptions PushSubscription[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
model Exam {
|
||||||
|
id String @id @default(dbgenerated("uuidv7()"))
|
||||||
|
date DateTime @db.Date
|
||||||
|
title String @db.VarChar
|
||||||
|
memberExams MemberExam[]
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
model FoundEventAttachments {
|
||||||
|
id String @id @default(dbgenerated("uuidv7()")) @db.Uuid
|
||||||
|
title String @db.VarChar
|
||||||
|
url String @db.VarChar
|
||||||
|
event FoundEvents @relation(fields: [eventId], references: [id])
|
||||||
|
eventId String @db.Uuid
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
model FoundEvents {
|
||||||
|
id String @id @default(dbgenerated("uuidv7()")) @db.Uuid
|
||||||
|
source String @db.VarChar
|
||||||
|
url String @db.VarChar
|
||||||
|
foundDate DateTime @default(now()) @db.Date
|
||||||
|
eventDate String? @db.VarChar
|
||||||
|
title String? @db.VarChar
|
||||||
|
description String? @db.VarChar
|
||||||
|
attachedFiles FoundEventAttachments[]
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
model Member {
|
||||||
|
id String @id @default(dbgenerated("uuidv7()")) @db.Uuid
|
||||||
|
vorname String? @db.VarChar
|
||||||
|
nachname String? @db.VarChar
|
||||||
|
geburtsdatum DateTime? @db.Date
|
||||||
|
geburtsort String? @db.VarChar
|
||||||
|
geschlecht String? @db.VarChar
|
||||||
|
passnummer String? @db.VarChar
|
||||||
|
verein Boolean?
|
||||||
|
graduierung String? @db.VarChar
|
||||||
|
letztePruefung DateTime? @db.Date
|
||||||
|
kontakt String? @db.VarChar
|
||||||
|
kuendigungzum DateTime? @db.Date
|
||||||
|
marker Boolean?
|
||||||
|
creationDate DateTime? @default(now()) @db.Date
|
||||||
|
memberExams MemberExam[]
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
model MemberExam {
|
||||||
|
id String @id @default(dbgenerated("uuidv7()")) @db.Uuid
|
||||||
|
targetGrade String @db.VarChar
|
||||||
|
|
||||||
|
memberId String @db.Uuid
|
||||||
|
member Member @relation(fields: [memberId], references: [id])
|
||||||
|
|
||||||
|
examId String @db.Uuid
|
||||||
|
exam Exam @relation(fields: [examId], references: [id])
|
||||||
|
|
||||||
|
passed Boolean?
|
||||||
|
comment String? @db.VarChar
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
model PushSubscription {
|
||||||
|
id String @id @default(dbgenerated("uuidv7()")) @db.Uuid
|
||||||
|
endpoint String @db.VarChar
|
||||||
|
expirationTime Float?
|
||||||
|
p256dh String @db.VarChar
|
||||||
|
auth String @db.VarChar
|
||||||
|
|
||||||
|
userId String @db.VarChar
|
||||||
|
user User @relation(fields: [userId], references: [id])
|
||||||
|
|
||||||
|
topic Topic
|
||||||
|
topicConfiguration Json? @db.JsonB
|
||||||
|
clientId String @db.Uuid
|
||||||
|
lastNotified DateTime? @db.Date
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
generator client {
|
||||||
|
provider = "prisma-client"
|
||||||
|
output = "../../src/generated/prisma"
|
||||||
|
}
|
||||||
|
|
||||||
|
datasource db {
|
||||||
|
provider = "postgresql"
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
model session {
|
||||||
|
sid String @id @db.VarChar
|
||||||
|
sess Json @db.Json
|
||||||
|
expire DateTime @db.Timestamp(6)
|
||||||
|
|
||||||
|
@@index([expire], map: "IDX_session_expire")
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
enum Topic {
|
||||||
|
TEST
|
||||||
|
EVENTS
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
model User {
|
||||||
|
id String @id @db.VarChar
|
||||||
|
subscriptions PushSubscription[]
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
import express from "express";
|
||||||
|
import { Body, Controller, Get, Path, Post, Query, Request, Route } from "tsoa";
|
||||||
|
import type {
|
||||||
|
ExamCreationDto,
|
||||||
|
ExamDto,
|
||||||
|
ExamWithMembersDto,
|
||||||
|
MemberExamCreationDto,
|
||||||
|
MemberExamDto,
|
||||||
|
} from "../dtos/examDto.js";
|
||||||
|
import { inject } from "../infrastructure/di/index.js";
|
||||||
|
import { ExamsService } from "../services/examsService.js";
|
||||||
|
|
||||||
|
@Route("exams")
|
||||||
|
export class ExamsController extends Controller {
|
||||||
|
private readonly examsService = inject(ExamsService);
|
||||||
|
|
||||||
|
@Post()
|
||||||
|
public async createExam(
|
||||||
|
@Request() request: express.Request,
|
||||||
|
@Body() newExam: ExamCreationDto,
|
||||||
|
): Promise<ExamDto> {
|
||||||
|
return await this.examsService.createExam(newExam, request);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get("latest")
|
||||||
|
public async getLatestExam(
|
||||||
|
@Request() request: express.Request,
|
||||||
|
): Promise<ExamWithMembersDto | null> {
|
||||||
|
return await this.examsService.getLatest(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Post("register/{examId}")
|
||||||
|
public async registerForExam(
|
||||||
|
@Request() request: express.Request,
|
||||||
|
@Body() newRegistration: MemberExamCreationDto
|
||||||
|
): Promise<MemberExamDto> {
|
||||||
|
return await this.examsService.register(newRegistration, request);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
import {
|
||||||
|
type ExamModel,
|
||||||
|
type MemberExamModel,
|
||||||
|
} from "../generated/prisma/models.js";
|
||||||
|
|
||||||
|
export class ExamCreationDto implements Omit<ExamModel, "id"> {
|
||||||
|
date!: Date;
|
||||||
|
title!: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ExamDto implements ExamModel {
|
||||||
|
id!: string;
|
||||||
|
date!: Date;
|
||||||
|
title!: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class MemberExamDto implements MemberExamModel {
|
||||||
|
id!: string;
|
||||||
|
targetGrade!: string;
|
||||||
|
memberId!: string;
|
||||||
|
examId!: string;
|
||||||
|
passed!: boolean | null;
|
||||||
|
comment!: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ExamWithMembersDto implements ExamModel {
|
||||||
|
id!: string;
|
||||||
|
date!: Date;
|
||||||
|
title!: string;
|
||||||
|
memberExams!: MemberExamDto[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export class MemberExamCreationDto implements Omit<
|
||||||
|
MemberExamModel,
|
||||||
|
"id" | "passed" | "comment"
|
||||||
|
> {
|
||||||
|
targetGrade!: string;
|
||||||
|
memberId!: string;
|
||||||
|
examId!: string;
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
import type { Request } from "express";
|
||||||
|
import type {
|
||||||
|
ExamCreationDto,
|
||||||
|
ExamDto,
|
||||||
|
ExamWithMembersDto,
|
||||||
|
MemberExamCreationDto,
|
||||||
|
MemberExamDto,
|
||||||
|
} from "../dtos/examDto.js";
|
||||||
|
import { inject } from "../infrastructure/di/index.js";
|
||||||
|
import { Injectable } from "../infrastructure/di/injectable-decorator.js";
|
||||||
|
import { DatabaseService } from "./db/prisma.js";
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class ExamsService {
|
||||||
|
private readonly db = inject(DatabaseService);
|
||||||
|
public async createExam(
|
||||||
|
newExam: ExamCreationDto,
|
||||||
|
request: Request,
|
||||||
|
): Promise<ExamDto> {
|
||||||
|
return await this.db.doRequest(
|
||||||
|
async prisma =>
|
||||||
|
prisma.exam.create({
|
||||||
|
data: newExam,
|
||||||
|
}),
|
||||||
|
request,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
public async getLatest(
|
||||||
|
request: Request,
|
||||||
|
): Promise<ExamWithMembersDto | null> {
|
||||||
|
return await this.db.doRequest(
|
||||||
|
async prisma =>
|
||||||
|
prisma.exam.findFirst({
|
||||||
|
orderBy: { date: "desc" },
|
||||||
|
include: { memberExams: true },
|
||||||
|
}),
|
||||||
|
request,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async register(
|
||||||
|
creationDto: MemberExamCreationDto,
|
||||||
|
request: Request,
|
||||||
|
): Promise<MemberExamDto> {
|
||||||
|
return await this.db.doRequest(
|
||||||
|
async prisma =>
|
||||||
|
prisma.memberExam.create({
|
||||||
|
data: {
|
||||||
|
examId: creationDto.examId,
|
||||||
|
memberId: creationDto.memberId,
|
||||||
|
targetGrade: creationDto.targetGrade,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
request,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user