Compare commits

..

4 commits

Author SHA1 Message Date
bfd630ec26 DB (encrypted) export/import 2024-10-26 20:32:41 +02:00
223c47133b ignore WebStorm IDE files 2024-10-17 18:03:58 +02:00
anton
36d47b0d12 Exporting database as json 2024-10-17 17:44:52 +02:00
5503749705 some config vars only if not sqlite
new config parameter: DB_TYPE
2024-09-28 22:56:15 +02:00
298 changed files with 900 additions and 10504 deletions

View file

@ -1,6 +0,0 @@
# NodeJs
node_modules/
dist/
.git/
files/
.env

View file

@ -1,5 +1,4 @@
DB_TYPE = (mysql|sqlite|...)
DB_PORT = number
DB_HOST = database_host
DB_NAME = database_name
DB_USERNAME = database_username
@ -10,7 +9,6 @@ SERVER_PORT = portnumber
JWT_SECRET = ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890
JWT_EXPIRATION = [0-9]*(y|d|h|m|s)
REFRESH_EXPIRATION = [0-9]*(y|d|h|m|s)
PWA_REFRESH_EXPIRATION = [0-9]*(y|d|h|m|s)
MAIL_USERNAME = mail_username
MAIL_PASSWORD = mail_password
@ -19,4 +17,3 @@ MAIL_PORT = mail_portnumber
MAIL_SECURE (true|false) // true for port 465, fals for other ports
CLUB_NAME = clubname
CLUB_WEBSITE = https://my-club-website-url

5
.gitignore vendored
View file

@ -130,6 +130,5 @@ dist
.yarn/install-state.gz
.pnp.*
files
.idea
# WebStorm
.idea/

View file

@ -1,46 +0,0 @@
FROM node:18-alpine AS build
RUN apk add --no-cache \
chromium \
nss \
freetype \
harfbuzz \
ca-certificates \
ttf-freefont
WORKDIR /app
COPY package*.json ./
ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser
RUN npm install
COPY . /app
RUN npm run build
FROM node:18-alpine AS prod
RUN apk add --no-cache \
chromium \
nss \
freetype \
harfbuzz \
ca-certificates \
ttf-freefont
WORKDIR /app
RUN mkdir -p /app/export
ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser
COPY --from=build /app/src/templates /app/src/templates
COPY --from=build /app/dist /app/dist
COPY --from=build /app/node_modules /app/node_modules
COPY --from=build /app/package.json /app/package.json
EXPOSE 5000
CMD [ "npm", "run", "start" ]

102
README.md
View file

@ -1,92 +1,30 @@
# ff-admin-server
# member-administration-server
Administration für Feuerwehren und Vereine (Backend).
Memberadministration
## Einleitung
Dieses Projekt, `ff-admin-server`, ist das Backend zur Verwaltung von Mitgliederdaten. Die zugehörige Webapp ist im Repository [ff-admin-ui](https://forgejo.jk-effects.cloud/Ehrenamt/ff-admin) zu finden.
Eine Demo zusammen mit der `ff-admin` finden Sie unter [https://admin-demo.ff-admin.de](https://admin-demo.ff-admin.de).
Authentications is realized via JWT-Tokens. The server is able to send Mails to the members.
Login is possible via Username and TOTP.
## Installation
Das Image exposed nur den Port 5000. Die Env-Variable SERVER_PORT kann nur im lokal ausführenden dev-Kontext verwendet werden.
### Requirements
### Docker Compose Setup
1. MySql Database
2. Access to the internet for sending Mails
Um den Container hochzufahren, erstellen Sie eine `docker-compose.yml` Datei mit folgendem Inhalt:
### Configuration
```yaml
version: "3"
1. Copy the .env.example file to .env and fill in the required information
2. Create a new Database in MySql named as in the .env file
3. Install all packages via `npm install`
4. Start the application to create the database schema
services:
ff-ff-admin-server:
image: docker.registry.jk-effects.cloud/ehrenamt/ff-admin/server:latest
container_name: ff_member_administration_server
restart: unless-stopped
environment:
- DB_TYPE=<mysql|sqlite> # default ist auf mysql gesetzt
- DB_HOST=ffm-db
- DB_PORT=<number> # default ist auf 3306 gesetzt
- DB_NAME=ffadmin
- DB_USERNAME=administration_backend
- DB_PASSWORD=<dbuserpasswd>
- JWT_SECRET=<tobemodified>
- JWT_EXPIRATION=<number[m|d] - bsp.:15m> # default ist auf 15m gesetzt
- REFRESH_EXPIRATION=<number[m|d] - bsp.:1d> # default ist auf 1d gesetzt
- PWA_REFRESH_EXPIRATION=<number[m|d] - bsp.:5d> # default ist auf 5d gesetzt
- MAIL_USERNAME=<mailadress|username>
- MAIL_PASSWORD=<password>
- MAIL_HOST=<url>
- MAIL_PORT=<port> # default ist auf 578 gesetzt
- MAIL_SECURE=<boolean> # default ist auf false gesetzt
- CLUB_NAME=<tobemodified>
- CLUB_WEBSITE=<tobemodified>
volumes:
- <volume|local path>:/app/files
networks:
- ff_internal
depends_on:
- ff-db
## Testing
ff-db:
image: mariadb:11.2
container_name: ff_db
restart: unless-stopped
environment:
- MYSQL_DATABASE=ffadmin
- MYSQL_USER=administration_backend
- MYSQL_PASSWORD=<dbuserpasswd>
- MYSQL_ROOT_PASSWORD=<dbrootpasswd>
volumes:
- <volume|local path>:/var/lib/mysql
networks:
- ff_internal
networks:
ff_internal:
```
Führen Sie dann den folgenden Befehl im Verzeichnis der compose-Datei aus, um den Container zu starten:
```sh
docker-compose up -d
```
### Manuelle Installation
Klonen Sie dieses Repository und installieren Sie die Abhängigkeiten:
```sh
git clone https://forgejo.jk-effects.cloud/Ehrenamt/ff-admin-server.git
cd ff-admin-server
npm install
npm run build
npm run start
```
## Fragen und Wünsche
Bei Fragen, Anregungen oder Wünschen können Sie sich gerne melden.\
Wir freuen uns über Ihr Feedback und helfen Ihnen gerne weiter.\
Schreiben Sie dafür eine Mail an julian.krauser@jk-effects.com.
1. Install the database-system-package you like (e.g. mysql, mariadb, postgresql, sqlite3)
2. Configure type inside src/data-source.ts to run the database-system you like.
3. Set migrationsRun to false and synchronize to true for rapid prototyping
4. Building the schema via CLI:
- Run `npm run update-database` to build the schema using the migrations without starting the application
- Run `npm run synchronize-database` to build the schema without using migrations without starting the application
5. Run `npm run dev` to run inside dev-environment (runs migrations if migrationsRun is set to true)

1240
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
{
"name": "ff-admin-server",
"version": "1.1.1",
"name": "member-administration-server",
"version": "0.0.2",
"description": "Feuerwehr/Verein Mitgliederverwaltung Server",
"main": "dist/index.js",
"scripts": {
@ -16,7 +16,7 @@
},
"repository": {
"type": "git",
"url": "https://forgejo.jk-effects.cloud/Ehrenamt/ff-admin-server.git"
"url": "https://forgejo.jk-effects.cloud/Ehrenamt/member-administration-server.git"
},
"keywords": [
"Feuerwehr"
@ -27,16 +27,11 @@
"cors": "^2.8.5",
"dotenv": "^16.4.5",
"express": "^5.0.0-beta.3",
"handlebars": "^4.7.8",
"ics": "^3.8.1",
"jsonwebtoken": "^9.0.2",
"moment": "^2.30.1",
"ms": "^2.1.3",
"mysql": "^2.18.1",
"node-schedule": "^2.1.1",
"nodemailer": "^6.9.14",
"pdf-lib": "^1.17.1",
"puppeteer": "^23.11.1",
"qrcode": "^1.5.4",
"reflect-metadata": "^0.2.2",
"socket.io": "^4.7.5",

View file

@ -1,12 +1,12 @@
import { dataSource } from "../../../data-source";
import { award } from "../../../entity/settings/award";
import InternalException from "../../../exceptions/internalException";
import { dataSource } from "../data-source";
import { award } from "../entity/award";
import InternalException from "../exceptions/internalException";
import { CreateAwardCommand, DeleteAwardCommand, UpdateAwardCommand } from "./awardCommand";
export default abstract class AwardCommandHandler {
/**
* @description create award
* @param {CreateAwardCommand} createAward
* @param CreateAwardCommand
* @returns {Promise<number>}
*/
static async create(createAward: CreateAwardCommand): Promise<number> {
@ -28,7 +28,7 @@ export default abstract class AwardCommandHandler {
/**
* @description update award
* @param {UpdateAwardCommand} updateAward
* @param UpdateAwardCommand
* @returns {Promise<void>}
*/
static async update(updateAward: UpdateAwardCommand): Promise<void> {
@ -48,22 +48,19 @@ export default abstract class AwardCommandHandler {
/**
* @description delete award
* @param {DeleteAwardCommand} deleteAward
* @param DeleteAwardCommand
* @returns {Promise<void>}
*/
static async delete(deleteAward: DeleteAwardCommand): Promise<void> {
static async delete(deletAward: DeleteAwardCommand): Promise<void> {
return await dataSource
.createQueryBuilder()
.delete()
.from(award)
.where("id = :id", { id: deleteAward.id })
.where("id = :id", { id: deletAward.id })
.execute()
.then(() => {})
.catch((err) => {
throw new InternalException(
`Failed deleting award ${err.code.includes("ER_ROW_IS_REFERENCED") ? " due to referenced data" : ""}`,
err
);
throw new InternalException("Failed deleting award", err);
});
}
}

View file

@ -1,24 +0,0 @@
export interface CreateCalendarCommand {
starttime: Date;
endtime: Date;
title: string;
content: string;
location: string;
allDay: boolean;
typeId: number;
}
export interface UpdateCalendarCommand {
id: string;
starttime: Date;
endtime: Date;
title: string;
content: string;
location: string;
allDay: boolean;
typeId: number;
}
export interface DeleteCalendarCommand {
id: string;
}

View file

@ -1,96 +0,0 @@
import { dataSource } from "../../../data-source";
import { calendar } from "../../../entity/club/calendar";
import { calendarType } from "../../../entity/settings/calendarType";
import InternalException from "../../../exceptions/internalException";
import { CreateCalendarCommand, DeleteCalendarCommand, UpdateCalendarCommand } from "./calendarCommand";
export default abstract class CalendarCommandHandler {
/**
* @description create calendar
* @param {CreateCalendarCommand} createCalendar
* @returns {Promise<number>}
*/
static async create(createCalendar: CreateCalendarCommand): Promise<number> {
return await dataSource
.createQueryBuilder()
.insert()
.into(calendar)
.values({
starttime: createCalendar.starttime,
endtime: createCalendar.endtime,
title: createCalendar.title,
content: createCalendar.content,
location: createCalendar.location,
allDay: createCalendar.allDay,
type: await dataSource
.getRepository(calendarType)
.createQueryBuilder("type")
.where("id = :id", { id: createCalendar.typeId })
.getOneOrFail(),
})
.execute()
.then((result) => {
return result.identifiers[0].id;
})
.catch((err) => {
throw new InternalException("Failed creating calendar", err);
});
}
/**
* @description update calendar
* @param {UpdateCalendarCommand} updateCalendar
* @returns {Promise<void>}
*/
static async update(updateCalendar: UpdateCalendarCommand): Promise<void> {
let sequence = await dataSource
.getRepository(calendar)
.createQueryBuilder("calendar")
.where("id = :id", { id: updateCalendar.id })
.getOneOrFail()
.then((res) => {
return res.sequence;
});
return await dataSource
.createQueryBuilder()
.update(calendar)
.set({
starttime: updateCalendar.starttime,
endtime: updateCalendar.endtime,
title: updateCalendar.title,
content: updateCalendar.content,
location: updateCalendar.location,
allDay: updateCalendar.allDay,
type: await dataSource
.getRepository(calendarType)
.createQueryBuilder("type")
.where("id = :id", { id: updateCalendar.typeId })
.getOneOrFail(),
sequence: sequence + 1,
})
.where("id = :id", { id: updateCalendar.id })
.execute()
.then(() => {})
.catch((err) => {
throw new InternalException("Failed updating award", err);
});
}
/**
* @description delete calendar
* @param {DeleteCalendarCommand} deleteCalendar
* @returns {Promise<void>}
*/
static async delete(deleteCalendar: DeleteCalendarCommand): Promise<void> {
return await dataSource
.createQueryBuilder()
.delete()
.from(calendar)
.where("id = :id", { id: deleteCalendar.id })
.execute()
.then(() => {})
.catch((err) => {
throw new InternalException("Failed deleting calendar", err);
});
}
}

View file

@ -1,18 +0,0 @@
export interface CreateNewsletterCommand {
title: string;
}
export interface SynchronizeNewsletterCommand {
id: number;
title: string;
description: string;
newsletterTitle: string;
newsletterText: string;
newsletterSignatur: string;
recipientsByQueryId?: number;
}
export interface SendNewsletterCommand {
id: number;
isSent: boolean;
}

View file

@ -1,73 +0,0 @@
import { dataSource } from "../../../data-source";
import { newsletter } from "../../../entity/club/newsletter/newsletter";
import InternalException from "../../../exceptions/internalException";
import { CreateNewsletterCommand, SendNewsletterCommand, SynchronizeNewsletterCommand } from "./newsletterCommand";
export default abstract class NewsletterCommandHandler {
/**
* @description create newsletter
* @param {CreateNewsletterCommand} createNewsletter
* @returns {Promise<number>}
*/
static async create(createNewsletter: CreateNewsletterCommand): Promise<number> {
return await dataSource
.createQueryBuilder()
.insert()
.into(newsletter)
.values({
title: createNewsletter.title,
})
.execute()
.then((result) => {
return result.identifiers[0].id;
})
.catch((err) => {
throw new InternalException("Failed creating newsletter", err);
});
}
/**
* @description sync newsletter
* @param {SynchronizeNewsletterCommand} syncNewsletter
* @returns {Promise<void>}
*/
static async sync(syncNewsletter: SynchronizeNewsletterCommand): Promise<void> {
return await dataSource
.createQueryBuilder()
.update(newsletter)
.set({
title: syncNewsletter.title,
description: syncNewsletter.description,
newsletterTitle: syncNewsletter.newsletterTitle,
newsletterText: syncNewsletter.newsletterText,
newsletterSignatur: syncNewsletter.newsletterSignatur,
recipientsByQueryId: syncNewsletter.recipientsByQueryId,
})
.where("id = :id", { id: syncNewsletter.id })
.execute()
.then(() => {})
.catch((err) => {
throw new InternalException("Failed synching newsletter", err);
});
}
/**
* @description send newsletter
* @param {SendNewsletterCommand} syncNewsletter
* @returns {Promise<void>}
*/
static async send(syncNewsletter: SendNewsletterCommand): Promise<void> {
return await dataSource
.createQueryBuilder()
.update(newsletter)
.set({
isSent: syncNewsletter.isSent,
})
.where("id = :id", { id: syncNewsletter.id })
.execute()
.then(() => {})
.catch((err) => {
throw new InternalException("Failed setting newsletter send state", err);
});
}
}

View file

@ -1,10 +0,0 @@
export interface SynchronizeNewsletterDatesCommand {
newsletterId: number;
dates: Array<NewsletterDateCommand>;
}
export interface NewsletterDateCommand {
calendarId: string;
diffTitle?: string;
diffDescription?: string;
}

View file

@ -1,97 +0,0 @@
import { DeleteResult, EntityManager, InsertResult, UpdateResult } from "typeorm";
import { dataSource } from "../../../data-source";
import InternalException from "../../../exceptions/internalException";
import NewsletterDatesService from "../../../service/club/newsletter/newsletterDatesService";
import { NewsletterDateCommand, SynchronizeNewsletterDatesCommand } from "./newsletterDatesCommand";
import { newsletterDates } from "../../../entity/club/newsletter/newsletterDates";
export default abstract class NewsletterDatesCommandHandler {
/**
* @description sync newsletter dates
* @param {SynchronizeNewsletterDatesCommand} syncNewsletterDates
* @returns {Promise<void>}
*/
static async sync(syncNewsletterDates: SynchronizeNewsletterDatesCommand): Promise<void> {
let currentDates = await NewsletterDatesService.getAll(syncNewsletterDates.newsletterId);
return await dataSource.manager
.transaction(async (manager) => {
let newDates = syncNewsletterDates.dates.filter(
(r) => !currentDates.some((cd) => cd.calendarId == r.calendarId)
);
let removeDates = currentDates.filter(
(r) => !syncNewsletterDates.dates.some((cd) => cd.calendarId == r.calendarId)
);
let keptDates = syncNewsletterDates.dates.filter(
(r) =>
currentDates.some((cd) => cd.calendarId == r.calendarId) &&
!removeDates.some((cd) => cd.calendarId == r.calendarId)
);
if (newDates.length != 0) {
await this.syncPresenceAdd(manager, syncNewsletterDates.newsletterId, newDates);
}
if (removeDates.length != 0) {
await this.syncPresenceRemove(manager, syncNewsletterDates.newsletterId, removeDates);
}
for (const date of keptDates) {
await this.syncPresenceUpdate(manager, syncNewsletterDates.newsletterId, date);
}
})
.then(() => {})
.catch((err) => {
throw new InternalException("Failed syncing newsletter dates", err);
});
}
private static async syncPresenceAdd(
manager: EntityManager,
newsletterId: number,
dates: Array<NewsletterDateCommand>
): Promise<InsertResult> {
return await manager
.createQueryBuilder()
.insert()
.into(newsletterDates)
.values(
dates.map((d) => ({
...d,
newsletterId: newsletterId,
}))
)
.execute();
}
private static async syncPresenceUpdate(
manager: EntityManager,
newsletterId: number,
date: NewsletterDateCommand
): Promise<UpdateResult> {
return await manager
.createQueryBuilder()
.update(newsletterDates)
.set({
diffTitle: date.diffTitle,
diffDescription: date.diffDescription,
})
.where("calendarId = :calendarId", { calendarId: date.calendarId })
.andWhere("newsletterId = :newsletterId", { newsletterId })
.execute();
}
private static async syncPresenceRemove(
manager: EntityManager,
newsletterId: number,
dates: Array<NewsletterDateCommand>
): Promise<DeleteResult> {
return await manager
.createQueryBuilder()
.delete()
.from(newsletterDates)
.where("calendarId IN (:...ids)", { ids: dates.map((d) => d.calendarId) })
.andWhere("newsletterId = :newsletterId", { newsletterId })
.execute();
}
}

View file

@ -1,4 +0,0 @@
export interface SynchronizeNewsletterRecipientsCommand {
newsletterId: number;
recipients: Array<number>;
}

View file

@ -1,73 +0,0 @@
import { DeleteResult, EntityManager, InsertResult, UpdateResult } from "typeorm";
import { dataSource } from "../../../data-source";
import InternalException from "../../../exceptions/internalException";
import NewsletterRecipientsService from "../../../service/club/newsletter/newsletterRecipientsService";
import { SynchronizeNewsletterRecipientsCommand } from "./newsletterRecipientsCommand";
import { newsletterRecipients } from "../../../entity/club/newsletter/newsletterRecipients";
export default abstract class NewsletterRecipientsCommandHandler {
/**
* @description sync newsletterRecipients
* @param {SynchronizeNewsletterRecipientsCommand} syncNewsletterRecipients
* @returns {Promise<void>}
*/
static async sync(syncNewsletterRecipients: SynchronizeNewsletterRecipientsCommand): Promise<void> {
let currentRecipients = (await NewsletterRecipientsService.getAll(syncNewsletterRecipients.newsletterId)).map(
(r) => r.memberId
);
return await dataSource.manager
.transaction(async (manager) => {
let newRecipients = syncNewsletterRecipients.recipients.filter(
(r) => !currentRecipients.map((np) => np).includes(r)
);
let removeRecipients = currentRecipients.filter(
(r) => !syncNewsletterRecipients.recipients.map((np) => np).includes(r)
);
if (newRecipients.length != 0) {
await this.syncPresenceAdd(manager, syncNewsletterRecipients.newsletterId, newRecipients);
}
if (removeRecipients.length != 0) {
await this.syncPresenceRemove(manager, syncNewsletterRecipients.newsletterId, removeRecipients);
}
})
.then(() => {})
.catch((err) => {
throw new InternalException("Failed syncing newsletter recipients", err);
});
}
private static async syncPresenceAdd(
manager: EntityManager,
newsletterId: number,
recipients: Array<number>
): Promise<InsertResult> {
return await manager
.createQueryBuilder()
.insert()
.into(newsletterRecipients)
.values(
recipients.map((r) => ({
memberId: r,
newsletterId: newsletterId,
}))
)
.execute();
}
private static async syncPresenceRemove(
manager: EntityManager,
newsletterId: number,
recipients: Array<number>
): Promise<DeleteResult> {
return await manager
.createQueryBuilder()
.delete()
.from(newsletterRecipients)
.where("memberId IN (:...ids)", { ids: recipients })
.andWhere("newsletterId = :newsletterId", { newsletterId })
.execute();
}
}

View file

@ -1,6 +0,0 @@
export interface SynchronizeProtocolAgendaCommand {
id?: number;
topic: string;
context: string;
protocolId: number;
}

View file

@ -1,49 +0,0 @@
import { dataSource } from "../../../data-source";
import { protocolAgenda } from "../../../entity/club/protocol/protocolAgenda";
import InternalException from "../../../exceptions/internalException";
import { SynchronizeProtocolAgendaCommand } from "./protocolAgendaCommand";
export default abstract class ProtocolAgendaCommandHandler {
/**
* @description create protocolAgenda
* @param {number} protocolId
* @returns {Promise<number>}
*/
static async create(protocolId: number): Promise<number> {
return await dataSource
.createQueryBuilder()
.insert()
.into(protocolAgenda)
.values({
topic: "",
context: "",
protocolId,
})
.execute()
.then((result) => {
return result.identifiers[0].id;
})
.catch((err) => {
throw new InternalException("Failed creating protocol", err);
});
}
/**
* @description sync protocolAgenda
* @param {Array<SynchronizeProtocolAgendaCommand>} syncProtocolAgenda
* @returns {Promise<void>}
*/
static async sync(syncProtocolAgenda: Array<SynchronizeProtocolAgendaCommand>): Promise<void> {
return await dataSource
.createQueryBuilder()
.insert()
.into(protocolAgenda)
.values(syncProtocolAgenda)
.orUpdate(["topic", "context"], ["id"])
.execute()
.then(() => {})
.catch((err) => {
throw new InternalException("Failed creating protocol", err);
});
}
}

View file

@ -1,13 +0,0 @@
export interface CreateProtocolCommand {
title: string;
date: Date;
}
export interface SynchronizeProtocolCommand {
id: number;
title: string;
date: Date;
starttime: Date;
endtime: Date;
summary: string;
}

View file

@ -1,53 +0,0 @@
import { dataSource } from "../../../data-source";
import { protocol } from "../../../entity/club/protocol/protocol";
import InternalException from "../../../exceptions/internalException";
import { CreateProtocolCommand, SynchronizeProtocolCommand } from "./protocolCommand";
export default abstract class ProtocolCommandHandler {
/**
* @description create protocol
* @param {CreateProtocolCommand} createProtocol
* @returns {Promise<number>}
*/
static async create(createProtocol: CreateProtocolCommand): Promise<number> {
return await dataSource
.createQueryBuilder()
.insert()
.into(protocol)
.values({
title: createProtocol.title,
date: createProtocol.date,
})
.execute()
.then((result) => {
return result.identifiers[0].id;
})
.catch((err) => {
throw new InternalException("Failed creating protocol", err);
});
}
/**
* @description sync protocol
* @param {SynchronizeProtocolCommand} syncProtocol
* @returns {Promise<void>}
*/
static async sync(syncProtocol: SynchronizeProtocolCommand): Promise<void> {
return await dataSource
.createQueryBuilder()
.update(protocol)
.set({
title: syncProtocol.title,
date: syncProtocol.date,
starttime: syncProtocol.starttime,
endtime: syncProtocol.endtime,
summary: syncProtocol.summary,
})
.where("id = :id", { id: syncProtocol.id })
.execute()
.then(() => {})
.catch((err) => {
throw new InternalException("Failed creating protocol", err);
});
}
}

View file

@ -1,6 +0,0 @@
export interface SynchronizeProtocolDecisionCommand {
id?: number;
topic: string;
context: string;
protocolId: number;
}

View file

@ -1,48 +0,0 @@
import { dataSource } from "../../../data-source";
import { protocolDecision } from "../../../entity/club/protocol/protocolDecision";
import InternalException from "../../../exceptions/internalException";
import { SynchronizeProtocolDecisionCommand } from "./protocolDecisionCommand";
export default abstract class ProtocolDecisionCommandHandler {
/**
* @description create protocolDecision
* @param {number} protocolId
* @returns {Promise<number>}
*/
static async create(protocolId: number): Promise<number> {
return await dataSource
.createQueryBuilder()
.insert()
.into(protocolDecision)
.values({
topic: "",
context: "",
protocolId,
})
.execute()
.then((result) => {
return result.identifiers[0].id;
})
.catch((err) => {
throw new InternalException("Failed creating protocol", err);
});
}
/**
* @description sync protocolDecision
* @param {Array<SynchronizeProtocolDecisionCommand>} syncProtocolDecisions
* @returns {Promise<void>}
*/
static async sync(syncProtocolDecisions: Array<SynchronizeProtocolDecisionCommand>): Promise<void> {
return await dataSource
.createQueryBuilder()
.insert()
.into(protocolDecision)
.values(syncProtocolDecisions)
.orUpdate(["topic", "context"], ["id"])
.execute()
.then(() => {})
.catch((err) => {
throw new InternalException("Failed creating protocol", err);
});
}
}

View file

@ -1,10 +0,0 @@
export interface SynchronizeProtocolPresenceCommand {
members: Array<ProtocolPresenceCommand>;
protocolId: number;
}
export interface ProtocolPresenceCommand {
memberId: number;
absent: boolean;
excused: boolean;
}

View file

@ -1,97 +0,0 @@
import { DeleteResult, EntityManager, InsertResult, UpdateResult } from "typeorm";
import { dataSource } from "../../../data-source";
import { protocolPresence } from "../../../entity/club/protocol/protocolPresence";
import InternalException from "../../../exceptions/internalException";
import ProtocolPresenceService from "../../../service/club/protocol/protocolPrecenseService";
import { ProtocolPresenceCommand, SynchronizeProtocolPresenceCommand } from "./protocolPresenceCommand";
export default abstract class ProtocolPresenceCommandHandler {
/**
* @description sync protocolPresence
* @param {SynchronizeProtocolPresenceCommand} syncProtocolPresences
* @returns {Promise<void>}
*/
static async sync(syncProtocolPresences: SynchronizeProtocolPresenceCommand): Promise<void> {
let currentPresence = await ProtocolPresenceService.getAll(syncProtocolPresences.protocolId);
return await dataSource.manager
.transaction(async (manager) => {
let newMembers = syncProtocolPresences.members.filter(
(r) => !currentPresence.some((cp) => cp.memberId == r.memberId)
);
let removeMembers = currentPresence.filter(
(r) => !syncProtocolPresences.members.some((cp) => cp.memberId == r.memberId)
);
let keptMembers = syncProtocolPresences.members.filter(
(m) =>
currentPresence.some((cd) => cd.memberId == m.memberId) &&
!removeMembers.some((cd) => cd.memberId == m.memberId)
);
if (newMembers.length != 0) {
await this.syncPresenceAdd(manager, syncProtocolPresences.protocolId, newMembers);
}
if (removeMembers.length != 0) {
await this.syncPresenceRemove(manager, syncProtocolPresences.protocolId, removeMembers);
}
for (const member of keptMembers) {
await this.syncPresenceUpdate(manager, syncProtocolPresences.protocolId, member);
}
})
.then(() => {})
.catch((err) => {
throw new InternalException("Failed saving protocol presence", err);
});
}
private static async syncPresenceAdd(
manager: EntityManager,
protocolId: number,
memberIds: Array<ProtocolPresenceCommand>
): Promise<InsertResult> {
return await manager
.createQueryBuilder()
.insert()
.into(protocolPresence)
.values(
memberIds.map((m) => ({
...m,
protocolId,
}))
)
.execute();
}
private static async syncPresenceUpdate(
manager: EntityManager,
protocolId: number,
member: ProtocolPresenceCommand
): Promise<UpdateResult> {
return await manager
.createQueryBuilder()
.update(protocolPresence)
.set({
absent: member.absent,
excused: member.excused,
})
.where("memberId = :memberId", { memberId: member.memberId })
.andWhere("protocolId = :protocolId", { protocolId })
.execute();
}
private static async syncPresenceRemove(
manager: EntityManager,
protocolId: number,
members: Array<ProtocolPresenceCommand>
): Promise<DeleteResult> {
return await manager
.createQueryBuilder()
.delete()
.from(protocolPresence)
.where("memberId IN (:...ids)", { ids: members.map((m) => m.memberId) })
.andWhere("protocolId = :protocolId", { protocolId })
.execute();
}
}

View file

@ -1,6 +0,0 @@
export interface CreateProtocolPrintoutCommand {
title: string;
iteration: number;
filename: string;
protocolId: number;
}

View file

@ -1,31 +0,0 @@
import { dataSource } from "../../../data-source";
import { protocolPrintout } from "../../../entity/club/protocol/protocolPrintout";
import InternalException from "../../../exceptions/internalException";
import { CreateProtocolPrintoutCommand } from "./protocolPrintoutCommand";
export default abstract class ProtocolPrintoutCommandHandler {
/**
* @description create protocolPrintout
* @param {CreateProtocolPrintoutCommand} printout
* @returns {Promise<number>}
*/
static async create(printout: CreateProtocolPrintoutCommand): Promise<number> {
return await dataSource
.createQueryBuilder()
.insert()
.into(protocolPrintout)
.values({
title: printout.title,
iteration: printout.iteration,
filename: printout.filename,
protocolId: printout.protocolId,
})
.execute()
.then((result) => {
return result.identifiers[0].id;
})
.catch((err) => {
throw new InternalException("Failed creating protocol", err);
});
}
}

View file

@ -1,9 +0,0 @@
export interface SynchronizeProtocolVotingCommand {
id: number;
topic: string;
context: string;
favour: number;
abstain: number;
against: number;
protocolId: number;
}

View file

@ -1,48 +0,0 @@
import { dataSource } from "../../../data-source";
import { protocolVoting } from "../../../entity/club/protocol/protocolVoting";
import InternalException from "../../../exceptions/internalException";
import { SynchronizeProtocolVotingCommand } from "./protocolVotingCommand";
export default abstract class ProtocolVotingCommandHandler {
/**
* @description create protocolVoting
* @param {number} protocolId
* @returns {Promise<number>}
*/
static async create(protocolId: number): Promise<number> {
return await dataSource
.createQueryBuilder()
.insert()
.into(protocolVoting)
.values({
topic: "",
context: "",
protocolId,
})
.execute()
.then((result) => {
return result.identifiers[0].id;
})
.catch((err) => {
throw new InternalException("Failed creating protocol", err);
});
}
/**
* @description sync protocolVoting
* @param {Array<SynchronizeProtocolVotingCommand>} syncProtocolVotings
* @returns {Promise<void>}
*/
static async sync(syncProtocolVotings: Array<SynchronizeProtocolVotingCommand>): Promise<void> {
return await dataSource
.createQueryBuilder()
.insert()
.into(protocolVoting)
.values(syncProtocolVotings)
.orUpdate(["topic", "context", "favour", "abstain", "against"], ["id"])
.execute()
.then(() => {})
.catch((err) => {
throw new InternalException("Failed creating protocol", err);
});
}
}

View file

@ -1,9 +1,7 @@
export interface CreateCommunicationCommand {
preferred: boolean;
isSMSAlarming: boolean;
mobile: string;
email: string;
postalCode: string;
city: string;
street: string;
streetNumber: number;
@ -15,10 +13,8 @@ export interface CreateCommunicationCommand {
export interface UpdateCommunicationCommand {
id: number;
preferred: boolean;
isSMSAlarming: boolean;
mobile: string;
email: string;
postalCode: string;
city: string;
street: string;
streetNumber: number;

View file

@ -1,6 +1,8 @@
import { dataSource } from "../../../data-source";
import { communication } from "../../../entity/club/member/communication";
import InternalException from "../../../exceptions/internalException";
import { dataSource } from "../data-source";
import { communication } from "../entity/communication";
import { communicationType } from "../entity/communicationType";
import { user } from "../entity/user";
import InternalException from "../exceptions/internalException";
import {
CreateCommunicationCommand,
DeleteCommunicationCommand,
@ -10,7 +12,7 @@ import {
export default abstract class CommunicationCommandHandler {
/**
* @description create communication
* @param {CreateCommunicationCommand} createCommunication
* @param CreateCommunicationCommand
* @returns {Promise<number>}
*/
static async create(createCommunication: CreateCommunicationCommand): Promise<number> {
@ -20,16 +22,22 @@ export default abstract class CommunicationCommandHandler {
.into(communication)
.values({
preferred: createCommunication.preferred,
isSMSAlarming: createCommunication.isSMSAlarming,
mobile: createCommunication.mobile,
email: createCommunication.email,
postalCode: createCommunication.postalCode,
city: createCommunication.city,
street: createCommunication.street,
streetNumber: createCommunication.streetNumber,
streetNumberAddition: createCommunication.streetNumberAddition,
memberId: createCommunication.memberId,
typeId: createCommunication.typeId,
member: await dataSource
.getRepository(user)
.createQueryBuilder("user")
.where("id = :id", { id: createCommunication.memberId })
.getOneOrFail(),
type: await dataSource
.getRepository(communicationType)
.createQueryBuilder("communication")
.where("id = :id", { id: createCommunication.typeId })
.getOneOrFail(),
})
.execute()
.then((result) => {
@ -42,7 +50,7 @@ export default abstract class CommunicationCommandHandler {
/**
* @description update communication
* @param {UpdateCommunicationCommand} updateCommunication
* @param UpdateCommunicationCommand
* @returns {Promise<void>}
*/
static async update(updateCommunication: UpdateCommunicationCommand): Promise<void> {
@ -51,10 +59,8 @@ export default abstract class CommunicationCommandHandler {
.update(communication)
.set({
preferred: updateCommunication.preferred,
isSMSAlarming: updateCommunication.isSMSAlarming,
mobile: updateCommunication.mobile,
email: updateCommunication.email,
postalCode: updateCommunication.postalCode,
city: updateCommunication.city,
street: updateCommunication.street,
streetNumber: updateCommunication.streetNumber,
@ -71,16 +77,16 @@ export default abstract class CommunicationCommandHandler {
/**
* @description delete communication
* @param {DeleteCommunicationCommand} deleteCommunication
* @param DeleteCommunicationCommand
* @returns {Promise<void>}
*/
static async delete(deleteCommunication: DeleteCommunicationCommand): Promise<void> {
static async delete(deletCommunication: DeleteCommunicationCommand): Promise<void> {
return await dataSource
.createQueryBuilder()
.delete()
.from(communication)
.where("id = :id", { id: deleteCommunication.id })
.andWhere("memberId = :memberId", { memberId: deleteCommunication.memberId })
.where("id = :id", { id: deletCommunication.id })
.andWhere("memberId = :memberId", { memberId: deletCommunication.memberId })
.execute()
.then(() => {})
.catch((err) => {

View file

@ -1,4 +1,4 @@
import { CommunicationFieldType } from "../../../type/fieldTypes";
import { CommunicationFieldType } from "../type/fieldTypes";
export interface CreateCommunicationTypeCommand {
type: string;

View file

@ -1,6 +1,6 @@
import { dataSource } from "../../../data-source";
import { communicationType } from "../../../entity/settings/communicationType";
import InternalException from "../../../exceptions/internalException";
import { dataSource } from "../data-source";
import { communicationType } from "../entity/communicationType";
import InternalException from "../exceptions/internalException";
import {
CreateCommunicationTypeCommand,
DeleteCommunicationTypeCommand,
@ -10,7 +10,7 @@ import {
export default abstract class CommunicationTypeCommandHandler {
/**
* @description create communicationType
* @param {CreateCommunicationTypeCommand} createCommunicationType
* @param CreateCommunicationTypeCommand
* @returns {Promise<number>}
*/
static async create(createCommunicationType: CreateCommunicationTypeCommand): Promise<number> {
@ -33,7 +33,7 @@ export default abstract class CommunicationTypeCommandHandler {
/**
* @description update communicationType
* @param {UpdateCommunicationTypeCommand} updateCommunicationType
* @param UpdateCommunicationTypeCommand
* @returns {Promise<void>}
*/
static async update(updateCommunicationType: UpdateCommunicationTypeCommand): Promise<void> {
@ -54,24 +54,19 @@ export default abstract class CommunicationTypeCommandHandler {
/**
* @description delete communicationType
* @param {DeleteCommunicationTypeCommand} deleteCommunicationType
* @param DeleteCommunicationTypeCommand
* @returns {Promise<void>}
*/
static async delete(deleteCommunicationType: DeleteCommunicationTypeCommand): Promise<void> {
static async delete(deletCommunicationType: DeleteCommunicationTypeCommand): Promise<void> {
return await dataSource
.createQueryBuilder()
.delete()
.from(communicationType)
.where("id = :id", { id: deleteCommunicationType.id })
.where("id = :id", { id: deletCommunicationType.id })
.execute()
.then(() => {})
.catch((err) => {
throw new InternalException(
`Failed deleting communicationType${
err.code.includes("ER_ROW_IS_REFERENCED") ? " due to referenced data" : ""
}`,
err
);
throw new InternalException("Failed deleting communicationType", err);
});
}
}

View file

@ -1,6 +1,6 @@
import { dataSource } from "../../../data-source";
import { executivePosition } from "../../../entity/settings/executivePosition";
import InternalException from "../../../exceptions/internalException";
import { dataSource } from "../data-source";
import { executivePosition } from "../entity/executivePosition";
import InternalException from "../exceptions/internalException";
import {
CreateExecutivePositionCommand,
DeleteExecutivePositionCommand,
@ -10,7 +10,7 @@ import {
export default abstract class ExecutivePositionCommandHandler {
/**
* @description create executivePosition
* @param {CreateExecutivePositionCommand} createExecutivePosition
* @param CreateExecutivePositionCommand
* @returns {Promise<number>}
*/
static async create(createExecutivePosition: CreateExecutivePositionCommand): Promise<number> {
@ -32,7 +32,7 @@ export default abstract class ExecutivePositionCommandHandler {
/**
* @description update executivePosition
* @param {UpdateExecutivePositionCommand} updateExecutivePosition
* @param UpdateExecutivePositionCommand
* @returns {Promise<void>}
*/
static async update(updateExecutivePosition: UpdateExecutivePositionCommand): Promise<void> {
@ -52,24 +52,19 @@ export default abstract class ExecutivePositionCommandHandler {
/**
* @description delete executivePosition
* @param {DeleteExecutivePositionCommand} deleteExecutivePosition
* @param DeleteExecutivePositionCommand
* @returns {Promise<void>}
*/
static async delete(deleteExecutivePosition: DeleteExecutivePositionCommand): Promise<void> {
static async delete(deletExecutivePosition: DeleteExecutivePositionCommand): Promise<void> {
return await dataSource
.createQueryBuilder()
.delete()
.from(executivePosition)
.where("id = :id", { id: deleteExecutivePosition.id })
.where("id = :id", { id: deletExecutivePosition.id })
.execute()
.then(() => {})
.catch((err) => {
throw new InternalException(
`Failed deleting executivePosition${
err.code.includes("ER_ROW_IS_REFERENCED") ? " due to referenced data" : ""
}`,
err
);
throw new InternalException("Failed deleting executivePosition", err);
});
}
}

View file

@ -1,7 +1,7 @@
import { dataSource } from "../../../data-source";
import { invite } from "../../../entity/user/invite";
import InternalException from "../../../exceptions/internalException";
import { StringHelper } from "../../../helpers/stringHelper";
import { dataSource } from "../data-source";
import { invite } from "../entity/invite";
import InternalException from "../exceptions/internalException";
import { StringHelper } from "../helpers/stringHelper";
import { CreateInviteCommand, DeleteInviteCommand } from "./inviteCommand";
export default abstract class InviteCommandHandler {
@ -37,7 +37,7 @@ export default abstract class InviteCommandHandler {
/**
* @description delete invite by mail and token
* @param DeleteInviteCommand
* @param DeleteRefreshCommand
* @returns {Promise<any>}
*/
static async deleteByTokenAndMail(deleteInvite: DeleteInviteCommand): Promise<any> {
@ -53,22 +53,4 @@ export default abstract class InviteCommandHandler {
throw new InternalException("failed invite removal", err);
});
}
/**
* @description delete invite by mail
* @param DeleteByMailInviteCommand
* @returns {Promise<any>}
*/
static async deleteByMail(mail: string): Promise<any> {
return await dataSource
.createQueryBuilder()
.delete()
.from(invite)
.where("invite.mail = :mail", { mail })
.execute()
.then((res) => {})
.catch((err) => {
throw new InternalException("failed invite removal", err);
});
}
}

View file

@ -1,12 +1,14 @@
import { dataSource } from "../../../data-source";
import { memberAwards } from "../../../entity/club/member/memberAwards";
import InternalException from "../../../exceptions/internalException";
import { dataSource } from "../data-source";
import { award } from "../entity/award";
import { memberAwards } from "../entity/memberAwards";
import { user } from "../entity/user";
import InternalException from "../exceptions/internalException";
import { CreateMemberAwardCommand, DeleteMemberAwardCommand, UpdateMemberAwardCommand } from "./memberAwardCommand";
export default abstract class MemberAwardCommandHandler {
/**
* @description create memberAward
* @param {CreateMemberAwardCommand} createMemberAward
* @param CreateMemberAwardCommand
* @returns {Promise<number>}
*/
static async create(createMemberAward: CreateMemberAwardCommand): Promise<number> {
@ -18,8 +20,16 @@ export default abstract class MemberAwardCommandHandler {
given: createMemberAward.given,
note: createMemberAward.note,
date: createMemberAward.date,
memberId: createMemberAward.memberId,
awardId: createMemberAward.awardId,
member: await dataSource
.getRepository(user)
.createQueryBuilder("user")
.where("id = :id", { id: createMemberAward.memberId })
.getOneOrFail(),
award: await dataSource
.getRepository(award)
.createQueryBuilder("award")
.where("id = :id", { id: createMemberAward.awardId })
.getOneOrFail(),
})
.execute()
.then((result) => {
@ -32,7 +42,7 @@ export default abstract class MemberAwardCommandHandler {
/**
* @description update memberAward
* @param {UpdateMemberAwardCommand} updateMemberAward
* @param UpdateMemberAwardCommand
* @returns {Promise<void>}
*/
static async update(updateMemberAward: UpdateMemberAwardCommand): Promise<void> {
@ -43,7 +53,11 @@ export default abstract class MemberAwardCommandHandler {
given: updateMemberAward.given,
note: updateMemberAward.note,
date: updateMemberAward.date,
award: updateMemberAward.awardId,
award: await dataSource
.getRepository(award)
.createQueryBuilder("award")
.where("id = :id", { id: updateMemberAward.awardId })
.getOneOrFail(),
})
.where("id = :id", { id: updateMemberAward.id })
.andWhere("memberId = :memberId", { memberId: updateMemberAward.memberId })
@ -56,16 +70,16 @@ export default abstract class MemberAwardCommandHandler {
/**
* @description delete memberAward
* @param {DeleteMemberAwardCommand} deleteMemberAward
* @param DeleteMemberAwardCommand
* @returns {Promise<void>}
*/
static async delete(deleteMemberAward: DeleteMemberAwardCommand): Promise<void> {
static async delete(deletMemberAward: DeleteMemberAwardCommand): Promise<void> {
return await dataSource
.createQueryBuilder()
.delete()
.from(memberAwards)
.where("id = :id", { id: deleteMemberAward.id })
.andWhere("memberId = :memberId", { memberId: deleteMemberAward.memberId })
.where("id = :id", { id: deletMemberAward.id })
.andWhere("memberId = :memberId", { memberId: deletMemberAward.memberId })
.execute()
.then(() => {})
.catch((err) => {

View file

@ -1,4 +1,4 @@
import { Salutation } from "../../../enums/salutation";
import { Salutation } from "../enums/salutation";
export interface CreateMemberCommand {
salutation: Salutation;
@ -6,7 +6,6 @@ export interface CreateMemberCommand {
lastname: string;
nameaffix: string;
birthdate: Date;
internalId?: string;
}
export interface UpdateMemberCommand {
@ -16,7 +15,6 @@ export interface UpdateMemberCommand {
lastname: string;
nameaffix: string;
birthdate: Date;
internalId?: string;
}
export interface UpdateMemberNewsletterCommand {

View file

@ -1,7 +1,8 @@
import { dataSource } from "../../../data-source";
import { communication } from "../../../entity/club/member/communication";
import { member } from "../../../entity/club/member/member";
import InternalException from "../../../exceptions/internalException";
import { dataSource } from "../data-source";
import { communication } from "../entity/communication";
import { member } from "../entity/member";
import InternalException from "../exceptions/internalException";
import CommunicationService from "../service/communicationService";
import {
CreateMemberCommand,
DeleteMemberCommand,
@ -12,7 +13,7 @@ import {
export default abstract class MemberCommandHandler {
/**
* @description create member
* @param {CreateMemberCommand} createMember
* @param CreateMemberCommand
* @returns {Promise<number>}
*/
static async create(createMember: CreateMemberCommand): Promise<number> {
@ -26,7 +27,6 @@ export default abstract class MemberCommandHandler {
lastname: createMember.lastname,
nameaffix: createMember.nameaffix,
birthdate: createMember.birthdate,
internalId: createMember.internalId,
})
.execute()
.then((result) => {
@ -39,10 +39,11 @@ export default abstract class MemberCommandHandler {
/**
* @description update member
* @param {UpdateMemberCommand} updateMember
* @param UpdateMemberCommand
* @returns {Promise<void>}
*/
static async update(updateMember: UpdateMemberCommand): Promise<void> {
console.log(updateMember);
return await dataSource
.createQueryBuilder()
.update(member)
@ -52,7 +53,6 @@ export default abstract class MemberCommandHandler {
lastname: updateMember.lastname,
nameaffix: updateMember.nameaffix,
birthdate: updateMember.birthdate,
internalId: updateMember.internalId,
})
.where("id = :id", { id: updateMember.id })
.execute()
@ -64,10 +64,11 @@ export default abstract class MemberCommandHandler {
/**
* @description update member newsletter
* @param {UpdateMemberCommand} updateMember
* @param UpdateMemberCommand
* @returns {Promise<void>}
*/
static async updateNewsletter(updateMember: UpdateMemberNewsletterCommand): Promise<void> {
console.log(updateMember);
return await dataSource
.createQueryBuilder()
.update(member)
@ -87,29 +88,9 @@ export default abstract class MemberCommandHandler {
});
}
/**
* @description update member newsletter to unset
* @param {number} memberId
* @returns {Promise<void>}
*/
static async unsetNewsletter(memberId: number): Promise<void> {
return await dataSource
.createQueryBuilder()
.update(member)
.set({
sendNewsletter: null,
})
.where("id = :id", { id: memberId })
.execute()
.then(() => {})
.catch((err) => {
throw new InternalException("Failed updating member", err);
});
}
/**
* @description delete member
* @param {DeleteMemberCommand} deleteMember
* @param DeleteMemberCommand
* @returns {Promise<void>}
*/
static async delete(deleteMember: DeleteMemberCommand): Promise<void> {

View file

@ -1,6 +1,8 @@
import { dataSource } from "../../../data-source";
import { memberExecutivePositions } from "../../../entity/club/member/memberExecutivePositions";
import InternalException from "../../../exceptions/internalException";
import { dataSource } from "../data-source";
import { executivePosition } from "../entity/executivePosition";
import { memberExecutivePositions } from "../entity/memberExecutivePositions";
import { user } from "../entity/user";
import InternalException from "../exceptions/internalException";
import {
CreateMemberExecutivePositionCommand,
DeleteMemberExecutivePositionCommand,
@ -10,7 +12,7 @@ import {
export default abstract class MemberExecutivePositionCommandHandler {
/**
* @description create memberExecutivePosition
* @param {CreateMemberExecutivePositionCommand} createMemberExecutivePosition
* @param CreateMemberExecutivePositionCommand
* @returns {Promise<number>}
*/
static async create(createMemberExecutivePosition: CreateMemberExecutivePositionCommand): Promise<number> {
@ -22,8 +24,16 @@ export default abstract class MemberExecutivePositionCommandHandler {
note: createMemberExecutivePosition.note,
start: createMemberExecutivePosition.start,
end: createMemberExecutivePosition.end,
memberId: createMemberExecutivePosition.memberId,
executivePositionId: createMemberExecutivePosition.executivePositionId,
member: await dataSource
.getRepository(user)
.createQueryBuilder("user")
.where("id = :id", { id: createMemberExecutivePosition.memberId })
.getOneOrFail(),
executivePosition: await dataSource
.getRepository(executivePosition)
.createQueryBuilder("executivePosition")
.where("id = :id", { id: createMemberExecutivePosition.executivePositionId })
.getOneOrFail(),
})
.execute()
.then((result) => {
@ -36,7 +46,7 @@ export default abstract class MemberExecutivePositionCommandHandler {
/**
* @description update memberExecutivePosition
* @param {UpdateMemberExecutivePositionCommand} updateMemberExecutivePosition
* @param UpdateMemberExecutivePositionCommand
* @returns {Promise<void>}
*/
static async update(updateMemberExecutivePosition: UpdateMemberExecutivePositionCommand): Promise<void> {
@ -47,7 +57,11 @@ export default abstract class MemberExecutivePositionCommandHandler {
note: updateMemberExecutivePosition.note,
start: updateMemberExecutivePosition.start,
end: updateMemberExecutivePosition.end,
executivePositionId: updateMemberExecutivePosition.executivePositionId,
executivePosition: await dataSource
.getRepository(executivePosition)
.createQueryBuilder("executivePosition")
.where("id = :id", { id: updateMemberExecutivePosition.executivePositionId })
.getOneOrFail(),
})
.where("id = :id", { id: updateMemberExecutivePosition.id })
.andWhere("memberId = :memberId", { memberId: updateMemberExecutivePosition.memberId })
@ -60,16 +74,16 @@ export default abstract class MemberExecutivePositionCommandHandler {
/**
* @description delete memberExecutivePosition
* @param {DeleteMemberExecutivePositionCommand} deleteMemberExecutivePosition
* @param DeleteMemberExecutivePositionCommand
* @returns {Promise<void>}
*/
static async delete(deleteMemberExecutivePosition: DeleteMemberExecutivePositionCommand): Promise<void> {
static async delete(deletMemberExecutivePosition: DeleteMemberExecutivePositionCommand): Promise<void> {
return await dataSource
.createQueryBuilder()
.delete()
.from(memberExecutivePositions)
.where("id = :id", { id: deleteMemberExecutivePosition.id })
.andWhere("memberId = :memberId", { memberId: deleteMemberExecutivePosition.memberId })
.where("id = :id", { id: deletMemberExecutivePosition.id })
.andWhere("memberId = :memberId", { memberId: deletMemberExecutivePosition.memberId })
.execute()
.then(() => {})
.catch((err) => {

View file

@ -1,6 +1,8 @@
import { dataSource } from "../../../data-source";
import { memberQualifications } from "../../../entity/club/member/memberQualifications";
import InternalException from "../../../exceptions/internalException";
import { dataSource } from "../data-source";
import { qualification } from "../entity/qualification";
import { memberQualifications } from "../entity/memberQualifications";
import { user } from "../entity/user";
import InternalException from "../exceptions/internalException";
import {
CreateMemberQualificationCommand,
DeleteMemberQualificationCommand,
@ -10,7 +12,7 @@ import {
export default abstract class MemberQualificationCommandHandler {
/**
* @description create memberQualification
* @param {CreateMemberQualificationCommand} createMemberQualification
* @param CreateMemberQualificationCommand
* @returns {Promise<number>}
*/
static async create(createMemberQualification: CreateMemberQualificationCommand): Promise<number> {
@ -21,8 +23,16 @@ export default abstract class MemberQualificationCommandHandler {
.values({
note: createMemberQualification.note,
start: createMemberQualification.start,
memberId: createMemberQualification.memberId,
qualificationId: createMemberQualification.qualificationId,
member: await dataSource
.getRepository(user)
.createQueryBuilder("user")
.where("id = :id", { id: createMemberQualification.memberId })
.getOneOrFail(),
qualification: await dataSource
.getRepository(qualification)
.createQueryBuilder("qualification")
.where("id = :id", { id: createMemberQualification.qualificationId })
.getOneOrFail(),
})
.execute()
.then((result) => {
@ -35,7 +45,7 @@ export default abstract class MemberQualificationCommandHandler {
/**
* @description update memberQualification
* @param {UpdateMemberQualificationCommand} updateMemberQualification
* @param UpdateMemberQualificationCommand
* @returns {Promise<void>}
*/
static async update(updateMemberQualification: UpdateMemberQualificationCommand): Promise<void> {
@ -47,7 +57,11 @@ export default abstract class MemberQualificationCommandHandler {
start: updateMemberQualification.start,
end: updateMemberQualification.end,
terminationReason: updateMemberQualification.terminationReason,
qualificationId: updateMemberQualification.qualificationId,
qualification: await dataSource
.getRepository(qualification)
.createQueryBuilder("qualification")
.where("id = :id", { id: updateMemberQualification.qualificationId })
.getOneOrFail(),
})
.where("id = :id", { id: updateMemberQualification.id })
.andWhere("memberId = :memberId", { memberId: updateMemberQualification.memberId })
@ -60,16 +74,16 @@ export default abstract class MemberQualificationCommandHandler {
/**
* @description delete memberQualification
* @param {DeleteMemberQualificationCommand} deleteMemberQualification
* @param DeleteMemberQualificationCommand
* @returns {Promise<void>}
*/
static async delete(deleteMemberQualification: DeleteMemberQualificationCommand): Promise<void> {
static async delete(deletMemberQualification: DeleteMemberQualificationCommand): Promise<void> {
return await dataSource
.createQueryBuilder()
.delete()
.from(memberQualifications)
.where("id = :id", { id: deleteMemberQualification.id })
.andWhere("memberId = :memberId", { memberId: deleteMemberQualification.memberId })
.where("id = :id", { id: deletMemberQualification.id })
.andWhere("memberId = :memberId", { memberId: deletMemberQualification.memberId })
.execute()
.then(() => {})
.catch((err) => {

View file

@ -1,4 +1,5 @@
export interface CreateMembershipCommand {
internalId?: string;
start: Date;
memberId: number;
statusId: number;
@ -6,6 +7,7 @@ export interface CreateMembershipCommand {
export interface UpdateMembershipCommand {
id: number;
internalId?: string;
start: Date;
end?: Date;
terminationReason?: string;

View file

@ -1,16 +1,18 @@
import { dataSource } from "../../../data-source";
import { membership } from "../../../entity/club/member/membership";
import InternalException from "../../../exceptions/internalException";
import { dataSource } from "../data-source";
import { membership } from "../entity/membership";
import { membershipStatus } from "../entity/membershipStatus";
import { user } from "../entity/user";
import InternalException from "../exceptions/internalException";
import { CreateMembershipCommand, DeleteMembershipCommand, UpdateMembershipCommand } from "./membershipCommand";
export default abstract class MembershipCommandHandler {
/**
* @description create membership
* @param {CreateMembershipCommand} createMembership
* @param CreateMembershipCommand
* @returns {Promise<number>}
*/
static async create(createMembership: CreateMembershipCommand): Promise<number> {
let insertId = -1;
let insertid = -1;
return await dataSource
.transaction(async (manager) => {
await manager
@ -18,29 +20,37 @@ export default abstract class MembershipCommandHandler {
.insert()
.into(membership)
.values({
internalId: createMembership.internalId,
start: createMembership.start,
memberId: createMembership.memberId,
statusId: createMembership.statusId,
member: await dataSource
.getRepository(user)
.createQueryBuilder("user")
.where("id = :id", { id: createMembership.memberId })
.getOneOrFail(),
status: await dataSource
.getRepository(membershipStatus)
.createQueryBuilder("membershipStatus")
.where("id = :id", { id: createMembership.statusId })
.getOneOrFail(),
})
.execute()
.then((result) => {
insertId = result.identifiers[0].id;
insertid = result.identifiers[0].id;
});
await manager
.createQueryBuilder()
.update(membership)
.set({
end: new Date(new Date(createMembership.start).setDate(new Date(createMembership.start).getDate() - 1)),
terminationReason: "beendet durch neuen Eintrag.",
end: createMembership.start,
})
.where("end IS NULL")
.andWhere("memberId = :memberId", { memberId: createMembership.memberId })
.andWhere("id <> :id", { id: insertId })
.andWhere("id <> :id", { id: insertid })
.execute();
})
.then(() => {
return insertId;
return insertid;
})
.catch((err) => {
throw new InternalException("Failed creating membership", err);
@ -49,7 +59,7 @@ export default abstract class MembershipCommandHandler {
/**
* @description update membership
* @param {UpdateMembershipCommand} updateMembership
* @param UpdateMembershipCommand
* @returns {Promise<void>}
*/
static async update(updateMembership: UpdateMembershipCommand): Promise<void> {
@ -57,10 +67,15 @@ export default abstract class MembershipCommandHandler {
.createQueryBuilder()
.update(membership)
.set({
internalId: updateMembership.internalId,
start: updateMembership.start,
end: updateMembership.end,
terminationReason: updateMembership.terminationReason,
statusId: updateMembership.statusId,
status: await dataSource
.getRepository(membershipStatus)
.createQueryBuilder("membershipStatus")
.where("id = :id", { id: updateMembership.statusId })
.getOneOrFail(),
})
.where("id = :id", { id: updateMembership.id })
.andWhere("memberId = :memberId", { memberId: updateMembership.memberId })
@ -73,16 +88,16 @@ export default abstract class MembershipCommandHandler {
/**
* @description delete membership
* @param {DeleteMembershipCommand} deleteMembership
* @param DeleteMembershipCommand
* @returns {Promise<void>}
*/
static async delete(deleteMembership: DeleteMembershipCommand): Promise<void> {
static async delete(deletMembership: DeleteMembershipCommand): Promise<void> {
return await dataSource
.createQueryBuilder()
.delete()
.from(membership)
.where("id = :id", { id: deleteMembership.id })
.andWhere("memberId = :memberId", { memberId: deleteMembership.memberId })
.where("id = :id", { id: deletMembership.id })
.andWhere("memberId = :memberId", { memberId: deletMembership.memberId })
.execute()
.then(() => {})
.catch((err) => {

View file

@ -1,6 +1,6 @@
import { dataSource } from "../../../data-source";
import { membershipStatus } from "../../../entity/settings/membershipStatus";
import InternalException from "../../../exceptions/internalException";
import { dataSource } from "../data-source";
import { membershipStatus } from "../entity/membershipStatus";
import InternalException from "../exceptions/internalException";
import {
CreateMembershipStatusCommand,
DeleteMembershipStatusCommand,
@ -10,7 +10,7 @@ import {
export default abstract class MembershipStatusCommandHandler {
/**
* @description create membershipStatus
* @param {CreateMembershipStatusCommand} createMembershipStatus
* @param CreateMembershipStatusCommand
* @returns {Promise<number>}
*/
static async create(createMembershipStatus: CreateMembershipStatusCommand): Promise<number> {
@ -32,7 +32,7 @@ export default abstract class MembershipStatusCommandHandler {
/**
* @description update membershipStatus
* @param {UpdateMembershipStatusCommand} updateMembershipStatus
* @param UpdateMembershipStatusCommand
* @returns {Promise<void>}
*/
static async update(updateMembershipStatus: UpdateMembershipStatusCommand): Promise<void> {
@ -52,24 +52,19 @@ export default abstract class MembershipStatusCommandHandler {
/**
* @description delete membershipStatus
* @param {DeleteMembershipStatusCommand} deleteMembershipStatus
* @param DeleteMembershipStatusCommand
* @returns {Promise<void>}
*/
static async delete(deleteMembershipStatus: DeleteMembershipStatusCommand): Promise<void> {
static async delete(deletMembershipStatus: DeleteMembershipStatusCommand): Promise<void> {
return await dataSource
.createQueryBuilder()
.delete()
.from(membershipStatus)
.where("id = :id", { id: deleteMembershipStatus.id })
.where("id = :id", { id: deletMembershipStatus.id })
.execute()
.then(() => {})
.catch((err) => {
throw new InternalException(
`Failed deleting membershipStatus${
err.code.includes("ER_ROW_IS_REFERENCED") ? " due to referenced data" : ""
}`,
err
);
throw new InternalException("Failed deleting membershipStatus", err);
});
}
}

View file

@ -1,6 +1,6 @@
import { dataSource } from "../../../data-source";
import { qualification } from "../../../entity/settings/qualification";
import InternalException from "../../../exceptions/internalException";
import { dataSource } from "../data-source";
import { qualification } from "../entity/qualification";
import InternalException from "../exceptions/internalException";
import {
CreateQualificationCommand,
DeleteQualificationCommand,
@ -10,7 +10,7 @@ import {
export default abstract class QualificationCommandHandler {
/**
* @description create qualification
* @param {CreateQualificationCommand} createQualification
* @param CreateQualificationCommand
* @returns {Promise<number>}
*/
static async create(createQualification: CreateQualificationCommand): Promise<number> {
@ -33,7 +33,7 @@ export default abstract class QualificationCommandHandler {
/**
* @description update qualification
* @param {UpdateQualificationCommand} updateQualification
* @param UpdateQualificationCommand
* @returns {Promise<void>}
*/
static async update(updateQualification: UpdateQualificationCommand): Promise<void> {
@ -54,22 +54,19 @@ export default abstract class QualificationCommandHandler {
/**
* @description delete qualification
* @param {DeleteQualificationCommand} deleteQualification
* @param DeleteQualificationCommand
* @returns {Promise<void>}
*/
static async delete(deleteQualification: DeleteQualificationCommand): Promise<void> {
static async delete(deletQualification: DeleteQualificationCommand): Promise<void> {
return await dataSource
.createQueryBuilder()
.delete()
.from(qualification)
.where("id = :id", { id: deleteQualification.id })
.where("id = :id", { id: deletQualification.id })
.execute()
.then(() => {})
.catch((err) => {
throw new InternalException(
`Failed deleting qualification${err.code.includes("ER_ROW_IS_REFERENCED") ? " due to referenced data" : ""}`,
err
);
throw new InternalException("Failed deleting qualification", err);
});
}
}

View file

@ -1,6 +1,5 @@
export interface CreateRefreshCommand {
userId: number;
isFromPwa?: boolean;
}
export interface DeleteRefreshCommand {

View file

@ -1,19 +1,25 @@
import { dataSource } from "../data-source";
import { refresh } from "../entity/refresh";
import { PWA_REFRESH_EXPIRATION, REFRESH_EXPIRATION } from "../env.defaults";
import { REFRESH_EXPIRATION } from "../env.defaults";
import InternalException from "../exceptions/internalException";
import { JWTHelper } from "../helpers/jwtHelper";
import { StringHelper } from "../helpers/stringHelper";
import UserService from "../service/user/userService";
import UserService from "../service/userService";
import { JWTRefresh } from "../type/jwtTypes";
import { CreateRefreshCommand, DeleteRefreshCommand } from "./refreshCommand";
import ms from "ms";
export default abstract class RefreshCommandHandler {
/**
* @description create and save refreshToken to user
* @param {CreateRefreshCommand} createRefresh
* @param CreateRefreshCommand
* @returns {Promise<string>}
*/
static async create(createRefresh: CreateRefreshCommand): Promise<string> {
// let createRefreshToken: JWTRefresh = {
// userId: createRefresh.userId,
// };
// const refreshToken = await JWTHelper.create(createRefreshToken);
const refreshToken = StringHelper.random(32);
return await dataSource
@ -23,9 +29,7 @@ export default abstract class RefreshCommandHandler {
.values({
token: refreshToken,
user: await UserService.getById(createRefresh.userId),
expiry: createRefresh.isFromPwa
? new Date(Date.now() + ms(PWA_REFRESH_EXPIRATION))
: new Date(Date.now() + ms(REFRESH_EXPIRATION)),
expiry: new Date(Date.now() + ms(REFRESH_EXPIRATION)),
})
.execute()
.then((result) => {
@ -38,7 +42,7 @@ export default abstract class RefreshCommandHandler {
/**
* @description delete refresh by user and token
* @param {DeleteRefreshCommand} deleteRefresh
* @param DeleteRefreshCommand
* @returns {Promise<any>}
*/
static async deleteByToken(deleteRefresh: DeleteRefreshCommand): Promise<any> {

View file

@ -1,10 +0,0 @@
export interface CreateResetCommand {
mail: string;
username: string;
secret: string;
}
export interface DeleteResetCommand {
token: string;
mail: string;
}

View file

@ -1,54 +0,0 @@
import { dataSource } from "../data-source";
import { reset } from "../entity/reset";
import InternalException from "../exceptions/internalException";
import { StringHelper } from "../helpers/stringHelper";
import { CreateResetCommand, DeleteResetCommand } from "./resetCommand";
export default abstract class ResetCommandHandler {
/**
* @description create user
* @param {CreateResetCommand} createReset
* @returns {Promise<string>}
*/
static async create(createReset: CreateResetCommand): Promise<string> {
const token = StringHelper.random(32);
return await dataSource
.createQueryBuilder()
.insert()
.into(reset)
.values({
token: token,
mail: createReset.mail,
username: createReset.username,
secret: createReset.secret,
})
.orUpdate(["token", "secret"], ["mail"])
.execute()
.then((result) => {
return token;
})
.catch((err) => {
throw new InternalException("Failed saving reset", err);
});
}
/**
* @description delete reset by mail and token
* @param {DeleteRefreshCommand} deleteReset
* @returns {Promise<any>}
*/
static async deleteByTokenAndMail(deleteReset: DeleteResetCommand): Promise<any> {
return await dataSource
.createQueryBuilder()
.delete()
.from(reset)
.where("reset.token = :token", { token: deleteReset.token })
.andWhere("reset.mail = :mail", { mail: deleteReset.mail })
.execute()
.then((res) => {})
.catch((err) => {
throw new InternalException("failed reset removal", err);
});
}
}

View file

@ -1,12 +1,12 @@
import { dataSource } from "../../../data-source";
import { role } from "../../../entity/user/role";
import InternalException from "../../../exceptions/internalException";
import { dataSource } from "../data-source";
import { role } from "../entity/role";
import InternalException from "../exceptions/internalException";
import { CreateRoleCommand, DeleteRoleCommand, UpdateRoleCommand } from "./roleCommand";
export default abstract class RoleCommandHandler {
/**
* @description create role
* @param {CreateRoleCommand} createRole
* @param CreateRoleCommand
* @returns {Promise<number>}
*/
static async create(createRole: CreateRoleCommand): Promise<number> {
@ -28,7 +28,7 @@ export default abstract class RoleCommandHandler {
/**
* @description update role
* @param {UpdateRoleCommand} updateRole
* @param UpdateRoleCommand
* @returns {Promise<void>}
*/
static async update(updateRole: UpdateRoleCommand): Promise<void> {
@ -48,7 +48,7 @@ export default abstract class RoleCommandHandler {
/**
* @description delete role
* @param {DeleteRoleCommand} deleteRole
* @param DeleteRoleCommand
* @returns {Promise<void>}
*/
static async delete(deleteRole: DeleteRoleCommand): Promise<void> {

View file

@ -1,4 +1,4 @@
import { PermissionString } from "../../../type/permissionTypes";
import { PermissionString } from "../type/permissionTypes";
export interface CreateRolePermissionCommand {
permission: PermissionString;

View file

@ -1,21 +1,22 @@
import { DeleteResult, EntityManager, InsertResult } from "typeorm";
import { dataSource } from "../../../data-source";
import { rolePermission } from "../../../entity/user/role_permission";
import InternalException from "../../../exceptions/internalException";
import RoleService from "../../../service/user/roleService";
import { dataSource } from "../data-source";
import { rolePermission } from "../entity/role_permission";
import InternalException from "../exceptions/internalException";
import RoleService from "../service/roleService";
import {
CreateRolePermissionCommand,
DeleteRolePermissionCommand,
UpdateRolePermissionsCommand,
} from "./rolePermissionCommand";
import PermissionHelper from "../../../helpers/permissionHelper";
import RolePermissionService from "../../../service/user/rolePermissionService";
import { PermissionString } from "../../../type/permissionTypes";
import PermissionHelper from "../helpers/permissionHelper";
import RolePermissionService from "../service/rolePermissionService";
import { role } from "../entity/role";
import { PermissionString } from "../type/permissionTypes";
export default abstract class RolePermissionCommandHandler {
/**
* @description update role permissions
* @param {UpdateRolePermissionsCommand} updateRolePermissions
* @param UpdateRolePermissionsCommand
* @returns {Promise<void>}
*/
static async updatePermissions(updateRolePermissions: UpdateRolePermissionsCommand): Promise<void> {
@ -74,7 +75,7 @@ export default abstract class RolePermissionCommandHandler {
/**
* @description grant permission to user
* @param {CreateRolePermissionCommand} createPermission
* @param CreateRolePermissionCommand
* @returns {Promise<number>}
*/
static async create(createPermission: CreateRolePermissionCommand): Promise<number> {
@ -97,7 +98,7 @@ export default abstract class RolePermissionCommandHandler {
/**
* @description remove permission from role
* @param {DeleteRolePermissionCommand} deletePermission
* @param DeleteRolePermissionCommand
* @returns {Promise<any>}
*/
static async delete(deletePermission: DeleteRolePermissionCommand): Promise<any> {
@ -108,7 +109,7 @@ export default abstract class RolePermissionCommandHandler {
.where("roleId = :id", { id: deletePermission.roleId })
.andWhere("permission = :permission", { permission: deletePermission.permission })
.execute()
.then(() => {})
.then((res) => {})
.catch((err) => {
throw new InternalException("failed role permission removal", err);
});

View file

@ -1,18 +0,0 @@
export interface CreateCalendarTypeCommand {
type: string;
nscdr: boolean;
color: string;
passphrase?: string;
}
export interface UpdateCalendarTypeCommand {
id: number;
type: string;
nscdr: boolean;
color: string;
passphrase?: string;
}
export interface DeleteCalendarTypeCommand {
id: number;
}

View file

@ -1,75 +0,0 @@
import { dataSource } from "../../../data-source";
import { calendarType } from "../../../entity/settings/calendarType";
import InternalException from "../../../exceptions/internalException";
import { CreateCalendarTypeCommand, DeleteCalendarTypeCommand, UpdateCalendarTypeCommand } from "./calendarTypeCommand";
export default abstract class CalendarTypeCommandHandler {
/**
* @description create calendarType
* @param {CreateCalendarTypeCommand} createCalendarType
* @returns {Promise<number>}
*/
static async create(createCalendarType: CreateCalendarTypeCommand): Promise<number> {
return await dataSource
.createQueryBuilder()
.insert()
.into(calendarType)
.values({
type: createCalendarType.type,
nscdr: createCalendarType.nscdr,
color: createCalendarType.color,
passphrase: createCalendarType.nscdr ? null : createCalendarType.passphrase,
})
.execute()
.then((result) => {
return result.identifiers[0].id;
})
.catch((err) => {
throw new InternalException("Failed creating calendarType", err);
});
}
/**
* @description update calendarType
* @param {UpdateCalendarTypeCommand} updateCalendarType
* @returns {Promise<void>}
*/
static async update(updateCalendarType: UpdateCalendarTypeCommand): Promise<void> {
return await dataSource
.createQueryBuilder()
.update(calendarType)
.set({
type: updateCalendarType.type,
nscdr: updateCalendarType.nscdr,
color: updateCalendarType.color,
passphrase: updateCalendarType.nscdr ? null : updateCalendarType.passphrase,
})
.where("id = :id", { id: updateCalendarType.id })
.execute()
.then(() => {})
.catch((err) => {
throw new InternalException("Failed updating award", err);
});
}
/**
* @description delete calendarType
* @param {DeleteCalendarTypeCommand} deleteCalendarType
* @returns {Promise<void>}
*/
static async delete(deleteCalendarType: DeleteCalendarTypeCommand): Promise<void> {
return await dataSource
.createQueryBuilder()
.delete()
.from(calendarType)
.where("id = :id", { id: deleteCalendarType.id })
.execute()
.then(() => {})
.catch((err) => {
throw new InternalException(
`Failed deleting calendarType${err.code.includes("ER_ROW_IS_REFERENCED") ? " due to referenced data" : ""}`,
err
);
});
}
}

View file

@ -1,6 +0,0 @@
import { NewsletterConfigType } from "../../../enums/newsletterConfigType";
export interface SetNewsletterConfigCommand {
comTypeId: number;
config: NewsletterConfigType;
}

View file

@ -1,30 +0,0 @@
import { dataSource } from "../../../data-source";
import { newsletterConfig } from "../../../entity/settings/newsletterConfig";
import InternalException from "../../../exceptions/internalException";
import { SetNewsletterConfigCommand } from "./newsletterConfigCommand";
export default abstract class NewsletterConfigCommandHandler {
/**
* @description set newsletterConfig
* @param {SetNewsletterConfigCommand} setNewsletterConfig
* @returns {Promise<number>}
*/
static async set(setNewsletterConfig: SetNewsletterConfigCommand): Promise<number> {
return await dataSource
.createQueryBuilder()
.insert()
.into(newsletterConfig)
.values({
comTypeId: setNewsletterConfig.comTypeId,
config: setNewsletterConfig.config,
})
.orUpdate(["config"], "comTypeId")
.execute()
.then((result) => {
return result.identifiers[0].id;
})
.catch((err) => {
throw new InternalException("Failed setting newsletterConfig", err);
});
}
}

View file

@ -1,15 +0,0 @@
import { DynamicQueryStructure } from "../../../type/dynamicQueries";
export interface CreateQueryStoreCommand {
title: string;
query: string | DynamicQueryStructure;
}
export interface UpdateQueryStoreCommand {
id: number;
query: string | DynamicQueryStructure;
}
export interface DeleteQueryStoreCommand {
id: number;
}

View file

@ -1,72 +0,0 @@
import { dataSource } from "../../../data-source";
import { query } from "../../../entity/settings/query";
import InternalException from "../../../exceptions/internalException";
import { CreateQueryStoreCommand, DeleteQueryStoreCommand, UpdateQueryStoreCommand } from "./queryStoreCommand";
export default abstract class QueryStoreCommandHandler {
/**
* @description create queryStore
* @param {CreateQueryStoreCommand} createQueryStore
* @returns {Promise<number>}
*/
static async create(createQueryStore: CreateQueryStoreCommand): Promise<number> {
return await dataSource
.createQueryBuilder()
.insert()
.into(query)
.values({
title: createQueryStore.title,
query:
typeof createQueryStore.query == "string" ? createQueryStore.query : JSON.stringify(createQueryStore.query),
})
.execute()
.then((result) => {
return result.identifiers[0].id;
})
.catch((err) => {
throw new InternalException("Failed creating queryStore", err);
});
}
/**
* @description update queryStore
* @param {UpdateQueryStoreCommand} updateQueryStore
* @returns {Promise<void>}
*/
static async update(updateQueryStore: UpdateQueryStoreCommand): Promise<void> {
return await dataSource
.createQueryBuilder()
.update(query)
.set({
query:
typeof updateQueryStore.query == "string" ? updateQueryStore.query : JSON.stringify(updateQueryStore.query),
})
.where("id = :id", { id: updateQueryStore.id })
.execute()
.then(() => {})
.catch((err) => {
throw new InternalException("Failed updating queryStore", err);
});
}
/**
* @description delete queryStore
* @param {DeleteQueryStoreCommand} deleteQueryStore
* @returns {Promise<void>}
*/
static async delete(deleteQueryStore: DeleteQueryStoreCommand): Promise<void> {
return await dataSource
.createQueryBuilder()
.delete()
.from(query)
.where("id = :id", { id: deleteQueryStore.id })
.execute()
.then(() => {})
.catch((err) => {
throw new InternalException(
`Failed deleting queryStore${err.code.includes("ER_ROW_IS_REFERENCED") ? " due to referenced data" : ""}`,
err
);
});
}
}

View file

@ -1,16 +0,0 @@
export interface CreateTemplateCommand {
template: string;
description: string | null;
}
export interface UpdateTemplateCommand {
id: number;
template: string;
description: string | null;
design: object;
html: string;
}
export interface DeleteTemplateCommand {
id: number;
}

View file

@ -1,73 +0,0 @@
import { dataSource } from "../../../data-source";
import { template } from "../../../entity/settings/template";
import InternalException from "../../../exceptions/internalException";
import { CreateTemplateCommand, DeleteTemplateCommand, UpdateTemplateCommand } from "./templateCommand";
export default abstract class TemplateCommandHandler {
/**
* @description create template
* @param {CreateTemplateCommand} createTemplate
* @returns {Promise<number>}
*/
static async create(createTemplate: CreateTemplateCommand): Promise<number> {
return await dataSource
.createQueryBuilder()
.insert()
.into(template)
.values({
template: createTemplate.template,
description: createTemplate.description,
})
.execute()
.then((result) => {
return result.identifiers[0].id;
})
.catch((err) => {
throw new InternalException("Failed creating template", err);
});
}
/**
* @description update template
* @param {UpdateTemplateCommand} updateTemplate
* @returns {Promise<void>}
*/
static async update(updateTemplate: UpdateTemplateCommand): Promise<void> {
return await dataSource
.createQueryBuilder()
.update(template)
.set({
template: updateTemplate.template,
description: updateTemplate.description,
design: updateTemplate.design,
html: updateTemplate.html,
})
.where("id = :id", { id: updateTemplate.id })
.execute()
.then(() => {})
.catch((err) => {
throw new InternalException("Failed updating template", err);
});
}
/**
* @description delete template
* @param {DeleteTemplateCommand} deleteTemplate
* @returns {Promise<void>}
*/
static async delete(deleteTemplate: DeleteTemplateCommand): Promise<void> {
return await dataSource
.createQueryBuilder()
.delete()
.from(template)
.where("id = :id", { id: deleteTemplate.id })
.execute()
.then(() => {})
.catch((err) => {
throw new InternalException(
`Failed deleting template${err.code.includes("ER_ROW_IS_REFERENCED") ? " due to referenced data" : ""}`,
err
);
});
}
}

View file

@ -1,8 +0,0 @@
export interface UpdateTemplateUsageCommand {
scope: string;
headerId: number | null;
bodyId: number | null;
footerId: number | null;
headerHeight: number | null;
footerHeight: number | null;
}

View file

@ -1,30 +0,0 @@
import { dataSource } from "../../../data-source";
import { templateUsage } from "../../../entity/settings/templateUsage";
import InternalException from "../../../exceptions/internalException";
import { UpdateTemplateUsageCommand } from "./templateUsageCommand";
export default abstract class TemplateUsageCommandHandler {
/**
* @description update templateUsage
* @param {UpdateTemplateUsageCommand} updateTemplateUsage
* @returns {Promise<void>}
*/
static async update(updateTemplateUsage: UpdateTemplateUsageCommand): Promise<void> {
return await dataSource
.createQueryBuilder()
.update(templateUsage)
.set({
headerId: updateTemplateUsage.headerId,
bodyId: updateTemplateUsage.bodyId,
footerId: updateTemplateUsage.footerId,
headerHeight: updateTemplateUsage.headerHeight,
footerHeight: updateTemplateUsage.footerHeight,
})
.where("scope = :scope", { scope: updateTemplateUsage.scope })
.execute()
.then(() => {})
.catch((err) => {
throw new InternalException("Failed updating templateUsage", err);
});
}
}

View file

@ -4,7 +4,6 @@ export interface CreateUserCommand {
firstname: string;
lastname: string;
secret: string;
isOwner: boolean;
}
export interface UpdateUserCommand {
@ -15,16 +14,6 @@ export interface UpdateUserCommand {
lastname: string;
}
export interface UpdateUserSecretCommand {
id: number;
secret: string;
}
export interface TransferUserOwnerCommand {
fromId: number;
toId: number;
}
export interface UpdateUserRolesCommand {
id: number;
roleIds: Array<number>;

View file

@ -1,21 +1,14 @@
import { EntityManager } from "typeorm";
import { dataSource } from "../../../data-source";
import { user } from "../../../entity/user/user";
import InternalException from "../../../exceptions/internalException";
import {
CreateUserCommand,
DeleteUserCommand,
TransferUserOwnerCommand,
UpdateUserCommand,
UpdateUserRolesCommand,
UpdateUserSecretCommand,
} from "./userCommand";
import UserService from "../../../service/user/userService";
import { dataSource } from "../data-source";
import { user } from "../entity/user";
import InternalException from "../exceptions/internalException";
import { CreateUserCommand, DeleteUserCommand, UpdateUserCommand, UpdateUserRolesCommand } from "./userCommand";
import UserService from "../service/userService";
export default abstract class UserCommandHandler {
/**
* @description create user
* @param {CreateUserCommand} createUser
* @param CreateUserCommand
* @returns {Promise<number>}
*/
static async create(createUser: CreateUserCommand): Promise<number> {
@ -29,7 +22,6 @@ export default abstract class UserCommandHandler {
firstname: createUser.firstname,
lastname: createUser.lastname,
secret: createUser.secret,
isOwner: createUser.isOwner,
})
.execute()
.then((result) => {
@ -42,7 +34,7 @@ export default abstract class UserCommandHandler {
/**
* @description update user
* @param {UpdateUserCommand} updateUser
* @param UpdateUserCommand
* @returns {Promise<void>}
*/
static async update(updateUser: UpdateUserCommand): Promise<void> {
@ -63,29 +55,9 @@ export default abstract class UserCommandHandler {
});
}
/**
* @description update user
* @param {UpdateUserSecretCommand} updateUser
* @returns {Promise<void>}
*/
static async updateSecret(updateUser: UpdateUserSecretCommand): Promise<void> {
return await dataSource
.createQueryBuilder()
.update(user)
.set({
secret: updateUser.secret,
})
.where("id = :id", { id: updateUser.id })
.execute()
.then(() => {})
.catch((err) => {
throw new InternalException("Failed updating user secret", err);
});
}
/**
* @description update user roles
* @param {UpdateUserRolesCommand} updateUserRoles
* @param UpdateUserRolesCommand
* @returns {Promise<void>}
*/
static async updateRoles(updateUserRoles: UpdateUserRolesCommand): Promise<void> {
@ -117,38 +89,6 @@ export default abstract class UserCommandHandler {
return await manager.createQueryBuilder().relation(user, "roles").of(userId).remove(roleId);
}
/**
* @description transfer ownership
* @param {TransferUserOwnerCommand} transferOwnership
* @returns {Promise<void>}
*/
static async transferOwnership(transferOwnership: TransferUserOwnerCommand): Promise<void> {
return await dataSource.manager
.transaction(async (manager) => {
await manager
.createQueryBuilder()
.update(user)
.set({
isOwner: false,
})
.where("id = :id", { id: transferOwnership.fromId })
.execute();
await manager
.createQueryBuilder()
.update(user)
.set({
isOwner: true,
})
.where("id = :id", { id: transferOwnership.toId })
.execute();
})
.then(() => {})
.catch((err) => {
throw new InternalException("Failed transfering ownership", err);
});
}
/**
* @description delete user
* @param DeleteUserCommand

View file

@ -1,4 +1,4 @@
import { PermissionString } from "../../../type/permissionTypes";
import { PermissionString } from "../type/permissionTypes";
export interface CreateUserPermissionCommand {
permission: PermissionString;

View file

@ -1,21 +1,21 @@
import { DeleteResult, EntityManager, InsertResult } from "typeorm";
import { dataSource } from "../../../data-source";
import { user } from "../../../entity/user/user";
import { userPermission } from "../../../entity/user/user_permission";
import InternalException from "../../../exceptions/internalException";
import { dataSource } from "../data-source";
import { user } from "../entity/user";
import { userPermission } from "../entity/user_permission";
import InternalException from "../exceptions/internalException";
import {
CreateUserPermissionCommand,
DeleteUserPermissionCommand,
UpdateUserPermissionsCommand,
} from "./userPermissionCommand";
import UserPermissionService from "../../../service/user/userPermissionService";
import PermissionHelper from "../../../helpers/permissionHelper";
import { PermissionString } from "../../../type/permissionTypes";
import UserPermissionService from "../service/userPermissionService";
import PermissionHelper from "../helpers/permissionHelper";
import { PermissionString } from "../type/permissionTypes";
export default abstract class UserPermissionCommandHandler {
/**
* @description update user permissions
* @param {UpdateUserPermissionsCommand} updateUserPermissions
* @param UpdateUserPermissionsCommand
* @returns {Promise<void>}
*/
static async updatePermissions(updateUserPermissions: UpdateUserPermissionsCommand): Promise<void> {
@ -75,7 +75,7 @@ export default abstract class UserPermissionCommandHandler {
/**
* @description grant permission to user
* @param {CreateUserPermissionCommand} createPermission
* @param CreateUserPermissionCommand
* @returns {Promise<number>}
*/
static async create(createPermission: CreateUserPermissionCommand): Promise<number> {
@ -98,7 +98,7 @@ export default abstract class UserPermissionCommandHandler {
/**
* @description remove permission to user
* @param {DeleteUserPermissionCommand} deletePermission
* @param DeleteUserPermissionCommand
* @returns {Promise<any>}
*/
static async delete(deletePermission: DeleteUserPermissionCommand): Promise<any> {

View file

@ -1,8 +1,8 @@
import { Request, Response } from "express";
import AwardService from "../../../service/settings/awardService";
import AwardFactory from "../../../factory/admin/settings/award";
import { CreateAwardCommand, DeleteAwardCommand, UpdateAwardCommand } from "../../../command/settings/award/awardCommand";
import AwardCommandHandler from "../../../command/settings/award/awardCommandHandler";
import AwardService from "../../service/awardService";
import AwardFactory from "../../factory/admin/award";
import { CreateAwardCommand, DeleteAwardCommand, UpdateAwardCommand } from "../../command/awardCommand";
import AwardCommandHandler from "../../command/awardCommandHandler";
/**
* @description get all awards

View file

@ -1,205 +0,0 @@
import { Request, Response } from "express";
import CalendarService from "../../../service/club/calendarService";
import CalendarFactory from "../../../factory/admin/club/calendar";
import CalendarTypeService from "../../../service/settings/calendarTypeService";
import CalendarTypeFactory from "../../../factory/admin/settings/calendarType";
import { CreateCalendarCommand, DeleteCalendarCommand, UpdateCalendarCommand } from "../../../command/club/calendar/calendarCommand";
import CalendarCommandHandler from "../../../command/club/calendar/calendarCommandHandler";
import {
CreateCalendarTypeCommand,
DeleteCalendarTypeCommand,
UpdateCalendarTypeCommand,
} from "../../../command/settings/calendarType/calendarTypeCommand";
import CalendarTypeCommandHandler from "../../../command/settings/calendarType/calendarTypeCommandHandler";
/**
* @description get all calendar items
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function getAllCalendarItems(req: Request, res: Response): Promise<any> {
let items = await CalendarService.getAll();
res.json(CalendarFactory.mapToBase(items));
}
/**
* @description get calendar item by id
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function getCalendarItemById(req: Request, res: Response): Promise<any> {
const id = req.params.id;
let item = await CalendarService.getById(id);
res.json(CalendarFactory.mapToSingle(item));
}
/**
* @description get all calendar types
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function getAllCalendarTypes(req: Request, res: Response): Promise<any> {
let types = await CalendarTypeService.getAll();
res.json(CalendarTypeFactory.mapToBase(types));
}
/**
* @description get calendar type by id
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function getCalendarTypeById(req: Request, res: Response): Promise<any> {
const id = parseInt(req.params.id);
let type = await CalendarTypeService.getById(id);
res.json(CalendarTypeFactory.mapToSingle(type));
}
/**
* @description create calendar item
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function createCalendarItem(req: Request, res: Response): Promise<any> {
const starttime = req.body.starttime;
const endtime = req.body.endtime;
const title = req.body.title;
const content = req.body.content;
const location = req.body.location;
const allDay = req.body.allDay;
const typeId = req.body.typeId;
let createItem: CreateCalendarCommand = {
starttime,
endtime,
title,
content,
location,
allDay,
typeId,
};
let id = await CalendarCommandHandler.create(createItem);
res.send(id);
}
/**
* @description create calendar type
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function createCalendarType(req: Request, res: Response): Promise<any> {
const type = req.body.type;
const nscdr = req.body.nscdr;
const color = req.body.color;
const passphrase = req.body.passphrase;
let createType: CreateCalendarTypeCommand = {
type,
nscdr,
color,
passphrase,
};
let id = await CalendarTypeCommandHandler.create(createType);
res.send(id);
}
/**
* @description update calendar item
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function updateCalendarItem(req: Request, res: Response): Promise<any> {
const id = req.params.id;
const starttime = req.body.starttime;
const endtime = req.body.endtime;
const title = req.body.title;
const content = req.body.content;
const location = req.body.location;
const allDay = req.body.allDay;
const typeId = req.body.typeId;
let updateItem: UpdateCalendarCommand = {
id,
starttime,
endtime,
title,
content,
location,
allDay,
typeId,
};
await CalendarCommandHandler.update(updateItem);
res.sendStatus(204);
}
/**
* @description update calendar type
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function updateCalendarType(req: Request, res: Response): Promise<any> {
const id = parseInt(req.params.id);
const type = req.body.type;
const nscdr = req.body.nscdr;
const color = req.body.color;
const passphrase = req.body.passphrase;
let updateType: UpdateCalendarTypeCommand = {
id,
type,
nscdr,
color,
passphrase,
};
await CalendarTypeCommandHandler.update(updateType);
res.sendStatus(204);
}
/**
* @description delete calendar item
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function deleteCalendarItem(req: Request, res: Response): Promise<any> {
const id = req.params.id;
let deleteItem: DeleteCalendarCommand = {
id,
};
await CalendarCommandHandler.delete(deleteItem);
res.sendStatus(204);
}
/**
* @description delete calendar type
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function deleteCalendarType(req: Request, res: Response): Promise<any> {
const id = parseInt(req.params.id);
let deleteType: DeleteCalendarTypeCommand = {
id,
};
await CalendarTypeCommandHandler.delete(deleteType);
res.sendStatus(204);
}

View file

@ -1,388 +0,0 @@
import { Request, Response } from "express";
import NewsletterService from "../../../service/club/newsletter/newsletterService";
import NewsletterFactory from "../../../factory/admin/club/newsletter/newsletter";
import NewsletterDatesService from "../../../service/club/newsletter/newsletterDatesService";
import NewsletterDatesFactory from "../../../factory/admin/club/newsletter/newsletterDates";
import NewsletterRecipientsService from "../../../service/club/newsletter/newsletterRecipientsService";
import NewsletterRecipientsFactory from "../../../factory/admin/club/newsletter/newsletterRecipients";
import { FileSystemHelper } from "../../../helpers/fileSystemHelper";
import {
CreateNewsletterCommand,
SynchronizeNewsletterCommand,
} from "../../../command/club/newsletter/newsletterCommand";
import NewsletterCommandHandler from "../../../command/club/newsletter/newsletterCommandHandler";
import { SynchronizeNewsletterDatesCommand } from "../../../command/club/newsletter/newsletterDatesCommand";
import NewsletterDatesCommandHandler from "../../../command/club/newsletter/newsletterDatesCommandHandler";
import { SynchronizeNewsletterRecipientsCommand } from "../../../command/club/newsletter/newsletterRecipientsCommand";
import NewsletterRecipientsCommandHandler from "../../../command/club/newsletter/newsletterRecipientsCommandHandler";
import { NewsletterDatesViewModel } from "../../../viewmodel/admin/club/newsletter/newsletterDates.models";
import { PdfExport } from "../../../helpers/pdfExport";
import UserService from "../../../service/user/userService";
import { TemplateHelper } from "../../../helpers/templateHelper";
import MailHelper from "../../../helpers/mailHelper";
import { NewsletterEventType, NewsletterHelper } from "../../../helpers/newsletterHelper";
import { Salutation } from "../../../enums/salutation";
/**
* @description get all newsletters
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function getAllNewsletters(req: Request, res: Response): Promise<any> {
let offset = parseInt((req.query.offset as string) ?? "0");
let count = parseInt((req.query.count as string) ?? "25");
let [newsletters, total] = await NewsletterService.getAll(offset, count);
res.json({
newsletters: NewsletterFactory.mapToBase(newsletters),
total: total,
offset: offset,
count: count,
});
}
/**
* @description get newsletter by id
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function getNewsletterById(req: Request, res: Response): Promise<any> {
let id = parseInt(req.params.id);
let newsletter = await NewsletterService.getById(id);
res.json(NewsletterFactory.mapToSingle(newsletter));
}
/**
* @description get newsletter dates by id
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function getNewsletterDatesById(req: Request, res: Response): Promise<any> {
let newsletterId = parseInt(req.params.newsletterId);
let dates = await NewsletterDatesService.getAll(newsletterId);
res.json(NewsletterDatesFactory.mapToBase(dates));
}
/**
* @description get newsletter recipients by id
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function getNewsletterRecipientsById(req: Request, res: Response): Promise<any> {
let newsletterId = parseInt(req.params.newsletterId);
let recipients = await NewsletterRecipientsService.getAll(newsletterId);
res.json(NewsletterRecipientsFactory.mapToBase(recipients));
}
/**
* @description get newsletter printouts by id
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function getNewsletterPrintoutsById(req: Request, res: Response): Promise<any> {
let newsletterId = parseInt(req.params.newsletterId);
let newsletter = await NewsletterService.getById(newsletterId);
let filesInFolder = FileSystemHelper.getFilesInDirectory(
`newsletter/${newsletter.id}_${newsletter.title.replace(" ", "")}`
);
res.json(filesInFolder);
}
/**
* @description get newsletter printout by id and print
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function getNewsletterPrintoutByIdAndPrint(req: Request, res: Response): Promise<any> {
let newsletterId = parseInt(req.params.newsletterId);
let filename = req.params.filename;
let newsletter = await NewsletterService.getById(newsletterId);
let filepath = FileSystemHelper.formatPath(
"newsletter",
`${newsletter.id}_${newsletter.title.replace(" ", "")}`,
filename
);
res.sendFile(filepath, {
headers: {
"Content-Type": "application/pdf",
},
});
}
/**
* @description create newsletter printout preview by id
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function createNewsletterPrintoutPreviewById(req: Request, res: Response): Promise<any> {
let newsletterId = parseInt(req.params.newsletterId);
let newsletter = await NewsletterService.getById(newsletterId);
let dates = await NewsletterDatesService.getAll(newsletterId);
let recipient = await UserService.getById(parseInt(req.userId));
let data = NewsletterHelper.buildData(newsletter, dates);
data.recipient = {
firstname: recipient.firstname,
lastname: recipient.lastname,
salutation: Salutation.none,
nameaffix: "",
street: "Straße",
streetNumber: "Hausnummer",
streetNumberAdd: "Adresszusatz",
};
let pdf = await PdfExport.renderFile({
title: "Probedruck Newsletter",
template: "newsletter",
saveToDisk: false,
data: data,
});
let pdfbuffer = Buffer.from(pdf);
res.setHeader("Content-Type", "application/pdf");
res.setHeader("Content-Length", pdfbuffer.byteLength);
res.setHeader("Content-Disposition", "inline; filename=preview.pdf");
res.send(pdfbuffer);
}
/**
* @description create newsletter
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function createNewsletter(req: Request, res: Response): Promise<any> {
let title = req.body.title;
let createNewsletter: CreateNewsletterCommand = {
title,
};
let id = await NewsletterCommandHandler.create(createNewsletter);
res.send(id);
}
/**
* @description get newsletter printout progress by id
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function getNewsletterPrintoutProgressById(req: Request, res: Response): Promise<any> {
let newsletterId = parseInt(req.params.newsletterId);
res.writeHead(200, {
"Content-Type": "text/plain",
"Transfer-Encoding": "chunked",
});
const progressHandler = (data: NewsletterEventType) => {
if (data.newsletterId == newsletterId && data.kind == "pdf") {
res.write(JSON.stringify(data) + "//");
}
};
const completeHandler = (data: NewsletterEventType) => {
if (data.newsletterId == newsletterId && data.kind == "pdf") {
res.write(JSON.stringify(data));
res.end();
}
};
NewsletterHelper.jobStatus.on("progress", progressHandler);
NewsletterHelper.jobStatus.on("complete", completeHandler);
req.on("close", () => {
NewsletterHelper.jobStatus.off("progress", progressHandler);
NewsletterHelper.jobStatus.off("complete", completeHandler);
});
}
/**
* @description create newsletter printouts for each member by id
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function createNewsletterPrintoutById(req: Request, res: Response): Promise<any> {
let newsletterId = parseInt(req.params.newsletterId);
await NewsletterHelper.printPdfs(newsletterId);
res.sendStatus(204);
}
/**
* @description create newsletter mail preview by id
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function createNewsletterMailPreviewById(req: Request, res: Response): Promise<any> {
let newsletterId = parseInt(req.params.newsletterId);
let newsletter = await NewsletterService.getById(newsletterId);
let dates = await NewsletterDatesService.getAll(newsletterId);
let recipient = await UserService.getById(parseInt(req.userId));
let data = NewsletterHelper.buildData(newsletter, dates);
data.recipient = {
firstname: recipient.firstname,
lastname: recipient.lastname,
salutation: Salutation.none,
nameaffix: "",
street: "Straße",
streetNumber: "Hausnummer",
streetNumberAdd: "Adresszusatz",
};
const { body } = await TemplateHelper.renderFileForModule({
module: "newsletter",
bodyData: data,
title: "Probeversand Newsletter",
});
await MailHelper.sendMail(recipient.mail, "Probeversand Newsletter", body);
res.sendStatus(204);
}
/**
* @description send newsletter mail and create printouts by id
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function sendNewsletterById(req: Request, res: Response): Promise<any> {
let newsletterId = parseInt(req.params.newsletterId);
await NewsletterHelper.sendMails(newsletterId);
res.sendStatus(204);
}
/**
* @description get newsletter sending progress by id
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function getNewsletterSendingProgressById(req: Request, res: Response): Promise<any> {
let newsletterId = parseInt(req.params.newsletterId);
res.writeHead(200, {
"Content-Type": "text/plain",
"Transfer-Encoding": "chunked",
});
const progressHandler = (data: NewsletterEventType) => {
if (data.newsletterId == newsletterId && data.kind == "mail") {
res.write(JSON.stringify(data) + "//");
}
};
const completeHandler = (data: NewsletterEventType) => {
if (data.newsletterId == newsletterId && data.kind == "mail") {
res.write(JSON.stringify(data));
res.end();
}
};
NewsletterHelper.jobStatus.on("progress", progressHandler);
NewsletterHelper.jobStatus.on("complete", completeHandler);
req.on("close", () => {
NewsletterHelper.jobStatus.off("progress", progressHandler);
NewsletterHelper.jobStatus.off("complete", completeHandler);
});
}
/**
* @description synchronize newsletter by id
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function synchronizeNewsletterById(req: Request, res: Response): Promise<any> {
let id = parseInt(req.params.id);
let title = req.body.title;
let description = req.body.description;
let newsletterTitle = req.body.newsletterTitle;
let newsletterText = req.body.newsletterText;
let newsletterSignatur = req.body.newsletterSignatur;
let recipientsByQueryId = req.body.recipientsByQueryId ?? null;
let syncNewsletter: SynchronizeNewsletterCommand = {
id,
title,
description,
newsletterTitle,
newsletterText,
newsletterSignatur,
recipientsByQueryId,
};
await NewsletterCommandHandler.sync(syncNewsletter);
res.sendStatus(204);
}
/**
* @description synchronize newsletter dates by id
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function synchronizeNewsletterDatesById(req: Request, res: Response): Promise<any> {
let newsletterId = parseInt(req.params.newsletterId);
let dates = req.body.dates as Array<NewsletterDatesViewModel>;
let syncDates: SynchronizeNewsletterDatesCommand = {
newsletterId,
dates: dates.map((d) => ({
calendarId: d.calendarId,
diffTitle: d.diffTitle,
diffDescription: d.diffDescription,
})),
};
await NewsletterDatesCommandHandler.sync(syncDates);
res.sendStatus(204);
}
/**
* @description synchronize newsletter recipients by id
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function synchronizeNewsletterRecipientsById(req: Request, res: Response): Promise<any> {
let newsletterId = parseInt(req.params.newsletterId);
let recipients = req.body.recipients as Array<number>;
let syncRecipients: SynchronizeNewsletterRecipientsCommand = {
newsletterId,
recipients: recipients,
};
await NewsletterRecipientsCommandHandler.sync(syncRecipients);
res.sendStatus(204);
}

View file

@ -1,401 +0,0 @@
import { Request, Response } from "express";
import ProtocolService from "../../../service/club/protocol/protocolService";
import ProtocolFactory from "../../../factory/admin/club/protocol/protocol";
import ProtocolAgendaService from "../../../service/club/protocol/protocolAgendaService";
import ProtocolAgendaFactory from "../../../factory/admin/club/protocol/protocolAgenda";
import ProtocolDecisionService from "../../../service/club/protocol/protocolDecisionService";
import ProtocolDecisionFactory from "../../../factory/admin/club/protocol/protocolDecision";
import ProtocolPresenceService from "../../../service/club/protocol/protocolPrecenseService";
import ProtocolPresenceFactory from "../../../factory/admin/club/protocol/protocolPresence";
import ProtocolVotingService from "../../../service/club/protocol/protocolVotingService";
import ProtocolVotingFactory from "../../../factory/admin/club/protocol/protocolVoting";
import { CreateProtocolCommand, SynchronizeProtocolCommand } from "../../../command/club/protocol/protocolCommand";
import ProtocolCommandHandler from "../../../command/club/protocol/protocolCommandHandler";
import { SynchronizeProtocolAgendaCommand } from "../../../command/club/protocol/protocolAgendaCommand";
import ProtocolAgendaCommandHandler from "../../../command/club/protocol/protocolAgendaCommandHandler";
import { ProtocolAgendaViewModel } from "../../../viewmodel/admin/club/protocol/protocolAgenda.models";
import ProtocolDecisionCommandHandler from "../../../command/club/protocol/protocolDecisionCommandHandler";
import { ProtocolDecisionViewModel } from "../../../viewmodel/admin/club/protocol/protocolDecision.models";
import ProtocolPresenceCommandHandler from "../../../command/club/protocol/protocolPresenceCommandHandler";
import { SynchronizeProtocolPresenceCommand } from "../../../command/club/protocol/protocolPresenceCommand";
import { SynchronizeProtocolDecisionCommand } from "../../../command/club/protocol/protocolDecisionCommand";
import { SynchronizeProtocolVotingCommand } from "../../../command/club/protocol/protocolVotingCommand";
import { ProtocolVotingViewModel } from "../../../viewmodel/admin/club/protocol/protocolVoting.models";
import ProtocolVotingCommandHandler from "../../../command/club/protocol/protocolVotingCommandHandler";
import { PdfExport } from "../../../helpers/pdfExport";
import ProtocolPrintoutService from "../../../service/club/protocol/protocolPrintoutService";
import ProtocolPrintoutFactory from "../../../factory/admin/club/protocol/protocolPrintout";
import { CreateProtocolPrintoutCommand } from "../../../command/club/protocol/protocolPrintoutCommand";
import ProtocolPrintoutCommandHandler from "../../../command/club/protocol/protocolPrintoutCommandHandler";
import { FileSystemHelper } from "../../../helpers/fileSystemHelper";
import { ProtocolPresenceViewModel } from "../../../viewmodel/admin/club/protocol/protocolPresence.models";
/**
* @description get all protocols
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function getAllProtocols(req: Request, res: Response): Promise<any> {
let offset = parseInt((req.query.offset as string) ?? "0");
let count = parseInt((req.query.count as string) ?? "25");
let [protocols, total] = await ProtocolService.getAll(offset, count);
res.json({
protocols: ProtocolFactory.mapToBase(protocols),
total: total,
offset: offset,
count: count,
});
}
/**
* @description get protocol by id
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function getProtocolById(req: Request, res: Response): Promise<any> {
let id = parseInt(req.params.id);
let protocol = await ProtocolService.getById(id);
res.json(ProtocolFactory.mapToSingle(protocol));
}
/**
* @description get protocol agenda by id
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function getProtocolAgendaById(req: Request, res: Response): Promise<any> {
let protocolId = parseInt(req.params.protocolId);
let agenda = await ProtocolAgendaService.getAll(protocolId);
res.json(ProtocolAgendaFactory.mapToBase(agenda));
}
/**
* @description get protocol decisions by id
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function getProtocolDecisonsById(req: Request, res: Response): Promise<any> {
let protocolId = parseInt(req.params.protocolId);
let decisions = await ProtocolDecisionService.getAll(protocolId);
res.json(ProtocolDecisionFactory.mapToBase(decisions));
}
/**
* @description get protocol precense by id
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function getProtocolPrecenseById(req: Request, res: Response): Promise<any> {
let protocolId = parseInt(req.params.protocolId);
let presence = await ProtocolPresenceService.getAll(protocolId);
res.json(ProtocolPresenceFactory.mapToBase(presence));
}
/**
* @description get protocol votings by id
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function getProtocolVotingsById(req: Request, res: Response): Promise<any> {
let protocolId = parseInt(req.params.protocolId);
let votings = await ProtocolVotingService.getAll(protocolId);
res.json(ProtocolVotingFactory.mapToBase(votings));
}
/**
* @description get protocol printouts by id
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function getProtocolPrintoutsById(req: Request, res: Response): Promise<any> {
let protocolId = parseInt(req.params.protocolId);
let printouts = await ProtocolPrintoutService.getAll(protocolId);
res.json(ProtocolPrintoutFactory.mapToBase(printouts));
}
/**
* @description get protocol printout by id and print
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function getProtocolPrintoutByIdAndPrint(req: Request, res: Response): Promise<any> {
let protocolId = parseInt(req.params.protocolId);
let printoutId = parseInt(req.params.printoutId);
let printout = await ProtocolPrintoutService.getById(printoutId, protocolId);
let filepath = FileSystemHelper.formatPath("protocol", printout.filename);
res.sendFile(filepath, {
headers: {
"Content-Type": "application/pdf",
},
});
}
/**
* @description create protocol
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function createProtocol(req: Request, res: Response): Promise<any> {
let title = req.body.title;
let date = req.body.date;
let createProtocol: CreateProtocolCommand = {
title,
date,
};
let id = await ProtocolCommandHandler.create(createProtocol);
res.send(id);
}
/**
* @description create protocol agenda by id
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function createProtocolAgendaById(req: Request, res: Response): Promise<any> {
let protocolId = parseInt(req.params.protocolId);
let agenda = await ProtocolAgendaCommandHandler.create(protocolId);
res.send(agenda);
}
/**
* @description create protocol decisions by id
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function createProtocolDecisonsById(req: Request, res: Response): Promise<any> {
let protocolId = parseInt(req.params.protocolId);
let decision = await ProtocolDecisionCommandHandler.create(protocolId);
res.send(decision);
}
/**
* @description create protocol votings by id
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function createProtocolVotingsById(req: Request, res: Response): Promise<any> {
let protocolId = parseInt(req.params.protocolId);
let voting = await ProtocolVotingCommandHandler.create(protocolId);
res.send(voting);
}
/**
* @description create protocol printout by id
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function createProtocolPrintoutById(req: Request, res: Response): Promise<any> {
let protocolId = parseInt(req.params.protocolId);
let protocol = await ProtocolService.getById(protocolId);
let agenda = await ProtocolAgendaService.getAll(protocolId);
let decisions = await ProtocolDecisionService.getAll(protocolId);
let presence = await ProtocolPresenceService.getAll(protocolId);
let votings = await ProtocolVotingService.getAll(protocolId);
let iteration = await ProtocolPrintoutService.getCount(protocolId);
let title = `${protocol.title} - ${new Date(protocol.date).toLocaleDateString("de-DE", {
day: "2-digit",
month: "long",
year: "numeric",
})}`;
let filename = `${new Date().toISOString().split("T")[0]}_${iteration + 1}_Protokoll_${protocol.title.replace(
/[^a-zA-Z0-9]/g,
""
)}`;
await PdfExport.renderFile({
template: "protocol",
title,
filename,
folder: "protocol",
data: {
title: protocol.title,
summary: protocol.summary,
iteration: iteration + 1,
date: new Date(protocol.date).toLocaleDateString("de-DE", {
weekday: "long",
day: "2-digit",
month: "2-digit",
year: "numeric",
}),
start: protocol.starttime,
end: protocol.endtime,
agenda,
decisions,
presence: presence.filter((p) => !p.absent).map((p) => p.member),
absent: presence.filter((p) => p.absent).map((p) => ({ ...p.member, excused: p.excused })),
excused_absent: presence.filter((p) => p.absent && p.excused).map((p) => p.member),
unexcused_absent: presence.filter((p) => p.absent && !p.excused).map((p) => p.member),
votings,
},
});
let printout: CreateProtocolPrintoutCommand = {
title,
iteration: iteration + 1,
filename: `${filename}.pdf`,
protocolId,
};
await ProtocolPrintoutCommandHandler.create(printout);
res.sendStatus(204);
}
/**
* @description synchronize protocol by id
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function synchronizeProtocolById(req: Request, res: Response): Promise<any> {
let id = parseInt(req.params.id);
let title = req.body.title;
let date = req.body.date;
let starttime = req.body.starttime;
let endtime = req.body.endtime;
let summary = req.body.summary;
let syncProtocol: SynchronizeProtocolCommand = {
id,
title,
date,
starttime,
endtime,
summary,
};
await ProtocolCommandHandler.sync(syncProtocol);
res.sendStatus(204);
}
/**
* @description synchronize protocol agenda by id
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function synchronizeProtocolAgendaById(req: Request, res: Response): Promise<any> {
let protocolId = parseInt(req.params.protocolId);
let agenda = req.body.agenda as Array<ProtocolAgendaViewModel>;
let syncAgenda: Array<SynchronizeProtocolAgendaCommand> = agenda.map(
(a: ProtocolAgendaViewModel): SynchronizeProtocolAgendaCommand => ({
id: a.id ?? null,
topic: a.topic,
context: a.context,
protocolId,
})
);
await ProtocolAgendaCommandHandler.sync(syncAgenda);
res.sendStatus(204);
}
/**
* @description synchronize protocol decisions by id
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function synchronizeProtocolDecisonsById(req: Request, res: Response): Promise<any> {
let protocolId = parseInt(req.params.protocolId);
let decisions = req.body.decisions as Array<ProtocolDecisionViewModel>;
let syncDecision: Array<SynchronizeProtocolDecisionCommand> = decisions.map(
(d: ProtocolDecisionViewModel): SynchronizeProtocolDecisionCommand => ({
id: d.id ?? null,
topic: d.topic,
context: d.context,
protocolId,
})
);
await ProtocolDecisionCommandHandler.sync(syncDecision);
res.sendStatus(204);
}
/**
* @description synchronize protocol votings by id
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function synchronizeProtocolVotingsById(req: Request, res: Response): Promise<any> {
let protocolId = parseInt(req.params.protocolId);
let votings = req.body.votings as Array<ProtocolVotingViewModel>;
let syncVoting: Array<SynchronizeProtocolVotingCommand> = votings.map(
(d: ProtocolVotingViewModel): SynchronizeProtocolVotingCommand => ({
id: d.id ?? null,
topic: d.topic,
context: d.context,
favour: d.favour,
abstain: d.abstain,
against: d.abstain,
protocolId,
})
);
await ProtocolVotingCommandHandler.sync(syncVoting);
res.sendStatus(204);
}
/**
* @description synchronize protocol precense by id
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function synchronizeProtocolPrecenseById(req: Request, res: Response): Promise<any> {
let protocolId = parseInt(req.params.protocolId);
let presence = req.body.presence as Array<ProtocolPresenceViewModel>;
let syncPresence: SynchronizeProtocolPresenceCommand = {
members: presence.map((p) => ({
memberId: p.memberId,
absent: p.absent,
excused: p.excused,
})),
protocolId,
};
await ProtocolPresenceCommandHandler.sync(syncPresence);
res.sendStatus(204);
}

View file

@ -1,44 +0,0 @@
import { Request, Response } from "express";
import DynamicQueryBuilder from "../../../helpers/dynamicQueryBuilder";
import { dataSource } from "../../../data-source";
/**
* @description get all table metas
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function getAllTableMeta(req: Request, res: Response): Promise<any> {
let tableMetas = DynamicQueryBuilder.getAllTableMeta();
res.json(tableMetas);
}
/**
* @description get meta by tablename
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function getTableMetaByTablename(req: Request, res: Response): Promise<any> {
const tablename = req.params.tablename;
let tableMeta = DynamicQueryBuilder.getTableMeta(tablename);
res.json(tableMeta);
}
/**
* @description execute Query
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function executeQuery(req: Request, res: Response): Promise<any> {
let offset = parseInt((req.query.offset as string) ?? "0");
let count = parseInt((req.query.count as string) ?? "25");
const query = req.body.query;
let result = await DynamicQueryBuilder.executeQuery(query, offset, count);
res.json(result);
}

View file

@ -1,13 +1,13 @@
import { Request, Response } from "express";
import CommunicationTypeService from "../../../service/settings/communicationTypeService";
import CommunicationTypeFactory from "../../../factory/admin/settings/communicationType";
import CommunicationService from "../../../service/club/member/communicationService";
import CommunicationTypeService from "../../service/communicationTypeService";
import CommunicationTypeFactory from "../../factory/admin/communicationType";
import CommunicationService from "../../service/communicationService";
import {
CreateCommunicationTypeCommand,
DeleteCommunicationTypeCommand,
UpdateCommunicationTypeCommand,
} from "../../../command/settings/communicationType/communicationTypeCommand";
import CommunicationTypeCommandHandler from "../../../command/settings/communicationType/communicationTypeCommandHandler";
} from "../../command/communicationTypeCommand";
import CommunicationTypeCommandHandler from "../../command/communicationTypeCommandHandler";
/**
* @description get all communicationTypes

View file

@ -1,12 +1,12 @@
import { Request, Response } from "express";
import ExecutivePositionService from "../../../service/settings/executivePositionService";
import ExecutivePositionFactory from "../../../factory/admin/settings/executivePosition";
import ExecutivePositionService from "../../service/executivePositionService";
import ExecutivePositionFactory from "../../factory/admin/executivePosition";
import {
CreateExecutivePositionCommand,
DeleteExecutivePositionCommand,
UpdateExecutivePositionCommand,
} from "../../../command/settings/executivePosition/executivePositionCommand";
import ExecutivePositionCommandHandler from "../../../command/settings/executivePosition/executivePositionCommandHandler";
} from "../../command/executivePositionCommand";
import ExecutivePositionCommandHandler from "../../command/executivePositionCommandHandler";
/**
* @description get all executivePositions

View file

@ -0,0 +1,161 @@
import { Request, Response } from "express";
import MemberService from "../../service/memberService";
import AwardService from "../../service/awardService";
import CommunicationTypeService from "../../service/communicationTypeService";
import ExecutivePositionService from "../../service/executivePositionService";
import crypto from "crypto";
import { type BinaryLike } from "node:crypto";
import { CreateAwardCommand } from "../../command/awardCommand";
import AwardCommandHandler from "../../command/awardCommandHandler";
/**
* @description get all data stored in the database as a single json object
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function getDatabaseExport(req: Request, res: Response): Promise<any> {
const noEncryption = req.headers["x-encrypt-no"];
const secret = req.headers["x-encrypt-with"];
try {
if (!secret && !noEncryption) {
res.status(400).send("Empty encryption key");
return;
}
let data: any = {};
console.log("Exporting awards...");
data.awards = await AwardService.getAll();
console.log(`Exported ${data.awards.length} awards`);
console.log("Exporting communication types...");
data.communicationTypes = await CommunicationTypeService.getAll();
console.log(`Exported ${data.communicationTypes.length} communicationTypes`);
console.log("Exporting executivePositions...");
data.executivePositions = await ExecutivePositionService.getAll();
console.log(`Exported ${data.executivePositions.length} executivePositions`);
console.log("Exporting members...");
data.members = await MemberService.getAll();
console.log(`Exported ${data.members.length} members`);
if (noEncryption) {
console.log(`Sending data unencrypted with length ${data.length}`);
res.json({
encrypted: !noEncryption,
data: data,
});
console.log("finished encrypted data");
} else {
const dataStr: string = JSON.stringify(data);
console.log(`Encrypting data...`);
const iv = await new Promise((resolve, reject) => {
// create initialization vector
crypto.randomBytes(16, (err, iv) => {
if (err) {
reject(err);
return;
}
resolve(iv);
});
});
// encrypt data
let base64Key = crypto.createHash("sha256").update(String(secret)).digest("base64");
const key = Buffer.from(base64Key, "base64");
// create initialization vector
const randomIV: Buffer = await new Promise((resolve, reject) => {
crypto.randomBytes(16, (err, iv) => {
if (err) {
reject(err);
return;
}
resolve(iv);
});
});
// console.log(`iv: ${randomIV.toString('hex')}`);
// console.log(`key: ${key.toString('hex')}`);
let cipher = crypto.createCipheriv("aes-256-gcm", key, randomIV);
const encryptedData: string = cipher.update(dataStr, "utf8", "hex") + cipher.final("hex");
const authTag = cipher.getAuthTag().toString("hex");
// console.log(`authTag: ${authTag}`);
console.log(`Sending encrypted data with length ${encryptedData.length}`);
res.json({
encrypted: !noEncryption,
iv: randomIV.toString("base64"),
data: encryptedData,
authTag: authTag,
});
console.log("finished encrypted data");
}
} catch (ex) {
console.log(ex);
res.status(500).send(ex.message ? ex.message : "Exception!");
}
}
/**
* @description decrypt the import data and use it to re-fill the database
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function importDatabaseExport(req: Request, res: Response): Promise<any> {
const { data: receivedData } = req.body;
if (!receivedData) {
res.status(400).send("Empty database import data");
return;
}
const noEncryption = req.headers["x-encrypt-no"];
try {
let data;
if (noEncryption) {
data = receivedData;
} else {
const secret = req.headers["x-decrypt-with"];
const { iv, authTag } = req.body;
if (!secret) {
res.status(400).send("Empty decryption key");
return;
}
if (!iv) {
res.status(400).send("Empty database import iv");
return;
}
if (!authTag) {
res.status(400).send("Empty database import authTag");
return;
}
// prepare the secret to be in a buffer
const base64Key = crypto.createHash("sha256").update(String(secret)).digest("base64");
const key = Buffer.from(base64Key, "base64");
// decrypt data
const ivString = Buffer.from(iv, "base64");
// console.log(`iv: ${ivString.toString('hex')}`);
// console.log(`key: ${key.toString('hex')}`);
// console.log(`authTag: ${authTag}`);
const decipher = crypto.createDecipheriv("aes-256-gcm", key, ivString);
decipher.setAuthTag(Buffer.from(authTag, "hex"));
const decrypted = decipher.update(receivedData, "hex", "utf-8") + decipher.final("utf-8");
data = JSON.parse(decrypted.toString());
}
for (const award of data.awards) {
let createAward: CreateAwardCommand = {
award: award,
};
const awardId: any = await AwardCommandHandler.create(createAward);
console.log(`Award with id ${awardId} created`);
}
res.send(200);
} catch (ex) {
console.log(ex);
res.status(500).send(ex.message ? ex.message : "Exception!");
}
}

View file

@ -1,55 +1,53 @@
import { Request, Response } from "express";
import MemberService from "../../../service/club/member/memberService";
import MemberFactory from "../../../factory/admin/club/member/member";
import MembershipService from "../../../service/club/member/membershipService";
import MembershipFactory from "../../../factory/admin/club/member/membership";
import MemberAwardService from "../../../service/club/member/memberAwardService";
import MemberAwardFactory from "../../../factory/admin/club/member/memberAward";
import MemberQualificationService from "../../../service/club/member/memberQualificationService";
import MemberQualificationFactory from "../../../factory/admin/club/member/memberQualification";
import MemberExecutivePositionService from "../../../service/club/member/memberExecutivePositionService";
import MemberExecutivePositionFactory from "../../../factory/admin/club/member/memberExecutivePosition";
import CommunicationService from "../../../service/club/member/communicationService";
import CommunicationFactory from "../../../factory/admin/club/member/communication";
import MemberService from "../../service/memberService";
import MemberFactory from "../../factory/admin/member";
import MembershipService from "../../service/membershipService";
import MembershipFactory from "../../factory/admin/membership";
import MemberAwardService from "../../service/memberAwardService";
import MemberAwardFactory from "../../factory/admin/memberAward";
import MemberQualificationService from "../../service/memberQualificationService";
import MemberQualificationFactory from "../../factory/admin/memberQualification";
import MemberExecutivePositionService from "../../service/memberExecutivePositionService";
import MemberExecutivePositionFactory from "../../factory/admin/memberExecutivePosition";
import CommunicationService from "../../service/communicationService";
import CommunicationFactory from "../../factory/admin/communication";
import {
CreateMemberCommand,
DeleteMemberCommand,
UpdateMemberCommand,
UpdateMemberNewsletterCommand,
} from "../../../command/club/member/memberCommand";
import MemberCommandHandler from "../../../command/club/member/memberCommandHandler";
} from "../../command/memberCommand";
import MemberCommandHandler from "../../command/memberCommandHandler";
import {
CreateMembershipCommand,
DeleteMembershipCommand,
UpdateMembershipCommand,
} from "../../../command/club/member/membershipCommand";
import MembershipCommandHandler from "../../../command/club/member/membershipCommandHandler";
} from "../../command/membershipCommand";
import MembershipCommandHandler from "../../command/membershipCommandHandler";
import {
CreateMemberAwardCommand,
DeleteMemberAwardCommand,
UpdateMemberAwardCommand,
} from "../../../command/club/member/memberAwardCommand";
import MemberAwardCommandHandler from "../../../command/club/member/memberAwardCommandHandler";
} from "../../command/memberAwardCommand";
import MemberAwardCommandHandler from "../../command/memberAwardCommandHandler";
import {
CreateMemberExecutivePositionCommand,
DeleteMemberExecutivePositionCommand,
UpdateMemberExecutivePositionCommand,
} from "../../../command/club/member/memberExecutivePositionCommand";
import MemberExecutivePositionCommandHandler from "../../../command/club/member/memberExecutivePositionCommandHandler";
} from "../../command/memberExecutivePositionCommand";
import MemberExecutivePositionCommandHandler from "../../command/memberExecutivePositionCommandHandler";
import {
CreateMemberQualificationCommand,
DeleteMemberQualificationCommand,
UpdateMemberQualificationCommand,
} from "../../../command/club/member/memberQualificationCommand";
import MemberQualificationCommandHandler from "../../../command/club/member/memberQualificationCommandHandler";
} from "../../command/memberQualificationCommand";
import MemberQualificationCommandHandler from "../../command/memberQualificationCommandHandler";
import {
CreateCommunicationCommand,
DeleteCommunicationCommand,
UpdateCommunicationCommand,
} from "../../../command/club/member/communicationCommand";
import CommunicationCommandHandler from "../../../command/club/member/communicationCommandHandler";
import { PdfExport } from "../../../helpers/pdfExport";
import { PermissionModule } from "../../../type/permissionTypes";
} from "../../command/communicationCommand";
import CommunicationCommandHandler from "../../command/communicationCommandHandler";
/**
* @description get all members
@ -60,14 +58,7 @@ import { PermissionModule } from "../../../type/permissionTypes";
export async function getAllMembers(req: Request, res: Response): Promise<any> {
let offset = parseInt((req.query.offset as string) ?? "0");
let count = parseInt((req.query.count as string) ?? "25");
let search = (req.query.search as string) ?? "";
let noLimit = req.query.noLimit === "true";
let ids = ((req.query.ids ?? "") as string)
.split(",")
.filter((i) => i)
.map((i) => parseInt(i));
let [members, total] = await MemberService.getAll({ offset, count, search, noLimit, ids });
let [members, total] = await MemberService.getAll(offset, count);
res.json({
members: MemberFactory.mapToBase(members),
@ -225,33 +216,6 @@ export async function getCommunicationByMemberAndRecord(req: Request, res: Respo
res.json(CommunicationFactory.mapToSingle(communication));
}
/**
* @description create member printout list
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function createMemberPrintoutList(req: Request, res: Response): Promise<any> {
let members = await MemberService.getByRunningMembership();
let pdf = await PdfExport.renderFile({
title: "Mitgliederliste",
template: "member.list",
saveToDisk: false,
data: {
member: members,
},
});
let pdfbuffer = Buffer.from(pdf);
res.setHeader("Content-Type", "application/pdf");
res.setHeader("Content-Length", pdfbuffer.byteLength);
res.setHeader("Content-Disposition", "inline; filename=preview.pdf");
res.send(pdfbuffer);
}
/**
* @description create member
* @param req {Request} Express req object
@ -264,7 +228,6 @@ export async function createMember(req: Request, res: Response): Promise<any> {
const lastname = req.body.lastname;
const nameaffix = req.body.nameaffix;
const birthdate = req.body.birthdate;
const internalId = req.body.internalId;
let createMember: CreateMemberCommand = {
salutation,
@ -272,7 +235,6 @@ export async function createMember(req: Request, res: Response): Promise<any> {
lastname,
nameaffix,
birthdate,
internalId,
};
let memberId = await MemberCommandHandler.create(createMember);
@ -287,10 +249,12 @@ export async function createMember(req: Request, res: Response): Promise<any> {
*/
export async function addMembershipToMember(req: Request, res: Response): Promise<any> {
const memberId = parseInt(req.params.memberId);
const internalId = req.body.internalId;
const start = req.body.start;
const statusId = req.body.statusId;
let createMembership: CreateMembershipCommand = {
internalId,
start,
memberId,
statusId,
@ -382,10 +346,8 @@ export async function addExecutivePositionToMember(req: Request, res: Response):
export async function addCommunicationToMember(req: Request, res: Response): Promise<any> {
const memberId = parseInt(req.params.memberId);
const preferred = req.body.preferred;
const isSMSAlarming = req.body.isSMSAlarming;
const mobile = req.body.mobile;
const email = req.body.email;
const postalCode = req.body.postalCode;
const city = req.body.city;
const street = req.body.street;
const streetNumber = req.body.streetNumber;
@ -395,10 +357,8 @@ export async function addCommunicationToMember(req: Request, res: Response): Pro
let createCommunication: CreateCommunicationCommand = {
preferred,
isSMSAlarming,
mobile,
email,
postalCode,
city,
street,
streetNumber,
@ -432,7 +392,6 @@ export async function updateMemberById(req: Request, res: Response): Promise<any
const lastname = req.body.lastname;
const nameaffix = req.body.nameaffix;
const birthdate = req.body.birthdate;
const internalId = req.body.internalId;
let updateMember: UpdateMemberCommand = {
id: memberId,
@ -441,7 +400,6 @@ export async function updateMemberById(req: Request, res: Response): Promise<any
lastname,
nameaffix,
birthdate,
internalId,
};
await MemberCommandHandler.update(updateMember);
@ -457,6 +415,7 @@ export async function updateMemberById(req: Request, res: Response): Promise<any
export async function updateMembershipOfMember(req: Request, res: Response): Promise<any> {
const memberId = parseInt(req.params.memberId);
const recordId = parseInt(req.params.recordId);
const internalId = req.body.internalId;
const start = req.body.start;
const end = req.body.end || null;
const terminationReason = req.body.terminationReason;
@ -464,6 +423,7 @@ export async function updateMembershipOfMember(req: Request, res: Response): Pro
let updateMembership: UpdateMembershipCommand = {
id: recordId,
internalId,
start,
end,
terminationReason,
@ -568,23 +528,20 @@ export async function updateCommunicationOfMember(req: Request, res: Response):
const memberId = parseInt(req.params.memberId);
const recordId = parseInt(req.params.recordId);
const preferred = req.body.preferred;
const isSMSAlarming = req.body.isSMSAlarming;
const mobile = req.body.mobile;
const email = req.body.email;
const postalCode = req.body.postalCode;
const city = req.body.city;
const street = req.body.street;
const streetNumber = req.body.streetNumber;
const streetNumberAddition = req.body.streetNumberAddition;
const typeId = req.body.typeId;
const isNewsletterMain = req.body.isNewsletterMain;
let updateCommunication: UpdateCommunicationCommand = {
id: recordId,
preferred,
isSMSAlarming,
mobile,
email,
postalCode,
city,
street,
streetNumber,
@ -593,16 +550,12 @@ export async function updateCommunicationOfMember(req: Request, res: Response):
};
await CommunicationCommandHandler.update(updateCommunication);
let currentUserNewsletterMain = await MemberService.getNewsletterById(memberId);
if (isNewsletterMain) {
let updateNewsletter: UpdateMemberNewsletterCommand = {
id: memberId,
communicationId: recordId,
};
await MemberCommandHandler.updateNewsletter(updateNewsletter);
} else if (currentUserNewsletterMain.sendNewsletter?.id == recordId) {
await MemberCommandHandler.unsetNewsletter(memberId);
}
res.sendStatus(204);

View file

@ -1,12 +1,12 @@
import { Request, Response } from "express";
import MembershipStatusService from "../../../service/settings/membershipStatusService";
import MembershipStatusFactory from "../../../factory/admin/settings/membershipStatus";
import MembershipStatusService from "../../service/membershipStatusService";
import MembershipStatusFactory from "../../factory/admin/membershipStatus";
import {
CreateMembershipStatusCommand,
DeleteMembershipStatusCommand,
UpdateMembershipStatusCommand,
} from "../../../command/settings/membershipStatus/membershipStatusCommand";
import MembershipStatusCommandHandler from "../../../command/settings/membershipStatus/membershipStatusCommandHandler";
} from "../../command/membershipStatusCommand";
import MembershipStatusCommandHandler from "../../command/membershipStatusCommandHandler";
/**
* @description get all membershipStatus

View file

@ -1,12 +1,12 @@
import { Request, Response } from "express";
import QualificationService from "../../../service/settings/qualification";
import QualificationFactory from "../../../factory/admin/settings/qualification";
import QualificationService from "../../service/qualification";
import QualificationFactory from "../../factory/admin/qualification";
import {
CreateQualificationCommand,
DeleteQualificationCommand,
UpdateQualificationCommand,
} from "../../../command/settings/qualification/qualificationCommand";
import QualificationCommandHandler from "../../../command/settings/qualification/qualificationCommandHandler";
} from "../../command/qualificationCommand";
import QualificationCommandHandler from "../../command/qualificationCommandHandler";
/**
* @description get all qualifications

View file

@ -1,12 +1,12 @@
import { Request, Response } from "express";
import RoleService from "../../../service/user/roleService";
import RoleFactory from "../../../factory/admin/user/role";
import RolePermissionService from "../../../service/user/rolePermissionService";
import PermissionHelper from "../../../helpers/permissionHelper";
import { CreateRoleCommand, DeleteRoleCommand, UpdateRoleCommand } from "../../../command/user/role/roleCommand";
import RoleCommandHandler from "../../../command/user/role/roleCommandHandler";
import { UpdateRolePermissionsCommand } from "../../../command/user/role/rolePermissionCommand";
import RolePermissionCommandHandler from "../../../command/user/role/rolePermissionCommandHandler";
import RoleService from "../../service/roleService";
import RoleFactory from "../../factory/admin/role";
import RolePermissionService from "../../service/rolePermissionService";
import PermissionHelper from "../../helpers/permissionHelper";
import { CreateRoleCommand, DeleteRoleCommand, UpdateRoleCommand } from "../../command/roleCommand";
import RoleCommandHandler from "../../command/roleCommandHandler";
import { UpdateRolePermissionsCommand } from "../../command/rolePermissionCommand";
import RolePermissionCommandHandler from "../../command/rolePermissionCommandHandler";
/**
* @description get All roles

View file

@ -1,49 +0,0 @@
import { Request, Response } from "express";
import NewsletterConfigService from "../../../service/settings/newsletterConfigService";
import NewsletterConfigFactory from "../../../factory/admin/settings/newsletterConfig";
import NewsletterConfigCommandHandler from "../../../command/settings/newsletterConfig/newsletterConfigCommandHandler";
import { SetNewsletterConfigCommand } from "../../../command/settings/newsletterConfig/newsletterConfigCommand";
/**
* @description get all newsletterConfigs
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function getAllNewsletterConfigs(req: Request, res: Response): Promise<any> {
let newsletterConfigs = await NewsletterConfigService.getAll();
res.json(NewsletterConfigFactory.mapToBase(newsletterConfigs));
}
/**
* @description get newsletterConfig by id
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function getNewsletterConfigById(req: Request, res: Response): Promise<any> {
let comId = parseInt(req.params.comId);
let newsletterConfig = await NewsletterConfigService.getByComId(comId);
res.json(NewsletterConfigFactory.mapToSingle(newsletterConfig));
}
/**
* @description set newsletterConfig
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function setNewsletterConfig(req: Request, res: Response): Promise<any> {
let comTypeId = req.body.comTypeId;
let config = req.body.config;
let createNewsletterConfig: SetNewsletterConfigCommand = {
comTypeId,
config,
};
let id = await NewsletterConfigCommandHandler.set(createNewsletterConfig);
res.send(id);
}

View file

@ -1,93 +0,0 @@
import { Request, Response } from "express";
import QueryStoreFactory from "../../../factory/admin/settings/queryStore";
import QueryStoreService from "../../../service/settings/queryStoreService";
import {
CreateQueryStoreCommand,
DeleteQueryStoreCommand,
UpdateQueryStoreCommand,
} from "../../../command/settings/queryStore/queryStoreCommand";
import QueryStoreCommandHandler from "../../../command/settings/queryStore/queryStoreCommandHandler";
/**
* @description get all queryStores
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function getAllQueryStores(req: Request, res: Response): Promise<any> {
let queryStores = await QueryStoreService.getAll();
res.json(QueryStoreFactory.mapToBase(queryStores));
}
/**
* @description get queryStore by id
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function getQueryStoreById(req: Request, res: Response): Promise<any> {
const id = parseInt(req.params.id);
let queryStore = await QueryStoreService.getById(id);
res.json(QueryStoreFactory.mapToSingle(queryStore));
}
/**
* @description create new queryStore
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function createQueryStore(req: Request, res: Response): Promise<any> {
const query = req.body.query;
const title = req.body.title;
let createQueryStore: CreateQueryStoreCommand = {
title: title,
query: query,
};
let id = await QueryStoreCommandHandler.create(createQueryStore);
res.status(200).send(id);
}
/**
* @description update queryStore
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function updateQueryStore(req: Request, res: Response): Promise<any> {
const id = parseInt(req.params.id);
const query = req.body.query;
let updateQueryStore: UpdateQueryStoreCommand = {
id: id,
query: query,
};
await QueryStoreCommandHandler.update(updateQueryStore);
res.sendStatus(204);
}
/**
* @description delete queryStore
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function deleteQueryStore(req: Request, res: Response): Promise<any> {
const id = parseInt(req.params.id);
let deleteQueryStore: DeleteQueryStoreCommand = {
id: id,
};
await QueryStoreCommandHandler.delete(deleteQueryStore);
res.sendStatus(204);
}

View file

@ -1,120 +0,0 @@
import { Request, Response } from "express";
import TemplateService from "../../../service/settings/templateService";
import TemplateFactory from "../../../factory/admin/settings/template";
import { CreateTemplateCommand, DeleteTemplateCommand, UpdateTemplateCommand } from "../../../command/settings/template/templateCommand";
import TemplateCommandHandler from "../../../command/settings/template/templateCommandHandler";
/**
* @description get all templates
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function getAllTemplates(req: Request, res: Response): Promise<any> {
let templates = await TemplateService.getAll();
res.json(TemplateFactory.mapToBase(templates));
}
/**
* @description get template by id
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function getTemplateById(req: Request, res: Response): Promise<any> {
const id = parseInt(req.params.id);
let template = await TemplateService.getById(id);
res.json(TemplateFactory.mapToSingle(template));
}
/**
* @description create new template
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function createTemplate(req: Request, res: Response): Promise<any> {
const template = req.body.template;
const description = req.body.description;
let createTemplate: CreateTemplateCommand = {
template: template,
description: description,
};
let id = await TemplateCommandHandler.create(createTemplate);
res.status(200).send(id);
}
/**
* @description clone template
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function cloneTemplate(req: Request, res: Response): Promise<any> {
const cloneId = req.body.cloneId;
const { template, description, design, html } = await TemplateService.getById(cloneId);
let createTemplate: CreateTemplateCommand = {
template: "",
description: "",
};
let id = await TemplateCommandHandler.create(createTemplate);
let updateTemplate: UpdateTemplateCommand = {
id: id,
template: template + " - Kopie",
description: description,
design: design,
html: html,
};
await TemplateCommandHandler.update(updateTemplate);
res.status(200).send(id);
}
/**
* @description update template
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function updateTemplate(req: Request, res: Response): Promise<any> {
const id = parseInt(req.params.id);
const template = req.body.template;
const description = req.body.description;
const design = req.body.design;
const html = req.body.html;
let updateTemplate: UpdateTemplateCommand = {
id: id,
template: template,
description: description,
design: design,
html: html,
};
await TemplateCommandHandler.update(updateTemplate);
res.sendStatus(204);
}
/**
* @description delete template
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function deleteTemplate(req: Request, res: Response): Promise<any> {
const id = parseInt(req.params.id);
let deleteTemplate: DeleteTemplateCommand = {
id: id,
};
await TemplateCommandHandler.delete(deleteTemplate);
res.sendStatus(204);
}

View file

@ -1,95 +0,0 @@
import { Request, Response } from "express";
import TemplateUsageService from "../../../service/settings/templateUsageService";
import TemplateUsageFactory from "../../../factory/admin/settings/templateUsage";
import { UpdateTemplateUsageCommand } from "../../../command/settings/templateUsage/templateUsageCommand";
import TemplateUsageCommandHandler from "../../../command/settings/templateUsage/templateUsageCommandHandler";
import PermissionHelper from "../../../helpers/permissionHelper";
import ForbiddenRequestException from "../../../exceptions/forbiddenRequestException";
import { PermissionModule } from "../../../type/permissionTypes";
import { PdfExport } from "../../../helpers/pdfExport";
import { DemoDataHelper } from "../../../helpers/demoDataHelper";
/**
* @description get all templateUsages
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function getAllTemplateUsages(req: Request, res: Response): Promise<any> {
let templateUsages = await TemplateUsageService.getAll();
if (!req.isOwner) {
templateUsages = templateUsages.filter((tu) => {
return (
PermissionHelper.can(req.permissions, "update", "settings", tu.scope.split(".")[0] as PermissionModule) ||
PermissionHelper.can(req.permissions, "update", "club", tu.scope.split(".")[0] as PermissionModule)
);
});
}
res.json(TemplateUsageFactory.mapToBase(templateUsages));
}
/**
* @description print demo of templateUsage
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function printTemplateUsageDemo(req: Request, res: Response): Promise<any> {
const scope = req.params.scope as PermissionModule;
let demoData = DemoDataHelper.getData(scope);
let pdf = await PdfExport.renderFile({
template: scope,
saveToDisk: false,
data: demoData,
});
let pdfbuffer = Buffer.from(pdf);
res.setHeader("Content-Type", "application/pdf");
res.setHeader("Content-Length", pdfbuffer.byteLength);
res.setHeader("Content-Disposition", "inline; filename=preview.pdf");
res.send(pdfbuffer);
}
/**
* @description update templateUsage
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function updateTemplateUsage(req: Request, res: Response): Promise<any> {
const scope = req.params.scope;
let allowedSettings = PermissionHelper.can(
req.permissions,
"update",
"settings",
req.params.scope as PermissionModule
);
let allowedClub = PermissionHelper.can(req.permissions, "update", "club", req.params.scope as PermissionModule);
if (!(req.isOwner || allowedSettings || allowedClub)) {
throw new ForbiddenRequestException(`missing permission for editing scope ${req.params.scope}`);
}
const headerId = req.body.headerId ?? null;
const bodyId = req.body.bodyId ?? null;
const footerId = req.body.footerId ?? null;
const headerHeight = req.body.headerHeight ?? null;
const footerHeight = req.body.footerHeight ?? null;
let updateTemplateUsage: UpdateTemplateUsageCommand = {
scope: scope,
headerId: headerId,
bodyId: bodyId,
footerId: footerId,
headerHeight: headerHeight,
footerHeight: footerHeight,
};
await TemplateUsageCommandHandler.update(updateTemplateUsage);
res.sendStatus(204);
}

View file

@ -1,15 +1,15 @@
import { Request, Response } from "express";
import UserService from "../../../service/user/userService";
import UserFactory from "../../../factory/admin/user/user";
import UserPermissionService from "../../../service/user/userPermissionService";
import PermissionHelper from "../../../helpers/permissionHelper";
import RoleFactory from "../../../factory/admin/user/role";
import { DeleteUserCommand, UpdateUserCommand, UpdateUserRolesCommand } from "../../../command/user/user/userCommand";
import UserCommandHandler from "../../../command/user/user/userCommandHandler";
import MailHelper from "../../../helpers/mailHelper";
import { CLUB_NAME } from "../../../env.defaults";
import { UpdateUserPermissionsCommand } from "../../../command/user/user/userPermissionCommand";
import UserPermissionCommandHandler from "../../../command/user/user/userPermissionCommandHandler";
import UserService from "../../service/userService";
import UserFactory from "../../factory/admin/user";
import UserPermissionService from "../../service/userPermissionService";
import PermissionHelper from "../../helpers/permissionHelper";
import RoleFactory from "../../factory/admin/role";
import { DeleteUserCommand, UpdateUserCommand, UpdateUserRolesCommand } from "../../command/userCommand";
import UserCommandHandler from "../../command/userCommandHandler";
import MailHelper from "../../helpers/mailHelper";
import { CLUB_NAME } from "../../env.defaults";
import { UpdateUserPermissionsCommand } from "../../command/userPermissionCommand";
import UserPermissionCommandHandler from "../../command/userPermissionCommandHandler";
/**
* @description get All users
@ -146,7 +146,8 @@ export async function deleteUser(req: Request, res: Response): Promise<any> {
try {
// sendmail
await MailHelper.sendMail(
let mailhelper = new MailHelper();
await mailhelper.sendMail(
user.mail,
`Email Bestätigung für Mitglieder Admin-Portal von ${CLUB_NAME}`,
`Ihr Nutzerkonto des Adminportals wurde erfolgreich gelöscht.`

View file

@ -4,10 +4,13 @@ import { JWTToken } from "../type/jwtTypes";
import InternalException from "../exceptions/internalException";
import RefreshCommandHandler from "../command/refreshCommandHandler";
import { CreateRefreshCommand, DeleteRefreshCommand } from "../command/refreshCommand";
import UserService from "../service/user/userService";
import UserService from "../service/userService";
import speakeasy from "speakeasy";
import UnauthorizedRequestException from "../exceptions/unauthorizedRequestException";
import RefreshService from "../service/refreshService";
import UserPermissionService from "../service/userPermissionService";
import PermissionHelper from "../helpers/permissionHelper";
import RolePermissionService from "../service/rolePermissionService";
/**
* @description Check authentication status by token
@ -19,7 +22,7 @@ export async function login(req: Request, res: Response): Promise<any> {
let username = req.body.username;
let totp = req.body.totp;
let { id, secret } = await UserService.getByUsername(username);
let { id, secret, mail, firstname, lastname } = await UserService.getByUsername(username);
let valid = speakeasy.totp.verify({
secret: secret,
@ -32,13 +35,38 @@ export async function login(req: Request, res: Response): Promise<any> {
throw new UnauthorizedRequestException("Token not valid or expired");
}
let accessToken = await JWTHelper.buildToken(id);
let userPermissions = await UserPermissionService.getByUser(id);
let userPermissionStrings = userPermissions.map((e) => e.permission);
let userRoles = await UserService.getAssignedRolesByUserId(id);
let rolePermissions = userRoles.length != 0 ? await RolePermissionService.getByRoles(userRoles.map((e) => e.id)) : [];
let rolePermissionStrings = rolePermissions.map((e) => e.permission);
let permissionObject = PermissionHelper.convertToObject([...userPermissionStrings, ...rolePermissionStrings]);
let jwtData: JWTToken = {
userId: id,
mail: mail,
username: username,
firstname: firstname,
lastname: lastname,
permissions: permissionObject,
};
let accessToken: string;
let refreshToken: string;
JWTHelper.create(jwtData)
.then((result) => {
accessToken = result;
})
.catch((err) => {
console.log(err);
throw new InternalException("Failed accessToken creation", err);
});
let refreshCommand: CreateRefreshCommand = {
userId: id,
isFromPwa: req.isPWA,
};
let refreshToken = await RefreshCommandHandler.create(refreshCommand);
refreshToken = await RefreshCommandHandler.create(refreshCommand);
res.json({
accessToken,
@ -77,16 +105,39 @@ export async function refresh(req: Request, res: Response): Promise<any> {
throw new UnauthorizedRequestException("user not identified with token and refresh");
}
let accessToken = await JWTHelper.buildToken(tokenUserId);
let { id, username, mail, firstname, lastname } = await UserService.getById(tokenUserId);
let permissions = await UserPermissionService.getByUser(id);
let permissionStrings = permissions.map((e) => e.permission);
let permissionObject = PermissionHelper.convertToObject(permissionStrings);
let jwtData: JWTToken = {
userId: id,
mail: mail,
username: username,
firstname: firstname,
lastname: lastname,
permissions: permissionObject,
};
let accessToken: string;
let refreshToken: string;
JWTHelper.create(jwtData)
.then((result) => {
accessToken = result;
})
.catch((err) => {
throw new InternalException("Failed accessToken creation", err);
});
let refreshCommand: CreateRefreshCommand = {
userId: tokenUserId,
isFromPwa: req.isPWA,
userId: id,
};
let refreshToken = await RefreshCommandHandler.create(refreshCommand);
refreshToken = await RefreshCommandHandler.create(refreshCommand);
let removeToken: DeleteRefreshCommand = {
userId: tokenUserId,
userId: id,
token: refresh,
};
await RefreshCommandHandler.deleteByToken(removeToken);

View file

@ -7,30 +7,17 @@ import { CreateRefreshCommand } from "../command/refreshCommand";
import speakeasy from "speakeasy";
import UnauthorizedRequestException from "../exceptions/unauthorizedRequestException";
import QRCode from "qrcode";
import { CreateUserCommand } from "../command/user/user/userCommand";
import UserCommandHandler from "../command/user/user/userCommandHandler";
import { CreateInviteCommand, DeleteInviteCommand } from "../command/user/user/inviteCommand";
import InviteCommandHandler from "../command/user/user/inviteCommandHandler";
import { CreateUserCommand } from "../command/userCommand";
import UserCommandHandler from "../command/userCommandHandler";
import { CreateInviteCommand, DeleteInviteCommand } from "../command/inviteCommand";
import InviteCommandHandler from "../command/inviteCommandHandler";
import MailHelper from "../helpers/mailHelper";
import InviteService from "../service/user/inviteService";
import UserService from "../service/user/userService";
import InviteService from "../service/inviteService";
import UserService from "../service/userService";
import CustomRequestException from "../exceptions/customRequestException";
import { CLUB_NAME } from "../env.defaults";
import { CreateUserPermissionCommand } from "../command/user/user/userPermissionCommand";
import UserPermissionCommandHandler from "../command/user/user/userPermissionCommandHandler";
import InviteFactory from "../factory/admin/user/invite";
/**
* @description get all invites
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function getInvites(req: Request, res: Response): Promise<any> {
let invites = await InviteService.getAll();
res.json(InviteFactory.mapToBase(invites));
}
import { CreateUserPermissionCommand } from "../command/userPermissionCommand";
import UserPermissionCommandHandler from "../command/userPermissionCommandHandler";
/**
* @description start first user
@ -71,7 +58,8 @@ export async function inviteUser(req: Request, res: Response, isInvite: boolean
let token = await InviteCommandHandler.create(createInvite);
// sendmail
await MailHelper.sendMail(
let mailhelper = new MailHelper();
await mailhelper.sendMail(
mail,
`Email Bestätigung für Mitglieder Admin-Portal von ${CLUB_NAME}`,
`Öffne folgenden Link: ${origin}/${isInvite ? "invite" : "setup"}/verify?mail=${mail}&token=${token}`
@ -90,7 +78,7 @@ export async function verifyInvite(req: Request, res: Response): Promise<any> {
let mail = req.body.mail;
let token = req.body.token;
let { secret, username } = await InviteService.getByMailAndToken(mail, token);
let { secret } = await InviteService.getByMailAndToken(mail, token);
const url = `otpauth://totp/Mitgliederverwaltung ${CLUB_NAME}?secret=${secret}`;
@ -99,7 +87,6 @@ export async function verifyInvite(req: Request, res: Response): Promise<any> {
res.json({
dataUrl: result,
otp: secret,
username,
});
})
.catch((err) => {
@ -137,16 +124,43 @@ export async function finishInvite(req: Request, res: Response, grantAdmin: bool
lastname: lastname,
mail: mail,
secret: secret,
isOwner: grantAdmin,
};
let id = await UserCommandHandler.create(createUser);
let accessToken = await JWTHelper.buildToken(id);
if (grantAdmin) {
let createPermission: CreateUserPermissionCommand = {
permission: "*",
userId: id,
};
await UserPermissionCommandHandler.create(createPermission);
}
let jwtData: JWTToken = {
userId: id,
mail: mail,
username: username,
firstname: firstname,
lastname: lastname,
permissions: {
...(grantAdmin ? { admin: true } : {}),
},
};
let accessToken: string;
let refreshToken: string;
JWTHelper.create(jwtData)
.then((result) => {
accessToken = result;
})
.catch((err) => {
throw new InternalException("Failed accessToken creation", err);
});
let refreshCommand: CreateRefreshCommand = {
userId: id,
};
let refreshToken = await RefreshCommandHandler.create(refreshCommand);
refreshToken = await RefreshCommandHandler.create(refreshCommand);
let deleteInvite: DeleteInviteCommand = {
mail: mail,
@ -159,17 +173,3 @@ export async function finishInvite(req: Request, res: Response, grantAdmin: bool
refreshToken,
});
}
/**
* @description delete invite by mail
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function deleteInvite(req: Request, res: Response): Promise<any> {
const mail = req.params.mail;
await InviteCommandHandler.deleteByMail(mail);
res.sendStatus(204);
}

View file

@ -1,53 +0,0 @@
import { Request, Response } from "express";
import CalendarService from "../service/club/calendarService";
import CalendarTypeService from "../service/settings/calendarTypeService";
import { calendar } from "../entity/club/calendar";
import { createEvents } from "ics";
import moment from "moment";
import InternalException from "../exceptions/internalException";
import CalendarFactory from "../factory/admin/club/calendar";
import { CalendarHelper } from "../helpers/calendarHelper";
/**
* @description get all calendar items by types or nscdr
* @summary passphrase is passed as value pair like `type:passphrase`
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function getCalendarItemsByTypes(req: Request, res: Response): Promise<any> {
let types = Array.isArray(req.query.types) ? req.query.types : [req.query.types];
let nscdr = req.query.nscdr == "true";
let output = (req.query.output as "ics" | "json") ?? "ics";
if (output != "ics" && output != "json") {
throw new InternalException("set output query value to `ics` or `json` (defaults to `ics`)");
}
types = types.filter((t) => t);
let items: Array<calendar> = [];
if (types.length != 0) {
let typeIds = await CalendarTypeService.getByTypes((types as Array<string>).map((t) => t.split(":")[0]));
typeIds = typeIds.filter(
(ti) =>
ti.passphrase == null ||
ti.passphrase == "" ||
ti.passphrase == (types as Array<string>).find((t) => t.includes(ti.type)).split(":")[1]
);
items = await CalendarService.getByTypes(
typeIds.map((t) => t.id),
nscdr
);
} else {
items = await CalendarService.getByTypeNSCDR();
}
if (output == "json") {
res.json(CalendarFactory.mapToBase(items));
} else {
let { error, value } = CalendarHelper.buildICS(items);
res.type("ics").send(value);
}
}

View file

@ -1,128 +0,0 @@
import { Request, Response } from "express";
import { JWTHelper } from "../helpers/jwtHelper";
import { JWTToken } from "../type/jwtTypes";
import InternalException from "../exceptions/internalException";
import RefreshCommandHandler from "../command/refreshCommandHandler";
import { CreateRefreshCommand } from "../command/refreshCommand";
import speakeasy from "speakeasy";
import UnauthorizedRequestException from "../exceptions/unauthorizedRequestException";
import QRCode from "qrcode";
import { CreateResetCommand, DeleteResetCommand } from "../command/resetCommand";
import ResetCommandHandler from "../command/resetCommandHandler";
import MailHelper from "../helpers/mailHelper";
import ResetService from "../service/resetService";
import UserService from "../service/user/userService";
import { CLUB_NAME } from "../env.defaults";
import PermissionHelper from "../helpers/permissionHelper";
import RolePermissionService from "../service/user/rolePermissionService";
import UserPermissionService from "../service/user/userPermissionService";
import { UpdateUserSecretCommand } from "../command/user/user/userCommand";
import UserCommandHandler from "../command/user/user/userCommandHandler";
/**
* @description request totp reset
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function startReset(req: Request, res: Response): Promise<any> {
let origin = req.headers.origin;
let username = req.body.username;
let { mail } = await UserService.getByUsername(username);
var secret = speakeasy.generateSecret({ length: 20, name: `Mitgliederverwaltung ${CLUB_NAME}` });
let createReset: CreateResetCommand = {
username: username,
mail: mail,
secret: secret.base32,
};
let token = await ResetCommandHandler.create(createReset);
// sendmail
await MailHelper.sendMail(
mail,
`Email Bestätigung für Mitglieder Admin-Portal von ${CLUB_NAME}`,
`Öffne folgenden Link: ${origin}/reset/reset?mail=${mail}&token=${token}`
);
res.sendStatus(204);
}
/**
* @description verify reset link
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function verifyReset(req: Request, res: Response): Promise<any> {
let mail = req.body.mail;
let token = req.body.token;
let { secret } = await ResetService.getByMailAndToken(mail, token);
const url = `otpauth://totp/Mitgliederverwaltung ${CLUB_NAME}?secret=${secret}`;
QRCode.toDataURL(url)
.then((result) => {
res.json({
dataUrl: result,
otp: secret,
});
})
.catch((err) => {
throw new InternalException("QRCode not created", err);
});
}
/**
* @description finishReset
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function finishReset(req: Request, res: Response): Promise<any> {
let mail = req.body.mail;
let token = req.body.token;
let totp = req.body.totp;
let { secret, username } = await ResetService.getByMailAndToken(mail, token);
let valid = speakeasy.totp.verify({
secret: secret,
encoding: "base32",
token: totp,
window: 2,
});
if (!valid) {
throw new UnauthorizedRequestException("Token not valid or expired");
}
let { id } = await UserService.getByUsername(username);
let updateUserSecret: UpdateUserSecretCommand = {
id,
secret,
};
await UserCommandHandler.updateSecret(updateUserSecret);
let accessToken = await JWTHelper.buildToken(id);
let refreshCommand: CreateRefreshCommand = {
userId: id,
};
let refreshToken = await RefreshCommandHandler.create(refreshCommand);
let deleteReset: DeleteResetCommand = {
mail: mail,
token: token,
};
await ResetCommandHandler.deleteByTokenAndMail(deleteReset);
res.json({
accessToken,
refreshToken,
});
}

View file

@ -1,121 +0,0 @@
import { Request, Response } from "express";
import speakeasy from "speakeasy";
import QRCode from "qrcode";
import InternalException from "../exceptions/internalException";
import { CLUB_NAME } from "../env.defaults";
import UserService from "../service/user/userService";
import UserFactory from "../factory/admin/user/user";
import { TransferUserOwnerCommand, UpdateUserCommand } from "../command/user/user/userCommand";
import UserCommandHandler from "../command/user/user/userCommandHandler";
import ForbiddenRequestException from "../exceptions/forbiddenRequestException";
/**
* @description get my by id
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function getMeById(req: Request, res: Response): Promise<any> {
const id = parseInt(req.userId);
let user = await UserService.getById(id);
res.json(UserFactory.mapToSingle(user));
}
/**
* @description get my totp
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function getMyTotp(req: Request, res: Response): Promise<any> {
const userId = parseInt(req.userId);
let { secret } = await UserService.getById(userId);
const url = `otpauth://totp/Mitgliederverwaltung ${CLUB_NAME}?secret=${secret}`;
QRCode.toDataURL(url)
.then((result) => {
res.json({
dataUrl: result,
otp: secret,
});
})
.catch((err) => {
throw new InternalException("QRCode not created", err);
});
}
/**
* @description verify my totp
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function verifyMyTotp(req: Request, res: Response): Promise<any> {
const userId = parseInt(req.userId);
let totp = req.body.totp;
let { secret } = await UserService.getById(userId);
let valid = speakeasy.totp.verify({
secret: secret,
encoding: "base32",
token: totp,
window: 2,
});
if (!valid) {
throw new InternalException("Token not valid or expired");
}
res.sendStatus(204);
}
/**
* @description transferOwnership
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function transferOwnership(req: Request, res: Response): Promise<any> {
const userId = parseInt(req.userId);
let toId = req.body.toId;
let { isOwner } = await UserService.getById(userId);
if (!isOwner) {
throw new ForbiddenRequestException("Action only allowed to owner.");
}
let transfer: TransferUserOwnerCommand = {
toId: toId,
fromId: userId,
};
await UserCommandHandler.transferOwnership(transfer);
res.sendStatus(204);
}
/**
* @description update my data
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function updateMe(req: Request, res: Response): Promise<any> {
const id = parseInt(req.userId);
let mail = req.body.mail;
let firstname = req.body.firstname;
let lastname = req.body.lastname;
let username = req.body.username;
let updateUser: UpdateUserCommand = {
id: id,
mail: mail,
firstname: firstname,
lastname: lastname,
username: username,
};
await UserCommandHandler.update(updateUser);
res.sendStatus(204);
}

View file

@ -1,20 +1,20 @@
import "dotenv/config";
import "reflect-metadata";
import { DataSource } from "typeorm";
import { DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME, DB_TYPE, DB_PORT } from "./env.defaults";
import { DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME, DB_TYPE } from "./env.defaults";
import { user } from "./entity/user/user";
import { user } from "./entity/user";
import { refresh } from "./entity/refresh";
import { invite } from "./entity/user/invite";
import { userPermission } from "./entity/user/user_permission";
import { role } from "./entity/user/role";
import { rolePermission } from "./entity/user/role_permission";
import { award } from "./entity/settings/award";
import { communication } from "./entity/club/member/communication";
import { communicationType } from "./entity/settings/communicationType";
import { executivePosition } from "./entity/settings/executivePosition";
import { membershipStatus } from "./entity/settings/membershipStatus";
import { qualification } from "./entity/settings/qualification";
import { invite } from "./entity/invite";
import { userPermission } from "./entity/user_permission";
import { role } from "./entity/role";
import { rolePermission } from "./entity/role_permission";
import { award } from "./entity/award";
import { communication } from "./entity/communication";
import { communicationType } from "./entity/communicationType";
import { executivePosition } from "./entity/executivePosition";
import { membershipStatus } from "./entity/membershipStatus";
import { qualification } from "./entity/qualification";
import { Initial1724317398939 } from "./migrations/1724317398939-initial";
import { RefreshPrimaryChange1724573307851 } from "./migrations/1724573307851-refreshPrimaryChange";
@ -22,57 +22,18 @@ import { Invite1724579024939 } from "./migrations/1724579024939-invite";
import { Permissions1724661484664 } from "./migrations/1724661484664-permissions";
import { RolePermission1724771491085 } from "./migrations/1724771491085-role_permission";
import { MemberBaseData1725435669492 } from "./migrations/1725435669492-member_base_data";
import { member } from "./entity/club/member/member";
import { memberAwards } from "./entity/club/member/memberAwards";
import { memberExecutivePositions } from "./entity/club/member/memberExecutivePositions";
import { memberQualifications } from "./entity/club/member/memberQualifications";
import { membership } from "./entity/club/member/membership";
import { member } from "./entity/member";
import { memberAwards } from "./entity/memberAwards";
import { memberExecutivePositions } from "./entity/memberExecutivePositions";
import { memberQualifications } from "./entity/memberQualifications";
import { membership } from "./entity/membership";
import { Memberdata1726301836849 } from "./migrations/1726301836849-memberdata";
import { CommunicationFields1727439800630 } from "./migrations/1727439800630-communicationFields";
import { Ownership1728313041449 } from "./migrations/1728313041449-ownership";
import { protocol } from "./entity/club/protocol/protocol";
import { protocolAgenda } from "./entity/club/protocol/protocolAgenda";
import { protocolDecision } from "./entity/club/protocol/protocolDecision";
import { protocolPresence } from "./entity/club/protocol/protocolPresence";
import { protocolVoting } from "./entity/club/protocol/protocolVoting";
import { protocolPrintout } from "./entity/club/protocol/protocolPrintout";
import { Protocol1729347911107 } from "./migrations/1729347911107-protocol";
import { calendar } from "./entity/club/calendar";
import { calendarType } from "./entity/settings/calendarType";
import { Calendar1729947763295 } from "./migrations/1729947763295-calendar";
import { reset } from "./entity/reset";
import { ResetToken1732358596823 } from "./migrations/1732358596823-resetToken";
import { SMSAlarming1732696919191 } from "./migrations/1732696919191-SMSAlarming";
import { SecuringCalendarType1733249553766 } from "./migrations/1733249553766-securingCalendarType";
import { query } from "./entity/settings/query";
import { QueryStore1734187754677 } from "./migrations/1734187754677-queryStore";
import { memberView } from "./views/memberView";
import { memberExecutivePositionsView } from "./views/memberExecutivePositionView";
import { memberQualificationsView } from "./views/memberQualificationsView";
import { membershipView } from "./views/membershipsView";
import { MemberDataViews1734520998539 } from "./migrations/1734520998539-memberDataViews";
import { template } from "./entity/settings/template";
import { Template1734854680201 } from "./migrations/1734854680201-template";
import { templateUsage } from "./entity/settings/templateUsage";
import { TemplateUsage1734949173739 } from "./migrations/1734949173739-templateUsage";
import { newsletter } from "./entity/club/newsletter/newsletter";
import { newsletterDates } from "./entity/club/newsletter/newsletterDates";
import { newsletterRecipients } from "./entity/club/newsletter/newsletterRecipients";
import { Newsletter1735118780511 } from "./migrations/1735118780511-newsletter";
import { newsletterConfig } from "./entity/settings/newsletterConfig";
import { NewsletterConfig1735207446910 } from "./migrations/1735207446910-newsletterConfig";
import { InternalId1735822722235 } from "./migrations/1735822722235-internalId";
import { PostalCode1735927918979 } from "./migrations/1735927918979-postalCode";
import { ProtocolAbsent1736072179716 } from "./migrations/1736072179716-protocolAbsent";
import { Memberlist1736079005086 } from "./migrations/1736079005086-memberlist";
import { ExtendViewValues1736084198860 } from "./migrations/1736084198860-extendViewValues";
import { FinishInternalIdTransfer1736505324488 } from "./migrations/1736505324488-finishInternalIdTransfer";
import { ProtocolPresenceExcuse1737287798828 } from "./migrations/1737287798828-protocolPresenceExcuse";
const dataSource = new DataSource({
type: DB_TYPE as any,
host: process.env.NODE_ENV || process.env.DBMODE ? "localhost" : DB_HOST,
port: DB_PORT,
port: 3306,
username: DB_USERNAME,
password: DB_PASSWORD,
database: DB_NAME,
@ -83,7 +44,6 @@ const dataSource = new DataSource({
user,
refresh,
invite,
reset,
userPermission,
role,
rolePermission,
@ -98,25 +58,6 @@ const dataSource = new DataSource({
memberExecutivePositions,
memberQualifications,
membership,
protocol,
protocolAgenda,
protocolDecision,
protocolPresence,
protocolVoting,
protocolPrintout,
calendar,
calendarType,
query,
template,
templateUsage,
newsletter,
newsletterDates,
newsletterRecipients,
newsletterConfig,
memberView,
memberExecutivePositionsView,
memberQualificationsView,
membershipView,
],
migrations: [
Initial1724317398939,
@ -127,25 +68,6 @@ const dataSource = new DataSource({
MemberBaseData1725435669492,
Memberdata1726301836849,
CommunicationFields1727439800630,
Ownership1728313041449,
Protocol1729347911107,
Calendar1729947763295,
ResetToken1732358596823,
SMSAlarming1732696919191,
SecuringCalendarType1733249553766,
QueryStore1734187754677,
MemberDataViews1734520998539,
Template1734854680201,
TemplateUsage1734949173739,
Newsletter1735118780511,
NewsletterConfig1735207446910,
InternalId1735822722235,
PostalCode1735927918979,
ProtocolAbsent1736072179716,
Memberlist1736079005086,
ExtendViewValues1736084198860,
FinishInternalIdTransfer1736505324488,
ProtocolPresenceExcuse1737287798828,
],
migrationsRun: true,
migrationsTransactionMode: "each",

View file

@ -1,13 +0,0 @@
import { member } from "../entity/club/member/member";
import { protocolAgenda } from "../entity/club/protocol/protocolAgenda";
import { protocolDecision } from "../entity/club/protocol/protocolDecision";
import { protocolVoting } from "../entity/club/protocol/protocolVoting";
export const memberlistDemoData: { member: Array<Partial<member>> } = {
member: [
{
firstname: "Julian",
lastname: "Krauser",
},
]
}

View file

@ -1,72 +0,0 @@
import { calendar } from "../entity/club/calendar";
import { member } from "../entity/club/member/member";
import { Salutation } from "../enums/salutation";
export const newsletterDemoData: {
title: string;
description: string;
newsletterTitle: string;
newsletterText: string;
newsletterSignatur: string;
dates: Array<
Partial<
calendar & {
formattedStarttime: string;
formattedFullStarttime: string;
formattedEndtime: string;
formattedFullEndtime: string;
}
>
>;
recipient: Partial<member & { street: string; streetNumber: string; streetNumberAdd: string }>;
} = {
title: "Beispiel Newsletter Daten",
description: "Zusammenfassung der Demodaten.",
newsletterTitle: "<h1>Sehr geehrtes Feuerwehrmitglied</h1>",
newsletterText: "<p>zu folgenden Terminen möchten wir recht herzlich zur Teilnahme einladen:</p>",
newsletterSignatur: "<p>Mit freundlichen Grüßen</p><p>...</p>",
dates: [
{
title: "Termin 1",
content: "<p>Beschreibung eines Termins</p>",
starttime: new Date(),
formattedStarttime: new Date().toLocaleDateString("de-DE", {
weekday: "long",
day: "2-digit",
month: "long",
}),
formattedFullStarttime: new Date().toLocaleDateString("de-DE", {
weekday: "long",
day: "2-digit",
month: "long",
year: "numeric",
hour: "2-digit",
minute: "2-digit",
}),
endtime: new Date(),
formattedEndtime: new Date().toLocaleDateString("de-DE", {
weekday: "long",
day: "2-digit",
month: "long",
}),
formattedFullEndtime: new Date().toLocaleDateString("de-DE", {
weekday: "long",
day: "2-digit",
month: "long",
year: "numeric",
hour: "2-digit",
minute: "2-digit",
}),
location: "Feuerwehrhaus",
},
],
recipient: {
firstname: "Julian",
lastname: "Krauser",
salutation: Salutation.sir,
nameaffix: "",
street: "Straße",
streetNumber: "Hausnummer",
streetNumberAdd: "Adresszusatz",
},
};

View file

@ -1,58 +0,0 @@
import { member } from "../entity/club/member/member";
import { protocolAgenda } from "../entity/club/protocol/protocolAgenda";
import { protocolDecision } from "../entity/club/protocol/protocolDecision";
import { protocolVoting } from "../entity/club/protocol/protocolVoting";
export const protocolDemoData: {
title: string;
summary: string;
iteration: number;
date: string;
start: string;
end: string;
agenda: Array<Partial<protocolAgenda>>;
decisions: Array<Partial<protocolDecision>>;
presence: Array<Partial<member>>;
absent: Array<Partial<member>>;
votings: Array<Partial<protocolVoting>>;
} = {
title: "Beispiel Protokoll Daten",
summary: "Zusammenfassung der Demodaten.",
iteration: 1,
date: new Date().toLocaleDateString("de-DE", {
weekday: "long",
day: "2-digit",
month: "2-digit",
year: "numeric",
}),
start: "19:00:00",
end: "21:00:00",
agenda: [
{
topic: "Protokoll-TOP",
context: "Inhalt des Punktes",
},
],
decisions: [
{
topic: "Entscheidung yz",
context: "Inhalt der Entscheidung",
},
],
presence: [
{
firstname: "Julian",
lastname: "Krauser",
},
],
absent: [],
votings: [
{
topic: "Abstimmung xy",
context: "Inhalt der Abstimmung",
favour: 1,
abstain: 2,
against: 3,
},
],
};

View file

@ -1,5 +1,5 @@
import { Column, Entity, OneToMany, PrimaryColumn } from "typeorm";
import { memberAwards } from "../club/member/memberAwards";
import { memberAwards } from "./memberAwards";
@Entity()
export class award {

Some files were not shown because too many files have changed in this diff Show more