Compare commits
144 commits
anton/expo
...
main
Author | SHA1 | Date | |
---|---|---|---|
3e256dc2f7 | |||
bf5aec351c | |||
0bbe22e9ae | |||
9734149848 | |||
28e05c70a9 | |||
1116b50773 | |||
8b59f3b7a8 | |||
2d8e8a2e42 | |||
eb8f3fef3e | |||
b5509ba162 | |||
4dd6fa6d8a | |||
a4b26013a7 | |||
c803c2a583 | |||
ba03b6f097 | |||
e738be4e13 | |||
c9b8c3090d | |||
a2cc408e85 | |||
d206d7a77c | |||
03036c8b77 | |||
1c6c123142 | |||
e1f6b36336 | |||
916a6da4a0 | |||
b1e949dce2 | |||
69134b210a | |||
0f7516bd3d | |||
632a8290ac | |||
c173f917e3 | |||
55d4a952c3 | |||
03cc0f02b7 | |||
a968c6af25 | |||
8ba12b752c | |||
ad5f624d5d | |||
b547c2bbca | |||
25a83af0b7 | |||
00d98874f5 | |||
bd355cff1f | |||
d683bcb4c1 | |||
91217d1e6e | |||
84e2ec72ac | |||
5d3f8ea46a | |||
161a9dc51c | |||
455589e2b5 | |||
f16c5d91ba | |||
b92cca773e | |||
dd72f37856 | |||
83e145a93b | |||
14677d2030 | |||
b68e546788 | |||
9afb205da5 | |||
0d2c7dd7f1 | |||
cfefcd81d7 | |||
b5760202f7 | |||
43c18cdc7b | |||
f3aae6a017 | |||
dc049c7e85 | |||
e693bd9aa3 | |||
728c4e05fa | |||
5f827fb177 | |||
5a59a63e4a | |||
d7b92aedc1 | |||
dad54c97ed | |||
6dcd650cad | |||
4180da5749 | |||
7d36ed3121 | |||
01ce3fdd39 | |||
e9b29f8acf | |||
020ae4a939 | |||
71480ecc97 | |||
6cb8ca0a12 | |||
5f18e614be | |||
160d82459d | |||
98477eafde | |||
4385b6dc34 | |||
f46b370184 | |||
98afcf3b40 | |||
d102512c98 | |||
e15507dce8 | |||
b4cdf4899a | |||
6b7b5a99d6 | |||
7ca51c3670 | |||
f4f293846b | |||
a718f74d24 | |||
52a1f34162 | |||
ac5a7e7427 | |||
7497787ae4 | |||
2518a1046f | |||
63a0a60b12 | |||
ee0d6ddcce | |||
6fd2091a7e | |||
7dbacfe795 | |||
4007000c60 | |||
7810f05513 | |||
8f49533fcb | |||
597feef9ef | |||
74a496a5e0 | |||
f05adbd430 | |||
8b7bbf8edd | |||
9944fb931a | |||
f58032e1e5 | |||
a24a9cdc7f | |||
5c68f0c54f | |||
717de68f4e | |||
1d73a15227 | |||
4fbe108e3d | |||
9dfc55d7f6 | |||
fa411027e9 | |||
c66c847ec1 | |||
d1cf9f4c66 | |||
0a5b5dc7b5 | |||
19655eca00 | |||
fa1eb6a5f0 | |||
48a8d1fb45 | |||
6c7adb01cb | |||
273745f830 | |||
ea227433e6 | |||
f87c7b4a7c | |||
ba3c763a09 | |||
e175d30156 | |||
7b6528ee96 | |||
98eb870385 | |||
1d9919d520 | |||
91c3fde688 | |||
bd19e49a8b | |||
2822bc02ff | |||
848a9e86fc | |||
8c597fd68d | |||
136da08b70 | |||
bf701163d6 | |||
e7b8257336 | |||
3907482b06 | |||
a112805fbb | |||
624408c973 | |||
6f72c27d20 | |||
9da2a98f55 | |||
58213923e5 | |||
da219eb5f4 | |||
e1ad491e68 | |||
5f434c943e | |||
b9b258a1f6 | |||
475a13ce36 | |||
dd74005043 | |||
e2b46becf0 | |||
edc35f2f87 | |||
5c4e521bd8 |
296 changed files with 10504 additions and 715 deletions
6
.dockerignore
Normal file
6
.dockerignore
Normal file
|
@ -0,0 +1,6 @@
|
|||
# NodeJs
|
||||
node_modules/
|
||||
dist/
|
||||
.git/
|
||||
files/
|
||||
.env
|
|
@ -1,4 +1,5 @@
|
|||
DB_TYPE = (mysql|sqlite|...)
|
||||
DB_PORT = number
|
||||
DB_HOST = database_host
|
||||
DB_NAME = database_name
|
||||
DB_USERNAME = database_username
|
||||
|
@ -9,6 +10,7 @@ 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
|
||||
|
@ -16,4 +18,5 @@ MAIL_HOST = mail_hoststring
|
|||
MAIL_PORT = mail_portnumber
|
||||
MAIL_SECURE (true|false) // true for port 465, fals for other ports
|
||||
|
||||
CLUB_NAME = clubname
|
||||
CLUB_NAME = clubname
|
||||
CLUB_WEBSITE = https://my-club-website-url
|
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -130,3 +130,6 @@ dist
|
|||
.yarn/install-state.gz
|
||||
.pnp.*
|
||||
|
||||
files
|
||||
|
||||
.idea
|
46
Dockerfile
Normal file
46
Dockerfile
Normal file
|
@ -0,0 +1,46 @@
|
|||
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
102
README.md
|
@ -1,30 +1,92 @@
|
|||
# member-administration-server
|
||||
# ff-admin-server
|
||||
|
||||
Memberadministration
|
||||
Administration für Feuerwehren und Vereine (Backend).
|
||||
|
||||
Authentications is realized via JWT-Tokens. The server is able to send Mails to the members.
|
||||
Login is possible via Username and TOTP.
|
||||
## 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).
|
||||
|
||||
## Installation
|
||||
|
||||
### Requirements
|
||||
Das Image exposed nur den Port 5000. Die Env-Variable SERVER_PORT kann nur im lokal ausführenden dev-Kontext verwendet werden.
|
||||
|
||||
1. MySql Database
|
||||
2. Access to the internet for sending Mails
|
||||
### Docker Compose Setup
|
||||
|
||||
### Configuration
|
||||
Um den Container hochzufahren, erstellen Sie eine `docker-compose.yml` Datei mit folgendem Inhalt:
|
||||
|
||||
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
|
||||
```yaml
|
||||
version: "3"
|
||||
|
||||
## Testing
|
||||
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
|
||||
|
||||
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)
|
||||
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.
|
||||
|
|
1240
package-lock.json
generated
1240
package-lock.json
generated
File diff suppressed because it is too large
Load diff
11
package.json
11
package.json
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "member-administration-server",
|
||||
"version": "0.0.2",
|
||||
"name": "ff-admin-server",
|
||||
"version": "1.1.1",
|
||||
"description": "Feuerwehr/Verein Mitgliederverwaltung Server",
|
||||
"main": "dist/index.js",
|
||||
"scripts": {
|
||||
|
@ -16,7 +16,7 @@
|
|||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://forgejo.jk-effects.cloud/Ehrenamt/member-administration-server.git"
|
||||
"url": "https://forgejo.jk-effects.cloud/Ehrenamt/ff-admin-server.git"
|
||||
},
|
||||
"keywords": [
|
||||
"Feuerwehr"
|
||||
|
@ -27,11 +27,16 @@
|
|||
"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",
|
||||
|
|
24
src/command/club/calendar/calendarCommand.ts
Normal file
24
src/command/club/calendar/calendarCommand.ts
Normal file
|
@ -0,0 +1,24 @@
|
|||
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;
|
||||
}
|
96
src/command/club/calendar/calendarCommandHandler.ts
Normal file
96
src/command/club/calendar/calendarCommandHandler.ts
Normal file
|
@ -0,0 +1,96 @@
|
|||
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);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,7 +1,9 @@
|
|||
export interface CreateCommunicationCommand {
|
||||
preferred: boolean;
|
||||
isSMSAlarming: boolean;
|
||||
mobile: string;
|
||||
email: string;
|
||||
postalCode: string;
|
||||
city: string;
|
||||
street: string;
|
||||
streetNumber: number;
|
||||
|
@ -13,8 +15,10 @@ export interface CreateCommunicationCommand {
|
|||
export interface UpdateCommunicationCommand {
|
||||
id: number;
|
||||
preferred: boolean;
|
||||
isSMSAlarming: boolean;
|
||||
mobile: string;
|
||||
email: string;
|
||||
postalCode: string;
|
||||
city: string;
|
||||
street: string;
|
||||
streetNumber: number;
|
|
@ -1,8 +1,6 @@
|
|||
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 { dataSource } from "../../../data-source";
|
||||
import { communication } from "../../../entity/club/member/communication";
|
||||
import InternalException from "../../../exceptions/internalException";
|
||||
import {
|
||||
CreateCommunicationCommand,
|
||||
DeleteCommunicationCommand,
|
||||
|
@ -12,7 +10,7 @@ import {
|
|||
export default abstract class CommunicationCommandHandler {
|
||||
/**
|
||||
* @description create communication
|
||||
* @param CreateCommunicationCommand
|
||||
* @param {CreateCommunicationCommand} createCommunication
|
||||
* @returns {Promise<number>}
|
||||
*/
|
||||
static async create(createCommunication: CreateCommunicationCommand): Promise<number> {
|
||||
|
@ -22,22 +20,16 @@ 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,
|
||||
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(),
|
||||
memberId: createCommunication.memberId,
|
||||
typeId: createCommunication.typeId,
|
||||
})
|
||||
.execute()
|
||||
.then((result) => {
|
||||
|
@ -50,7 +42,7 @@ export default abstract class CommunicationCommandHandler {
|
|||
|
||||
/**
|
||||
* @description update communication
|
||||
* @param UpdateCommunicationCommand
|
||||
* @param {UpdateCommunicationCommand} updateCommunication
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
static async update(updateCommunication: UpdateCommunicationCommand): Promise<void> {
|
||||
|
@ -59,8 +51,10 @@ 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,
|
||||
|
@ -77,16 +71,16 @@ export default abstract class CommunicationCommandHandler {
|
|||
|
||||
/**
|
||||
* @description delete communication
|
||||
* @param DeleteCommunicationCommand
|
||||
* @param {DeleteCommunicationCommand} deleteCommunication
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
static async delete(deletCommunication: DeleteCommunicationCommand): Promise<void> {
|
||||
static async delete(deleteCommunication: DeleteCommunicationCommand): Promise<void> {
|
||||
return await dataSource
|
||||
.createQueryBuilder()
|
||||
.delete()
|
||||
.from(communication)
|
||||
.where("id = :id", { id: deletCommunication.id })
|
||||
.andWhere("memberId = :memberId", { memberId: deletCommunication.memberId })
|
||||
.where("id = :id", { id: deleteCommunication.id })
|
||||
.andWhere("memberId = :memberId", { memberId: deleteCommunication.memberId })
|
||||
.execute()
|
||||
.then(() => {})
|
||||
.catch((err) => {
|
|
@ -1,14 +1,12 @@
|
|||
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 { dataSource } from "../../../data-source";
|
||||
import { memberAwards } from "../../../entity/club/member/memberAwards";
|
||||
import InternalException from "../../../exceptions/internalException";
|
||||
import { CreateMemberAwardCommand, DeleteMemberAwardCommand, UpdateMemberAwardCommand } from "./memberAwardCommand";
|
||||
|
||||
export default abstract class MemberAwardCommandHandler {
|
||||
/**
|
||||
* @description create memberAward
|
||||
* @param CreateMemberAwardCommand
|
||||
* @param {CreateMemberAwardCommand} createMemberAward
|
||||
* @returns {Promise<number>}
|
||||
*/
|
||||
static async create(createMemberAward: CreateMemberAwardCommand): Promise<number> {
|
||||
|
@ -20,16 +18,8 @@ export default abstract class MemberAwardCommandHandler {
|
|||
given: createMemberAward.given,
|
||||
note: createMemberAward.note,
|
||||
date: createMemberAward.date,
|
||||
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(),
|
||||
memberId: createMemberAward.memberId,
|
||||
awardId: createMemberAward.awardId,
|
||||
})
|
||||
.execute()
|
||||
.then((result) => {
|
||||
|
@ -42,7 +32,7 @@ export default abstract class MemberAwardCommandHandler {
|
|||
|
||||
/**
|
||||
* @description update memberAward
|
||||
* @param UpdateMemberAwardCommand
|
||||
* @param {UpdateMemberAwardCommand} updateMemberAward
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
static async update(updateMemberAward: UpdateMemberAwardCommand): Promise<void> {
|
||||
|
@ -53,11 +43,7 @@ export default abstract class MemberAwardCommandHandler {
|
|||
given: updateMemberAward.given,
|
||||
note: updateMemberAward.note,
|
||||
date: updateMemberAward.date,
|
||||
award: await dataSource
|
||||
.getRepository(award)
|
||||
.createQueryBuilder("award")
|
||||
.where("id = :id", { id: updateMemberAward.awardId })
|
||||
.getOneOrFail(),
|
||||
award: updateMemberAward.awardId,
|
||||
})
|
||||
.where("id = :id", { id: updateMemberAward.id })
|
||||
.andWhere("memberId = :memberId", { memberId: updateMemberAward.memberId })
|
||||
|
@ -70,16 +56,16 @@ export default abstract class MemberAwardCommandHandler {
|
|||
|
||||
/**
|
||||
* @description delete memberAward
|
||||
* @param DeleteMemberAwardCommand
|
||||
* @param {DeleteMemberAwardCommand} deleteMemberAward
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
static async delete(deletMemberAward: DeleteMemberAwardCommand): Promise<void> {
|
||||
static async delete(deleteMemberAward: DeleteMemberAwardCommand): Promise<void> {
|
||||
return await dataSource
|
||||
.createQueryBuilder()
|
||||
.delete()
|
||||
.from(memberAwards)
|
||||
.where("id = :id", { id: deletMemberAward.id })
|
||||
.andWhere("memberId = :memberId", { memberId: deletMemberAward.memberId })
|
||||
.where("id = :id", { id: deleteMemberAward.id })
|
||||
.andWhere("memberId = :memberId", { memberId: deleteMemberAward.memberId })
|
||||
.execute()
|
||||
.then(() => {})
|
||||
.catch((err) => {
|
|
@ -1,4 +1,4 @@
|
|||
import { Salutation } from "../enums/salutation";
|
||||
import { Salutation } from "../../../enums/salutation";
|
||||
|
||||
export interface CreateMemberCommand {
|
||||
salutation: Salutation;
|
||||
|
@ -6,6 +6,7 @@ export interface CreateMemberCommand {
|
|||
lastname: string;
|
||||
nameaffix: string;
|
||||
birthdate: Date;
|
||||
internalId?: string;
|
||||
}
|
||||
|
||||
export interface UpdateMemberCommand {
|
||||
|
@ -15,6 +16,7 @@ export interface UpdateMemberCommand {
|
|||
lastname: string;
|
||||
nameaffix: string;
|
||||
birthdate: Date;
|
||||
internalId?: string;
|
||||
}
|
||||
|
||||
export interface UpdateMemberNewsletterCommand {
|
|
@ -1,8 +1,7 @@
|
|||
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 { dataSource } from "../../../data-source";
|
||||
import { communication } from "../../../entity/club/member/communication";
|
||||
import { member } from "../../../entity/club/member/member";
|
||||
import InternalException from "../../../exceptions/internalException";
|
||||
import {
|
||||
CreateMemberCommand,
|
||||
DeleteMemberCommand,
|
||||
|
@ -13,7 +12,7 @@ import {
|
|||
export default abstract class MemberCommandHandler {
|
||||
/**
|
||||
* @description create member
|
||||
* @param CreateMemberCommand
|
||||
* @param {CreateMemberCommand} createMember
|
||||
* @returns {Promise<number>}
|
||||
*/
|
||||
static async create(createMember: CreateMemberCommand): Promise<number> {
|
||||
|
@ -27,6 +26,7 @@ export default abstract class MemberCommandHandler {
|
|||
lastname: createMember.lastname,
|
||||
nameaffix: createMember.nameaffix,
|
||||
birthdate: createMember.birthdate,
|
||||
internalId: createMember.internalId,
|
||||
})
|
||||
.execute()
|
||||
.then((result) => {
|
||||
|
@ -39,11 +39,10 @@ export default abstract class MemberCommandHandler {
|
|||
|
||||
/**
|
||||
* @description update member
|
||||
* @param UpdateMemberCommand
|
||||
* @param {UpdateMemberCommand} updateMember
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
static async update(updateMember: UpdateMemberCommand): Promise<void> {
|
||||
console.log(updateMember);
|
||||
return await dataSource
|
||||
.createQueryBuilder()
|
||||
.update(member)
|
||||
|
@ -53,6 +52,7 @@ 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,11 +64,10 @@ export default abstract class MemberCommandHandler {
|
|||
|
||||
/**
|
||||
* @description update member newsletter
|
||||
* @param UpdateMemberCommand
|
||||
* @param {UpdateMemberCommand} updateMember
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
static async updateNewsletter(updateMember: UpdateMemberNewsletterCommand): Promise<void> {
|
||||
console.log(updateMember);
|
||||
return await dataSource
|
||||
.createQueryBuilder()
|
||||
.update(member)
|
||||
|
@ -88,9 +87,29 @@ 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
|
||||
* @param {DeleteMemberCommand} deleteMember
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
static async delete(deleteMember: DeleteMemberCommand): Promise<void> {
|
|
@ -1,8 +1,6 @@
|
|||
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 { dataSource } from "../../../data-source";
|
||||
import { memberExecutivePositions } from "../../../entity/club/member/memberExecutivePositions";
|
||||
import InternalException from "../../../exceptions/internalException";
|
||||
import {
|
||||
CreateMemberExecutivePositionCommand,
|
||||
DeleteMemberExecutivePositionCommand,
|
||||
|
@ -12,7 +10,7 @@ import {
|
|||
export default abstract class MemberExecutivePositionCommandHandler {
|
||||
/**
|
||||
* @description create memberExecutivePosition
|
||||
* @param CreateMemberExecutivePositionCommand
|
||||
* @param {CreateMemberExecutivePositionCommand} createMemberExecutivePosition
|
||||
* @returns {Promise<number>}
|
||||
*/
|
||||
static async create(createMemberExecutivePosition: CreateMemberExecutivePositionCommand): Promise<number> {
|
||||
|
@ -24,16 +22,8 @@ export default abstract class MemberExecutivePositionCommandHandler {
|
|||
note: createMemberExecutivePosition.note,
|
||||
start: createMemberExecutivePosition.start,
|
||||
end: createMemberExecutivePosition.end,
|
||||
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(),
|
||||
memberId: createMemberExecutivePosition.memberId,
|
||||
executivePositionId: createMemberExecutivePosition.executivePositionId,
|
||||
})
|
||||
.execute()
|
||||
.then((result) => {
|
||||
|
@ -46,7 +36,7 @@ export default abstract class MemberExecutivePositionCommandHandler {
|
|||
|
||||
/**
|
||||
* @description update memberExecutivePosition
|
||||
* @param UpdateMemberExecutivePositionCommand
|
||||
* @param {UpdateMemberExecutivePositionCommand} updateMemberExecutivePosition
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
static async update(updateMemberExecutivePosition: UpdateMemberExecutivePositionCommand): Promise<void> {
|
||||
|
@ -57,11 +47,7 @@ export default abstract class MemberExecutivePositionCommandHandler {
|
|||
note: updateMemberExecutivePosition.note,
|
||||
start: updateMemberExecutivePosition.start,
|
||||
end: updateMemberExecutivePosition.end,
|
||||
executivePosition: await dataSource
|
||||
.getRepository(executivePosition)
|
||||
.createQueryBuilder("executivePosition")
|
||||
.where("id = :id", { id: updateMemberExecutivePosition.executivePositionId })
|
||||
.getOneOrFail(),
|
||||
executivePositionId: updateMemberExecutivePosition.executivePositionId,
|
||||
})
|
||||
.where("id = :id", { id: updateMemberExecutivePosition.id })
|
||||
.andWhere("memberId = :memberId", { memberId: updateMemberExecutivePosition.memberId })
|
||||
|
@ -74,16 +60,16 @@ export default abstract class MemberExecutivePositionCommandHandler {
|
|||
|
||||
/**
|
||||
* @description delete memberExecutivePosition
|
||||
* @param DeleteMemberExecutivePositionCommand
|
||||
* @param {DeleteMemberExecutivePositionCommand} deleteMemberExecutivePosition
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
static async delete(deletMemberExecutivePosition: DeleteMemberExecutivePositionCommand): Promise<void> {
|
||||
static async delete(deleteMemberExecutivePosition: DeleteMemberExecutivePositionCommand): Promise<void> {
|
||||
return await dataSource
|
||||
.createQueryBuilder()
|
||||
.delete()
|
||||
.from(memberExecutivePositions)
|
||||
.where("id = :id", { id: deletMemberExecutivePosition.id })
|
||||
.andWhere("memberId = :memberId", { memberId: deletMemberExecutivePosition.memberId })
|
||||
.where("id = :id", { id: deleteMemberExecutivePosition.id })
|
||||
.andWhere("memberId = :memberId", { memberId: deleteMemberExecutivePosition.memberId })
|
||||
.execute()
|
||||
.then(() => {})
|
||||
.catch((err) => {
|
|
@ -1,8 +1,6 @@
|
|||
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 { dataSource } from "../../../data-source";
|
||||
import { memberQualifications } from "../../../entity/club/member/memberQualifications";
|
||||
import InternalException from "../../../exceptions/internalException";
|
||||
import {
|
||||
CreateMemberQualificationCommand,
|
||||
DeleteMemberQualificationCommand,
|
||||
|
@ -12,7 +10,7 @@ import {
|
|||
export default abstract class MemberQualificationCommandHandler {
|
||||
/**
|
||||
* @description create memberQualification
|
||||
* @param CreateMemberQualificationCommand
|
||||
* @param {CreateMemberQualificationCommand} createMemberQualification
|
||||
* @returns {Promise<number>}
|
||||
*/
|
||||
static async create(createMemberQualification: CreateMemberQualificationCommand): Promise<number> {
|
||||
|
@ -23,16 +21,8 @@ export default abstract class MemberQualificationCommandHandler {
|
|||
.values({
|
||||
note: createMemberQualification.note,
|
||||
start: createMemberQualification.start,
|
||||
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(),
|
||||
memberId: createMemberQualification.memberId,
|
||||
qualificationId: createMemberQualification.qualificationId,
|
||||
})
|
||||
.execute()
|
||||
.then((result) => {
|
||||
|
@ -45,7 +35,7 @@ export default abstract class MemberQualificationCommandHandler {
|
|||
|
||||
/**
|
||||
* @description update memberQualification
|
||||
* @param UpdateMemberQualificationCommand
|
||||
* @param {UpdateMemberQualificationCommand} updateMemberQualification
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
static async update(updateMemberQualification: UpdateMemberQualificationCommand): Promise<void> {
|
||||
|
@ -57,11 +47,7 @@ export default abstract class MemberQualificationCommandHandler {
|
|||
start: updateMemberQualification.start,
|
||||
end: updateMemberQualification.end,
|
||||
terminationReason: updateMemberQualification.terminationReason,
|
||||
qualification: await dataSource
|
||||
.getRepository(qualification)
|
||||
.createQueryBuilder("qualification")
|
||||
.where("id = :id", { id: updateMemberQualification.qualificationId })
|
||||
.getOneOrFail(),
|
||||
qualificationId: updateMemberQualification.qualificationId,
|
||||
})
|
||||
.where("id = :id", { id: updateMemberQualification.id })
|
||||
.andWhere("memberId = :memberId", { memberId: updateMemberQualification.memberId })
|
||||
|
@ -74,16 +60,16 @@ export default abstract class MemberQualificationCommandHandler {
|
|||
|
||||
/**
|
||||
* @description delete memberQualification
|
||||
* @param DeleteMemberQualificationCommand
|
||||
* @param {DeleteMemberQualificationCommand} deleteMemberQualification
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
static async delete(deletMemberQualification: DeleteMemberQualificationCommand): Promise<void> {
|
||||
static async delete(deleteMemberQualification: DeleteMemberQualificationCommand): Promise<void> {
|
||||
return await dataSource
|
||||
.createQueryBuilder()
|
||||
.delete()
|
||||
.from(memberQualifications)
|
||||
.where("id = :id", { id: deletMemberQualification.id })
|
||||
.andWhere("memberId = :memberId", { memberId: deletMemberQualification.memberId })
|
||||
.where("id = :id", { id: deleteMemberQualification.id })
|
||||
.andWhere("memberId = :memberId", { memberId: deleteMemberQualification.memberId })
|
||||
.execute()
|
||||
.then(() => {})
|
||||
.catch((err) => {
|
|
@ -1,5 +1,4 @@
|
|||
export interface CreateMembershipCommand {
|
||||
internalId?: string;
|
||||
start: Date;
|
||||
memberId: number;
|
||||
statusId: number;
|
||||
|
@ -7,7 +6,6 @@ export interface CreateMembershipCommand {
|
|||
|
||||
export interface UpdateMembershipCommand {
|
||||
id: number;
|
||||
internalId?: string;
|
||||
start: Date;
|
||||
end?: Date;
|
||||
terminationReason?: string;
|
|
@ -1,18 +1,16 @@
|
|||
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 { dataSource } from "../../../data-source";
|
||||
import { membership } from "../../../entity/club/member/membership";
|
||||
import InternalException from "../../../exceptions/internalException";
|
||||
import { CreateMembershipCommand, DeleteMembershipCommand, UpdateMembershipCommand } from "./membershipCommand";
|
||||
|
||||
export default abstract class MembershipCommandHandler {
|
||||
/**
|
||||
* @description create membership
|
||||
* @param CreateMembershipCommand
|
||||
* @param {CreateMembershipCommand} createMembership
|
||||
* @returns {Promise<number>}
|
||||
*/
|
||||
static async create(createMembership: CreateMembershipCommand): Promise<number> {
|
||||
let insertid = -1;
|
||||
let insertId = -1;
|
||||
return await dataSource
|
||||
.transaction(async (manager) => {
|
||||
await manager
|
||||
|
@ -20,37 +18,29 @@ export default abstract class MembershipCommandHandler {
|
|||
.insert()
|
||||
.into(membership)
|
||||
.values({
|
||||
internalId: createMembership.internalId,
|
||||
start: createMembership.start,
|
||||
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(),
|
||||
memberId: createMembership.memberId,
|
||||
statusId: createMembership.statusId,
|
||||
})
|
||||
.execute()
|
||||
.then((result) => {
|
||||
insertid = result.identifiers[0].id;
|
||||
insertId = result.identifiers[0].id;
|
||||
});
|
||||
|
||||
await manager
|
||||
.createQueryBuilder()
|
||||
.update(membership)
|
||||
.set({
|
||||
end: createMembership.start,
|
||||
end: new Date(new Date(createMembership.start).setDate(new Date(createMembership.start).getDate() - 1)),
|
||||
terminationReason: "beendet durch neuen Eintrag.",
|
||||
})
|
||||
.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);
|
||||
|
@ -59,7 +49,7 @@ export default abstract class MembershipCommandHandler {
|
|||
|
||||
/**
|
||||
* @description update membership
|
||||
* @param UpdateMembershipCommand
|
||||
* @param {UpdateMembershipCommand} updateMembership
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
static async update(updateMembership: UpdateMembershipCommand): Promise<void> {
|
||||
|
@ -67,15 +57,10 @@ export default abstract class MembershipCommandHandler {
|
|||
.createQueryBuilder()
|
||||
.update(membership)
|
||||
.set({
|
||||
internalId: updateMembership.internalId,
|
||||
start: updateMembership.start,
|
||||
end: updateMembership.end,
|
||||
terminationReason: updateMembership.terminationReason,
|
||||
status: await dataSource
|
||||
.getRepository(membershipStatus)
|
||||
.createQueryBuilder("membershipStatus")
|
||||
.where("id = :id", { id: updateMembership.statusId })
|
||||
.getOneOrFail(),
|
||||
statusId: updateMembership.statusId,
|
||||
})
|
||||
.where("id = :id", { id: updateMembership.id })
|
||||
.andWhere("memberId = :memberId", { memberId: updateMembership.memberId })
|
||||
|
@ -88,16 +73,16 @@ export default abstract class MembershipCommandHandler {
|
|||
|
||||
/**
|
||||
* @description delete membership
|
||||
* @param DeleteMembershipCommand
|
||||
* @param {DeleteMembershipCommand} deleteMembership
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
static async delete(deletMembership: DeleteMembershipCommand): Promise<void> {
|
||||
static async delete(deleteMembership: DeleteMembershipCommand): Promise<void> {
|
||||
return await dataSource
|
||||
.createQueryBuilder()
|
||||
.delete()
|
||||
.from(membership)
|
||||
.where("id = :id", { id: deletMembership.id })
|
||||
.andWhere("memberId = :memberId", { memberId: deletMembership.memberId })
|
||||
.where("id = :id", { id: deleteMembership.id })
|
||||
.andWhere("memberId = :memberId", { memberId: deleteMembership.memberId })
|
||||
.execute()
|
||||
.then(() => {})
|
||||
.catch((err) => {
|
18
src/command/club/newsletter/newsletterCommand.ts
Normal file
18
src/command/club/newsletter/newsletterCommand.ts
Normal file
|
@ -0,0 +1,18 @@
|
|||
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;
|
||||
}
|
73
src/command/club/newsletter/newsletterCommandHandler.ts
Normal file
73
src/command/club/newsletter/newsletterCommandHandler.ts
Normal file
|
@ -0,0 +1,73 @@
|
|||
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);
|
||||
});
|
||||
}
|
||||
}
|
10
src/command/club/newsletter/newsletterDatesCommand.ts
Normal file
10
src/command/club/newsletter/newsletterDatesCommand.ts
Normal file
|
@ -0,0 +1,10 @@
|
|||
export interface SynchronizeNewsletterDatesCommand {
|
||||
newsletterId: number;
|
||||
dates: Array<NewsletterDateCommand>;
|
||||
}
|
||||
|
||||
export interface NewsletterDateCommand {
|
||||
calendarId: string;
|
||||
diffTitle?: string;
|
||||
diffDescription?: string;
|
||||
}
|
97
src/command/club/newsletter/newsletterDatesCommandHandler.ts
Normal file
97
src/command/club/newsletter/newsletterDatesCommandHandler.ts
Normal file
|
@ -0,0 +1,97 @@
|
|||
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();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
export interface SynchronizeNewsletterRecipientsCommand {
|
||||
newsletterId: number;
|
||||
recipients: Array<number>;
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
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();
|
||||
}
|
||||
}
|
6
src/command/club/protocol/protocolAgendaCommand.ts
Normal file
6
src/command/club/protocol/protocolAgendaCommand.ts
Normal file
|
@ -0,0 +1,6 @@
|
|||
export interface SynchronizeProtocolAgendaCommand {
|
||||
id?: number;
|
||||
topic: string;
|
||||
context: string;
|
||||
protocolId: number;
|
||||
}
|
49
src/command/club/protocol/protocolAgendaCommandHandler.ts
Normal file
49
src/command/club/protocol/protocolAgendaCommandHandler.ts
Normal file
|
@ -0,0 +1,49 @@
|
|||
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);
|
||||
});
|
||||
}
|
||||
}
|
13
src/command/club/protocol/protocolCommand.ts
Normal file
13
src/command/club/protocol/protocolCommand.ts
Normal file
|
@ -0,0 +1,13 @@
|
|||
export interface CreateProtocolCommand {
|
||||
title: string;
|
||||
date: Date;
|
||||
}
|
||||
|
||||
export interface SynchronizeProtocolCommand {
|
||||
id: number;
|
||||
title: string;
|
||||
date: Date;
|
||||
starttime: Date;
|
||||
endtime: Date;
|
||||
summary: string;
|
||||
}
|
53
src/command/club/protocol/protocolCommandHandler.ts
Normal file
53
src/command/club/protocol/protocolCommandHandler.ts
Normal file
|
@ -0,0 +1,53 @@
|
|||
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);
|
||||
});
|
||||
}
|
||||
}
|
6
src/command/club/protocol/protocolDecisionCommand.ts
Normal file
6
src/command/club/protocol/protocolDecisionCommand.ts
Normal file
|
@ -0,0 +1,6 @@
|
|||
export interface SynchronizeProtocolDecisionCommand {
|
||||
id?: number;
|
||||
topic: string;
|
||||
context: string;
|
||||
protocolId: number;
|
||||
}
|
48
src/command/club/protocol/protocolDecisionCommandHandler.ts
Normal file
48
src/command/club/protocol/protocolDecisionCommandHandler.ts
Normal file
|
@ -0,0 +1,48 @@
|
|||
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);
|
||||
});
|
||||
}
|
||||
}
|
10
src/command/club/protocol/protocolPresenceCommand.ts
Normal file
10
src/command/club/protocol/protocolPresenceCommand.ts
Normal file
|
@ -0,0 +1,10 @@
|
|||
export interface SynchronizeProtocolPresenceCommand {
|
||||
members: Array<ProtocolPresenceCommand>;
|
||||
protocolId: number;
|
||||
}
|
||||
|
||||
export interface ProtocolPresenceCommand {
|
||||
memberId: number;
|
||||
absent: boolean;
|
||||
excused: boolean;
|
||||
}
|
97
src/command/club/protocol/protocolPresenceCommandHandler.ts
Normal file
97
src/command/club/protocol/protocolPresenceCommandHandler.ts
Normal file
|
@ -0,0 +1,97 @@
|
|||
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();
|
||||
}
|
||||
}
|
6
src/command/club/protocol/protocolPrintoutCommand.ts
Normal file
6
src/command/club/protocol/protocolPrintoutCommand.ts
Normal file
|
@ -0,0 +1,6 @@
|
|||
export interface CreateProtocolPrintoutCommand {
|
||||
title: string;
|
||||
iteration: number;
|
||||
filename: string;
|
||||
protocolId: number;
|
||||
}
|
31
src/command/club/protocol/protocolPrintoutCommandHandler.ts
Normal file
31
src/command/club/protocol/protocolPrintoutCommandHandler.ts
Normal file
|
@ -0,0 +1,31 @@
|
|||
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);
|
||||
});
|
||||
}
|
||||
}
|
9
src/command/club/protocol/protocolVotingCommand.ts
Normal file
9
src/command/club/protocol/protocolVotingCommand.ts
Normal file
|
@ -0,0 +1,9 @@
|
|||
export interface SynchronizeProtocolVotingCommand {
|
||||
id: number;
|
||||
topic: string;
|
||||
context: string;
|
||||
favour: number;
|
||||
abstain: number;
|
||||
against: number;
|
||||
protocolId: number;
|
||||
}
|
48
src/command/club/protocol/protocolVotingCommandHandler.ts
Normal file
48
src/command/club/protocol/protocolVotingCommandHandler.ts
Normal file
|
@ -0,0 +1,48 @@
|
|||
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);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
export interface CreateRefreshCommand {
|
||||
userId: number;
|
||||
isFromPwa?: boolean;
|
||||
}
|
||||
|
||||
export interface DeleteRefreshCommand {
|
||||
|
|
|
@ -1,25 +1,19 @@
|
|||
import { dataSource } from "../data-source";
|
||||
import { refresh } from "../entity/refresh";
|
||||
import { REFRESH_EXPIRATION } from "../env.defaults";
|
||||
import { PWA_REFRESH_EXPIRATION, REFRESH_EXPIRATION } from "../env.defaults";
|
||||
import InternalException from "../exceptions/internalException";
|
||||
import { JWTHelper } from "../helpers/jwtHelper";
|
||||
import { StringHelper } from "../helpers/stringHelper";
|
||||
import UserService from "../service/userService";
|
||||
import { JWTRefresh } from "../type/jwtTypes";
|
||||
import UserService from "../service/user/userService";
|
||||
import { CreateRefreshCommand, DeleteRefreshCommand } from "./refreshCommand";
|
||||
import ms from "ms";
|
||||
|
||||
export default abstract class RefreshCommandHandler {
|
||||
/**
|
||||
* @description create and save refreshToken to user
|
||||
* @param CreateRefreshCommand
|
||||
* @param {CreateRefreshCommand} createRefresh
|
||||
* @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
|
||||
|
@ -29,7 +23,9 @@ export default abstract class RefreshCommandHandler {
|
|||
.values({
|
||||
token: refreshToken,
|
||||
user: await UserService.getById(createRefresh.userId),
|
||||
expiry: new Date(Date.now() + ms(REFRESH_EXPIRATION)),
|
||||
expiry: createRefresh.isFromPwa
|
||||
? new Date(Date.now() + ms(PWA_REFRESH_EXPIRATION))
|
||||
: new Date(Date.now() + ms(REFRESH_EXPIRATION)),
|
||||
})
|
||||
.execute()
|
||||
.then((result) => {
|
||||
|
@ -42,7 +38,7 @@ export default abstract class RefreshCommandHandler {
|
|||
|
||||
/**
|
||||
* @description delete refresh by user and token
|
||||
* @param DeleteRefreshCommand
|
||||
* @param {DeleteRefreshCommand} deleteRefresh
|
||||
* @returns {Promise<any>}
|
||||
*/
|
||||
static async deleteByToken(deleteRefresh: DeleteRefreshCommand): Promise<any> {
|
||||
|
|
10
src/command/resetCommand.ts
Normal file
10
src/command/resetCommand.ts
Normal file
|
@ -0,0 +1,10 @@
|
|||
export interface CreateResetCommand {
|
||||
mail: string;
|
||||
username: string;
|
||||
secret: string;
|
||||
}
|
||||
|
||||
export interface DeleteResetCommand {
|
||||
token: string;
|
||||
mail: string;
|
||||
}
|
54
src/command/resetCommandHandler.ts
Normal file
54
src/command/resetCommandHandler.ts
Normal file
|
@ -0,0 +1,54 @@
|
|||
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);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,12 +1,12 @@
|
|||
import { dataSource } from "../data-source";
|
||||
import { award } from "../entity/award";
|
||||
import InternalException from "../exceptions/internalException";
|
||||
import { dataSource } from "../../../data-source";
|
||||
import { award } from "../../../entity/settings/award";
|
||||
import InternalException from "../../../exceptions/internalException";
|
||||
import { CreateAwardCommand, DeleteAwardCommand, UpdateAwardCommand } from "./awardCommand";
|
||||
|
||||
export default abstract class AwardCommandHandler {
|
||||
/**
|
||||
* @description create award
|
||||
* @param CreateAwardCommand
|
||||
* @param {CreateAwardCommand} createAward
|
||||
* @returns {Promise<number>}
|
||||
*/
|
||||
static async create(createAward: CreateAwardCommand): Promise<number> {
|
||||
|
@ -28,7 +28,7 @@ export default abstract class AwardCommandHandler {
|
|||
|
||||
/**
|
||||
* @description update award
|
||||
* @param UpdateAwardCommand
|
||||
* @param {UpdateAwardCommand} updateAward
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
static async update(updateAward: UpdateAwardCommand): Promise<void> {
|
||||
|
@ -48,19 +48,22 @@ export default abstract class AwardCommandHandler {
|
|||
|
||||
/**
|
||||
* @description delete award
|
||||
* @param DeleteAwardCommand
|
||||
* @param {DeleteAwardCommand} deleteAward
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
static async delete(deletAward: DeleteAwardCommand): Promise<void> {
|
||||
static async delete(deleteAward: DeleteAwardCommand): Promise<void> {
|
||||
return await dataSource
|
||||
.createQueryBuilder()
|
||||
.delete()
|
||||
.from(award)
|
||||
.where("id = :id", { id: deletAward.id })
|
||||
.where("id = :id", { id: deleteAward.id })
|
||||
.execute()
|
||||
.then(() => {})
|
||||
.catch((err) => {
|
||||
throw new InternalException("Failed deleting award", err);
|
||||
throw new InternalException(
|
||||
`Failed deleting award ${err.code.includes("ER_ROW_IS_REFERENCED") ? " due to referenced data" : ""}`,
|
||||
err
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
18
src/command/settings/calendarType/calendarTypeCommand.ts
Normal file
18
src/command/settings/calendarType/calendarTypeCommand.ts
Normal file
|
@ -0,0 +1,18 @@
|
|||
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;
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
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
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
import { CommunicationFieldType } from "../type/fieldTypes";
|
||||
import { CommunicationFieldType } from "../../../type/fieldTypes";
|
||||
|
||||
export interface CreateCommunicationTypeCommand {
|
||||
type: string;
|
|
@ -1,6 +1,6 @@
|
|||
import { dataSource } from "../data-source";
|
||||
import { communicationType } from "../entity/communicationType";
|
||||
import InternalException from "../exceptions/internalException";
|
||||
import { dataSource } from "../../../data-source";
|
||||
import { communicationType } from "../../../entity/settings/communicationType";
|
||||
import InternalException from "../../../exceptions/internalException";
|
||||
import {
|
||||
CreateCommunicationTypeCommand,
|
||||
DeleteCommunicationTypeCommand,
|
||||
|
@ -10,7 +10,7 @@ import {
|
|||
export default abstract class CommunicationTypeCommandHandler {
|
||||
/**
|
||||
* @description create communicationType
|
||||
* @param CreateCommunicationTypeCommand
|
||||
* @param {CreateCommunicationTypeCommand} createCommunicationType
|
||||
* @returns {Promise<number>}
|
||||
*/
|
||||
static async create(createCommunicationType: CreateCommunicationTypeCommand): Promise<number> {
|
||||
|
@ -33,7 +33,7 @@ export default abstract class CommunicationTypeCommandHandler {
|
|||
|
||||
/**
|
||||
* @description update communicationType
|
||||
* @param UpdateCommunicationTypeCommand
|
||||
* @param {UpdateCommunicationTypeCommand} updateCommunicationType
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
static async update(updateCommunicationType: UpdateCommunicationTypeCommand): Promise<void> {
|
||||
|
@ -54,19 +54,24 @@ export default abstract class CommunicationTypeCommandHandler {
|
|||
|
||||
/**
|
||||
* @description delete communicationType
|
||||
* @param DeleteCommunicationTypeCommand
|
||||
* @param {DeleteCommunicationTypeCommand} deleteCommunicationType
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
static async delete(deletCommunicationType: DeleteCommunicationTypeCommand): Promise<void> {
|
||||
static async delete(deleteCommunicationType: DeleteCommunicationTypeCommand): Promise<void> {
|
||||
return await dataSource
|
||||
.createQueryBuilder()
|
||||
.delete()
|
||||
.from(communicationType)
|
||||
.where("id = :id", { id: deletCommunicationType.id })
|
||||
.where("id = :id", { id: deleteCommunicationType.id })
|
||||
.execute()
|
||||
.then(() => {})
|
||||
.catch((err) => {
|
||||
throw new InternalException("Failed deleting communicationType", err);
|
||||
throw new InternalException(
|
||||
`Failed deleting communicationType${
|
||||
err.code.includes("ER_ROW_IS_REFERENCED") ? " due to referenced data" : ""
|
||||
}`,
|
||||
err
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
import { dataSource } from "../data-source";
|
||||
import { executivePosition } from "../entity/executivePosition";
|
||||
import InternalException from "../exceptions/internalException";
|
||||
import { dataSource } from "../../../data-source";
|
||||
import { executivePosition } from "../../../entity/settings/executivePosition";
|
||||
import InternalException from "../../../exceptions/internalException";
|
||||
import {
|
||||
CreateExecutivePositionCommand,
|
||||
DeleteExecutivePositionCommand,
|
||||
|
@ -10,7 +10,7 @@ import {
|
|||
export default abstract class ExecutivePositionCommandHandler {
|
||||
/**
|
||||
* @description create executivePosition
|
||||
* @param CreateExecutivePositionCommand
|
||||
* @param {CreateExecutivePositionCommand} createExecutivePosition
|
||||
* @returns {Promise<number>}
|
||||
*/
|
||||
static async create(createExecutivePosition: CreateExecutivePositionCommand): Promise<number> {
|
||||
|
@ -32,7 +32,7 @@ export default abstract class ExecutivePositionCommandHandler {
|
|||
|
||||
/**
|
||||
* @description update executivePosition
|
||||
* @param UpdateExecutivePositionCommand
|
||||
* @param {UpdateExecutivePositionCommand} updateExecutivePosition
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
static async update(updateExecutivePosition: UpdateExecutivePositionCommand): Promise<void> {
|
||||
|
@ -52,19 +52,24 @@ export default abstract class ExecutivePositionCommandHandler {
|
|||
|
||||
/**
|
||||
* @description delete executivePosition
|
||||
* @param DeleteExecutivePositionCommand
|
||||
* @param {DeleteExecutivePositionCommand} deleteExecutivePosition
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
static async delete(deletExecutivePosition: DeleteExecutivePositionCommand): Promise<void> {
|
||||
static async delete(deleteExecutivePosition: DeleteExecutivePositionCommand): Promise<void> {
|
||||
return await dataSource
|
||||
.createQueryBuilder()
|
||||
.delete()
|
||||
.from(executivePosition)
|
||||
.where("id = :id", { id: deletExecutivePosition.id })
|
||||
.where("id = :id", { id: deleteExecutivePosition.id })
|
||||
.execute()
|
||||
.then(() => {})
|
||||
.catch((err) => {
|
||||
throw new InternalException("Failed deleting executivePosition", err);
|
||||
throw new InternalException(
|
||||
`Failed deleting executivePosition${
|
||||
err.code.includes("ER_ROW_IS_REFERENCED") ? " due to referenced data" : ""
|
||||
}`,
|
||||
err
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
import { dataSource } from "../data-source";
|
||||
import { membershipStatus } from "../entity/membershipStatus";
|
||||
import InternalException from "../exceptions/internalException";
|
||||
import { dataSource } from "../../../data-source";
|
||||
import { membershipStatus } from "../../../entity/settings/membershipStatus";
|
||||
import InternalException from "../../../exceptions/internalException";
|
||||
import {
|
||||
CreateMembershipStatusCommand,
|
||||
DeleteMembershipStatusCommand,
|
||||
|
@ -10,7 +10,7 @@ import {
|
|||
export default abstract class MembershipStatusCommandHandler {
|
||||
/**
|
||||
* @description create membershipStatus
|
||||
* @param CreateMembershipStatusCommand
|
||||
* @param {CreateMembershipStatusCommand} createMembershipStatus
|
||||
* @returns {Promise<number>}
|
||||
*/
|
||||
static async create(createMembershipStatus: CreateMembershipStatusCommand): Promise<number> {
|
||||
|
@ -32,7 +32,7 @@ export default abstract class MembershipStatusCommandHandler {
|
|||
|
||||
/**
|
||||
* @description update membershipStatus
|
||||
* @param UpdateMembershipStatusCommand
|
||||
* @param {UpdateMembershipStatusCommand} updateMembershipStatus
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
static async update(updateMembershipStatus: UpdateMembershipStatusCommand): Promise<void> {
|
||||
|
@ -52,19 +52,24 @@ export default abstract class MembershipStatusCommandHandler {
|
|||
|
||||
/**
|
||||
* @description delete membershipStatus
|
||||
* @param DeleteMembershipStatusCommand
|
||||
* @param {DeleteMembershipStatusCommand} deleteMembershipStatus
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
static async delete(deletMembershipStatus: DeleteMembershipStatusCommand): Promise<void> {
|
||||
static async delete(deleteMembershipStatus: DeleteMembershipStatusCommand): Promise<void> {
|
||||
return await dataSource
|
||||
.createQueryBuilder()
|
||||
.delete()
|
||||
.from(membershipStatus)
|
||||
.where("id = :id", { id: deletMembershipStatus.id })
|
||||
.where("id = :id", { id: deleteMembershipStatus.id })
|
||||
.execute()
|
||||
.then(() => {})
|
||||
.catch((err) => {
|
||||
throw new InternalException("Failed deleting membershipStatus", err);
|
||||
throw new InternalException(
|
||||
`Failed deleting membershipStatus${
|
||||
err.code.includes("ER_ROW_IS_REFERENCED") ? " due to referenced data" : ""
|
||||
}`,
|
||||
err
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
import { NewsletterConfigType } from "../../../enums/newsletterConfigType";
|
||||
|
||||
export interface SetNewsletterConfigCommand {
|
||||
comTypeId: number;
|
||||
config: NewsletterConfigType;
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
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);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
import { dataSource } from "../data-source";
|
||||
import { qualification } from "../entity/qualification";
|
||||
import InternalException from "../exceptions/internalException";
|
||||
import { dataSource } from "../../../data-source";
|
||||
import { qualification } from "../../../entity/settings/qualification";
|
||||
import InternalException from "../../../exceptions/internalException";
|
||||
import {
|
||||
CreateQualificationCommand,
|
||||
DeleteQualificationCommand,
|
||||
|
@ -10,7 +10,7 @@ import {
|
|||
export default abstract class QualificationCommandHandler {
|
||||
/**
|
||||
* @description create qualification
|
||||
* @param CreateQualificationCommand
|
||||
* @param {CreateQualificationCommand} createQualification
|
||||
* @returns {Promise<number>}
|
||||
*/
|
||||
static async create(createQualification: CreateQualificationCommand): Promise<number> {
|
||||
|
@ -33,7 +33,7 @@ export default abstract class QualificationCommandHandler {
|
|||
|
||||
/**
|
||||
* @description update qualification
|
||||
* @param UpdateQualificationCommand
|
||||
* @param {UpdateQualificationCommand} updateQualification
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
static async update(updateQualification: UpdateQualificationCommand): Promise<void> {
|
||||
|
@ -54,19 +54,22 @@ export default abstract class QualificationCommandHandler {
|
|||
|
||||
/**
|
||||
* @description delete qualification
|
||||
* @param DeleteQualificationCommand
|
||||
* @param {DeleteQualificationCommand} deleteQualification
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
static async delete(deletQualification: DeleteQualificationCommand): Promise<void> {
|
||||
static async delete(deleteQualification: DeleteQualificationCommand): Promise<void> {
|
||||
return await dataSource
|
||||
.createQueryBuilder()
|
||||
.delete()
|
||||
.from(qualification)
|
||||
.where("id = :id", { id: deletQualification.id })
|
||||
.where("id = :id", { id: deleteQualification.id })
|
||||
.execute()
|
||||
.then(() => {})
|
||||
.catch((err) => {
|
||||
throw new InternalException("Failed deleting qualification", err);
|
||||
throw new InternalException(
|
||||
`Failed deleting qualification${err.code.includes("ER_ROW_IS_REFERENCED") ? " due to referenced data" : ""}`,
|
||||
err
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
15
src/command/settings/queryStore/queryStoreCommand.ts
Normal file
15
src/command/settings/queryStore/queryStoreCommand.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
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;
|
||||
}
|
72
src/command/settings/queryStore/queryStoreCommandHandler.ts
Normal file
72
src/command/settings/queryStore/queryStoreCommandHandler.ts
Normal file
|
@ -0,0 +1,72 @@
|
|||
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
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
16
src/command/settings/template/templateCommand.ts
Normal file
16
src/command/settings/template/templateCommand.ts
Normal file
|
@ -0,0 +1,16 @@
|
|||
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;
|
||||
}
|
73
src/command/settings/template/templateCommandHandler.ts
Normal file
73
src/command/settings/template/templateCommandHandler.ts
Normal file
|
@ -0,0 +1,73 @@
|
|||
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
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
export interface UpdateTemplateUsageCommand {
|
||||
scope: string;
|
||||
headerId: number | null;
|
||||
bodyId: number | null;
|
||||
footerId: number | null;
|
||||
headerHeight: number | null;
|
||||
footerHeight: number | null;
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
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);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,12 +1,12 @@
|
|||
import { dataSource } from "../data-source";
|
||||
import { role } from "../entity/role";
|
||||
import InternalException from "../exceptions/internalException";
|
||||
import { dataSource } from "../../../data-source";
|
||||
import { role } from "../../../entity/user/role";
|
||||
import InternalException from "../../../exceptions/internalException";
|
||||
import { CreateRoleCommand, DeleteRoleCommand, UpdateRoleCommand } from "./roleCommand";
|
||||
|
||||
export default abstract class RoleCommandHandler {
|
||||
/**
|
||||
* @description create role
|
||||
* @param CreateRoleCommand
|
||||
* @param {CreateRoleCommand} createRole
|
||||
* @returns {Promise<number>}
|
||||
*/
|
||||
static async create(createRole: CreateRoleCommand): Promise<number> {
|
||||
|
@ -28,7 +28,7 @@ export default abstract class RoleCommandHandler {
|
|||
|
||||
/**
|
||||
* @description update role
|
||||
* @param UpdateRoleCommand
|
||||
* @param {UpdateRoleCommand} updateRole
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
static async update(updateRole: UpdateRoleCommand): Promise<void> {
|
||||
|
@ -48,7 +48,7 @@ export default abstract class RoleCommandHandler {
|
|||
|
||||
/**
|
||||
* @description delete role
|
||||
* @param DeleteRoleCommand
|
||||
* @param {DeleteRoleCommand} deleteRole
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
static async delete(deleteRole: DeleteRoleCommand): Promise<void> {
|
|
@ -1,4 +1,4 @@
|
|||
import { PermissionString } from "../type/permissionTypes";
|
||||
import { PermissionString } from "../../../type/permissionTypes";
|
||||
|
||||
export interface CreateRolePermissionCommand {
|
||||
permission: PermissionString;
|
|
@ -1,22 +1,21 @@
|
|||
import { DeleteResult, EntityManager, InsertResult } from "typeorm";
|
||||
import { dataSource } from "../data-source";
|
||||
import { rolePermission } from "../entity/role_permission";
|
||||
import InternalException from "../exceptions/internalException";
|
||||
import RoleService from "../service/roleService";
|
||||
import { dataSource } from "../../../data-source";
|
||||
import { rolePermission } from "../../../entity/user/role_permission";
|
||||
import InternalException from "../../../exceptions/internalException";
|
||||
import RoleService from "../../../service/user/roleService";
|
||||
import {
|
||||
CreateRolePermissionCommand,
|
||||
DeleteRolePermissionCommand,
|
||||
UpdateRolePermissionsCommand,
|
||||
} from "./rolePermissionCommand";
|
||||
import PermissionHelper from "../helpers/permissionHelper";
|
||||
import RolePermissionService from "../service/rolePermissionService";
|
||||
import { role } from "../entity/role";
|
||||
import { PermissionString } from "../type/permissionTypes";
|
||||
import PermissionHelper from "../../../helpers/permissionHelper";
|
||||
import RolePermissionService from "../../../service/user/rolePermissionService";
|
||||
import { PermissionString } from "../../../type/permissionTypes";
|
||||
|
||||
export default abstract class RolePermissionCommandHandler {
|
||||
/**
|
||||
* @description update role permissions
|
||||
* @param UpdateRolePermissionsCommand
|
||||
* @param {UpdateRolePermissionsCommand} updateRolePermissions
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
static async updatePermissions(updateRolePermissions: UpdateRolePermissionsCommand): Promise<void> {
|
||||
|
@ -75,7 +74,7 @@ export default abstract class RolePermissionCommandHandler {
|
|||
|
||||
/**
|
||||
* @description grant permission to user
|
||||
* @param CreateRolePermissionCommand
|
||||
* @param {CreateRolePermissionCommand} createPermission
|
||||
* @returns {Promise<number>}
|
||||
*/
|
||||
static async create(createPermission: CreateRolePermissionCommand): Promise<number> {
|
||||
|
@ -98,7 +97,7 @@ export default abstract class RolePermissionCommandHandler {
|
|||
|
||||
/**
|
||||
* @description remove permission from role
|
||||
* @param DeleteRolePermissionCommand
|
||||
* @param {DeleteRolePermissionCommand} deletePermission
|
||||
* @returns {Promise<any>}
|
||||
*/
|
||||
static async delete(deletePermission: DeleteRolePermissionCommand): Promise<any> {
|
||||
|
@ -109,7 +108,7 @@ export default abstract class RolePermissionCommandHandler {
|
|||
.where("roleId = :id", { id: deletePermission.roleId })
|
||||
.andWhere("permission = :permission", { permission: deletePermission.permission })
|
||||
.execute()
|
||||
.then((res) => {})
|
||||
.then(() => {})
|
||||
.catch((err) => {
|
||||
throw new InternalException("failed role permission removal", err);
|
||||
});
|
|
@ -1,7 +1,7 @@
|
|||
import { dataSource } from "../data-source";
|
||||
import { invite } from "../entity/invite";
|
||||
import InternalException from "../exceptions/internalException";
|
||||
import { StringHelper } from "../helpers/stringHelper";
|
||||
import { dataSource } from "../../../data-source";
|
||||
import { invite } from "../../../entity/user/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 DeleteRefreshCommand
|
||||
* @param DeleteInviteCommand
|
||||
* @returns {Promise<any>}
|
||||
*/
|
||||
static async deleteByTokenAndMail(deleteInvite: DeleteInviteCommand): Promise<any> {
|
||||
|
@ -53,4 +53,22 @@ 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);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -4,6 +4,7 @@ export interface CreateUserCommand {
|
|||
firstname: string;
|
||||
lastname: string;
|
||||
secret: string;
|
||||
isOwner: boolean;
|
||||
}
|
||||
|
||||
export interface UpdateUserCommand {
|
||||
|
@ -14,6 +15,16 @@ 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>;
|
|
@ -1,14 +1,21 @@
|
|||
import { EntityManager } from "typeorm";
|
||||
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";
|
||||
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";
|
||||
|
||||
export default abstract class UserCommandHandler {
|
||||
/**
|
||||
* @description create user
|
||||
* @param CreateUserCommand
|
||||
* @param {CreateUserCommand} createUser
|
||||
* @returns {Promise<number>}
|
||||
*/
|
||||
static async create(createUser: CreateUserCommand): Promise<number> {
|
||||
|
@ -22,6 +29,7 @@ export default abstract class UserCommandHandler {
|
|||
firstname: createUser.firstname,
|
||||
lastname: createUser.lastname,
|
||||
secret: createUser.secret,
|
||||
isOwner: createUser.isOwner,
|
||||
})
|
||||
.execute()
|
||||
.then((result) => {
|
||||
|
@ -34,7 +42,7 @@ export default abstract class UserCommandHandler {
|
|||
|
||||
/**
|
||||
* @description update user
|
||||
* @param UpdateUserCommand
|
||||
* @param {UpdateUserCommand} updateUser
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
static async update(updateUser: UpdateUserCommand): Promise<void> {
|
||||
|
@ -55,9 +63,29 @@ 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
|
||||
* @param {UpdateUserRolesCommand} updateUserRoles
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
static async updateRoles(updateUserRoles: UpdateUserRolesCommand): Promise<void> {
|
||||
|
@ -89,6 +117,38 @@ 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
|
|
@ -1,4 +1,4 @@
|
|||
import { PermissionString } from "../type/permissionTypes";
|
||||
import { PermissionString } from "../../../type/permissionTypes";
|
||||
|
||||
export interface CreateUserPermissionCommand {
|
||||
permission: PermissionString;
|
|
@ -1,21 +1,21 @@
|
|||
import { DeleteResult, EntityManager, InsertResult } from "typeorm";
|
||||
import { dataSource } from "../data-source";
|
||||
import { user } from "../entity/user";
|
||||
import { userPermission } from "../entity/user_permission";
|
||||
import InternalException from "../exceptions/internalException";
|
||||
import { dataSource } from "../../../data-source";
|
||||
import { user } from "../../../entity/user/user";
|
||||
import { userPermission } from "../../../entity/user/user_permission";
|
||||
import InternalException from "../../../exceptions/internalException";
|
||||
import {
|
||||
CreateUserPermissionCommand,
|
||||
DeleteUserPermissionCommand,
|
||||
UpdateUserPermissionsCommand,
|
||||
} from "./userPermissionCommand";
|
||||
import UserPermissionService from "../service/userPermissionService";
|
||||
import PermissionHelper from "../helpers/permissionHelper";
|
||||
import { PermissionString } from "../type/permissionTypes";
|
||||
import UserPermissionService from "../../../service/user/userPermissionService";
|
||||
import PermissionHelper from "../../../helpers/permissionHelper";
|
||||
import { PermissionString } from "../../../type/permissionTypes";
|
||||
|
||||
export default abstract class UserPermissionCommandHandler {
|
||||
/**
|
||||
* @description update user permissions
|
||||
* @param UpdateUserPermissionsCommand
|
||||
* @param {UpdateUserPermissionsCommand} updateUserPermissions
|
||||
* @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
|
||||
* @param {CreateUserPermissionCommand} createPermission
|
||||
* @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
|
||||
* @param {DeleteUserPermissionCommand} deletePermission
|
||||
* @returns {Promise<any>}
|
||||
*/
|
||||
static async delete(deletePermission: DeleteUserPermissionCommand): Promise<any> {
|
205
src/controller/admin/club/calendarController.ts
Normal file
205
src/controller/admin/club/calendarController.ts
Normal file
|
@ -0,0 +1,205 @@
|
|||
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);
|
||||
}
|
|
@ -1,53 +1,55 @@
|
|||
import { Request, Response } from "express";
|
||||
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 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 {
|
||||
CreateMemberCommand,
|
||||
DeleteMemberCommand,
|
||||
UpdateMemberCommand,
|
||||
UpdateMemberNewsletterCommand,
|
||||
} from "../../command/memberCommand";
|
||||
import MemberCommandHandler from "../../command/memberCommandHandler";
|
||||
} from "../../../command/club/member/memberCommand";
|
||||
import MemberCommandHandler from "../../../command/club/member/memberCommandHandler";
|
||||
import {
|
||||
CreateMembershipCommand,
|
||||
DeleteMembershipCommand,
|
||||
UpdateMembershipCommand,
|
||||
} from "../../command/membershipCommand";
|
||||
import MembershipCommandHandler from "../../command/membershipCommandHandler";
|
||||
} from "../../../command/club/member/membershipCommand";
|
||||
import MembershipCommandHandler from "../../../command/club/member/membershipCommandHandler";
|
||||
import {
|
||||
CreateMemberAwardCommand,
|
||||
DeleteMemberAwardCommand,
|
||||
UpdateMemberAwardCommand,
|
||||
} from "../../command/memberAwardCommand";
|
||||
import MemberAwardCommandHandler from "../../command/memberAwardCommandHandler";
|
||||
} from "../../../command/club/member/memberAwardCommand";
|
||||
import MemberAwardCommandHandler from "../../../command/club/member/memberAwardCommandHandler";
|
||||
import {
|
||||
CreateMemberExecutivePositionCommand,
|
||||
DeleteMemberExecutivePositionCommand,
|
||||
UpdateMemberExecutivePositionCommand,
|
||||
} from "../../command/memberExecutivePositionCommand";
|
||||
import MemberExecutivePositionCommandHandler from "../../command/memberExecutivePositionCommandHandler";
|
||||
} from "../../../command/club/member/memberExecutivePositionCommand";
|
||||
import MemberExecutivePositionCommandHandler from "../../../command/club/member/memberExecutivePositionCommandHandler";
|
||||
import {
|
||||
CreateMemberQualificationCommand,
|
||||
DeleteMemberQualificationCommand,
|
||||
UpdateMemberQualificationCommand,
|
||||
} from "../../command/memberQualificationCommand";
|
||||
import MemberQualificationCommandHandler from "../../command/memberQualificationCommandHandler";
|
||||
} from "../../../command/club/member/memberQualificationCommand";
|
||||
import MemberQualificationCommandHandler from "../../../command/club/member/memberQualificationCommandHandler";
|
||||
import {
|
||||
CreateCommunicationCommand,
|
||||
DeleteCommunicationCommand,
|
||||
UpdateCommunicationCommand,
|
||||
} from "../../command/communicationCommand";
|
||||
import CommunicationCommandHandler from "../../command/communicationCommandHandler";
|
||||
} from "../../../command/club/member/communicationCommand";
|
||||
import CommunicationCommandHandler from "../../../command/club/member/communicationCommandHandler";
|
||||
import { PdfExport } from "../../../helpers/pdfExport";
|
||||
import { PermissionModule } from "../../../type/permissionTypes";
|
||||
|
||||
/**
|
||||
* @description get all members
|
||||
|
@ -58,7 +60,14 @@ import CommunicationCommandHandler from "../../command/communicationCommandHandl
|
|||
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 [members, total] = await MemberService.getAll(offset, count);
|
||||
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 });
|
||||
|
||||
res.json({
|
||||
members: MemberFactory.mapToBase(members),
|
||||
|
@ -216,6 +225,33 @@ 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
|
||||
|
@ -228,6 +264,7 @@ 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,
|
||||
|
@ -235,6 +272,7 @@ export async function createMember(req: Request, res: Response): Promise<any> {
|
|||
lastname,
|
||||
nameaffix,
|
||||
birthdate,
|
||||
internalId,
|
||||
};
|
||||
let memberId = await MemberCommandHandler.create(createMember);
|
||||
|
||||
|
@ -249,12 +287,10 @@ 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,
|
||||
|
@ -346,8 +382,10 @@ 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;
|
||||
|
@ -357,8 +395,10 @@ export async function addCommunicationToMember(req: Request, res: Response): Pro
|
|||
|
||||
let createCommunication: CreateCommunicationCommand = {
|
||||
preferred,
|
||||
isSMSAlarming,
|
||||
mobile,
|
||||
email,
|
||||
postalCode,
|
||||
city,
|
||||
street,
|
||||
streetNumber,
|
||||
|
@ -392,6 +432,7 @@ 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,
|
||||
|
@ -400,6 +441,7 @@ export async function updateMemberById(req: Request, res: Response): Promise<any
|
|||
lastname,
|
||||
nameaffix,
|
||||
birthdate,
|
||||
internalId,
|
||||
};
|
||||
await MemberCommandHandler.update(updateMember);
|
||||
|
||||
|
@ -415,7 +457,6 @@ 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;
|
||||
|
@ -423,7 +464,6 @@ export async function updateMembershipOfMember(req: Request, res: Response): Pro
|
|||
|
||||
let updateMembership: UpdateMembershipCommand = {
|
||||
id: recordId,
|
||||
internalId,
|
||||
start,
|
||||
end,
|
||||
terminationReason,
|
||||
|
@ -528,20 +568,23 @@ 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,
|
||||
|
@ -550,12 +593,16 @@ 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);
|
388
src/controller/admin/club/newsletterController.ts
Normal file
388
src/controller/admin/club/newsletterController.ts
Normal file
|
@ -0,0 +1,388 @@
|
|||
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);
|
||||
}
|
401
src/controller/admin/club/protocolController.ts
Normal file
401
src/controller/admin/club/protocolController.ts
Normal file
|
@ -0,0 +1,401 @@
|
|||
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);
|
||||
}
|
44
src/controller/admin/club/queryBuilderController.ts
Normal file
44
src/controller/admin/club/queryBuilderController.ts
Normal file
|
@ -0,0 +1,44 @@
|
|||
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);
|
||||
}
|
|
@ -1,8 +1,8 @@
|
|||
import { Request, Response } from "express";
|
||||
import AwardService from "../../service/awardService";
|
||||
import AwardFactory from "../../factory/admin/award";
|
||||
import { CreateAwardCommand, DeleteAwardCommand, UpdateAwardCommand } from "../../command/awardCommand";
|
||||
import AwardCommandHandler from "../../command/awardCommandHandler";
|
||||
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";
|
||||
|
||||
/**
|
||||
* @description get all awards
|
|
@ -1,13 +1,13 @@
|
|||
import { Request, Response } from "express";
|
||||
import CommunicationTypeService from "../../service/communicationTypeService";
|
||||
import CommunicationTypeFactory from "../../factory/admin/communicationType";
|
||||
import CommunicationService from "../../service/communicationService";
|
||||
import CommunicationTypeService from "../../../service/settings/communicationTypeService";
|
||||
import CommunicationTypeFactory from "../../../factory/admin/settings/communicationType";
|
||||
import CommunicationService from "../../../service/club/member/communicationService";
|
||||
import {
|
||||
CreateCommunicationTypeCommand,
|
||||
DeleteCommunicationTypeCommand,
|
||||
UpdateCommunicationTypeCommand,
|
||||
} from "../../command/communicationTypeCommand";
|
||||
import CommunicationTypeCommandHandler from "../../command/communicationTypeCommandHandler";
|
||||
} from "../../../command/settings/communicationType/communicationTypeCommand";
|
||||
import CommunicationTypeCommandHandler from "../../../command/settings/communicationType/communicationTypeCommandHandler";
|
||||
|
||||
/**
|
||||
* @description get all communicationTypes
|
|
@ -1,12 +1,12 @@
|
|||
import { Request, Response } from "express";
|
||||
import ExecutivePositionService from "../../service/executivePositionService";
|
||||
import ExecutivePositionFactory from "../../factory/admin/executivePosition";
|
||||
import ExecutivePositionService from "../../../service/settings/executivePositionService";
|
||||
import ExecutivePositionFactory from "../../../factory/admin/settings/executivePosition";
|
||||
import {
|
||||
CreateExecutivePositionCommand,
|
||||
DeleteExecutivePositionCommand,
|
||||
UpdateExecutivePositionCommand,
|
||||
} from "../../command/executivePositionCommand";
|
||||
import ExecutivePositionCommandHandler from "../../command/executivePositionCommandHandler";
|
||||
} from "../../../command/settings/executivePosition/executivePositionCommand";
|
||||
import ExecutivePositionCommandHandler from "../../../command/settings/executivePosition/executivePositionCommandHandler";
|
||||
|
||||
/**
|
||||
* @description get all executivePositions
|
|
@ -1,12 +1,12 @@
|
|||
import { Request, Response } from "express";
|
||||
import MembershipStatusService from "../../service/membershipStatusService";
|
||||
import MembershipStatusFactory from "../../factory/admin/membershipStatus";
|
||||
import MembershipStatusService from "../../../service/settings/membershipStatusService";
|
||||
import MembershipStatusFactory from "../../../factory/admin/settings/membershipStatus";
|
||||
import {
|
||||
CreateMembershipStatusCommand,
|
||||
DeleteMembershipStatusCommand,
|
||||
UpdateMembershipStatusCommand,
|
||||
} from "../../command/membershipStatusCommand";
|
||||
import MembershipStatusCommandHandler from "../../command/membershipStatusCommandHandler";
|
||||
} from "../../../command/settings/membershipStatus/membershipStatusCommand";
|
||||
import MembershipStatusCommandHandler from "../../../command/settings/membershipStatus/membershipStatusCommandHandler";
|
||||
|
||||
/**
|
||||
* @description get all membershipStatus
|
49
src/controller/admin/settings/newsletterConfigController.ts
Normal file
49
src/controller/admin/settings/newsletterConfigController.ts
Normal file
|
@ -0,0 +1,49 @@
|
|||
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);
|
||||
}
|
|
@ -1,12 +1,12 @@
|
|||
import { Request, Response } from "express";
|
||||
import QualificationService from "../../service/qualification";
|
||||
import QualificationFactory from "../../factory/admin/qualification";
|
||||
import QualificationService from "../../../service/settings/qualification";
|
||||
import QualificationFactory from "../../../factory/admin/settings/qualification";
|
||||
import {
|
||||
CreateQualificationCommand,
|
||||
DeleteQualificationCommand,
|
||||
UpdateQualificationCommand,
|
||||
} from "../../command/qualificationCommand";
|
||||
import QualificationCommandHandler from "../../command/qualificationCommandHandler";
|
||||
} from "../../../command/settings/qualification/qualificationCommand";
|
||||
import QualificationCommandHandler from "../../../command/settings/qualification/qualificationCommandHandler";
|
||||
|
||||
/**
|
||||
* @description get all qualifications
|
93
src/controller/admin/settings/queryStoreController.ts
Normal file
93
src/controller/admin/settings/queryStoreController.ts
Normal file
|
@ -0,0 +1,93 @@
|
|||
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);
|
||||
}
|
120
src/controller/admin/settings/templateController.ts
Normal file
120
src/controller/admin/settings/templateController.ts
Normal file
|
@ -0,0 +1,120 @@
|
|||
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);
|
||||
}
|
95
src/controller/admin/settings/templateUsageController.ts
Normal file
95
src/controller/admin/settings/templateUsageController.ts
Normal file
|
@ -0,0 +1,95 @@
|
|||
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);
|
||||
}
|
|
@ -1,12 +1,12 @@
|
|||
import { Request, Response } from "express";
|
||||
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";
|
||||
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";
|
||||
|
||||
/**
|
||||
* @description get All roles
|
|
@ -1,15 +1,15 @@
|
|||
import { Request, Response } from "express";
|
||||
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";
|
||||
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";
|
||||
|
||||
/**
|
||||
* @description get All users
|
||||
|
@ -146,8 +146,7 @@ export async function deleteUser(req: Request, res: Response): Promise<any> {
|
|||
|
||||
try {
|
||||
// sendmail
|
||||
let mailhelper = new MailHelper();
|
||||
await mailhelper.sendMail(
|
||||
await MailHelper.sendMail(
|
||||
user.mail,
|
||||
`Email Bestätigung für Mitglieder Admin-Portal von ${CLUB_NAME}`,
|
||||
`Ihr Nutzerkonto des Adminportals wurde erfolgreich gelöscht.`
|
|
@ -4,13 +4,10 @@ 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/userService";
|
||||
import UserService from "../service/user/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
|
||||
|
@ -22,7 +19,7 @@ export async function login(req: Request, res: Response): Promise<any> {
|
|||
let username = req.body.username;
|
||||
let totp = req.body.totp;
|
||||
|
||||
let { id, secret, mail, firstname, lastname } = await UserService.getByUsername(username);
|
||||
let { id, secret } = await UserService.getByUsername(username);
|
||||
|
||||
let valid = speakeasy.totp.verify({
|
||||
secret: secret,
|
||||
|
@ -35,38 +32,13 @@ export async function login(req: Request, res: Response): Promise<any> {
|
|||
throw new UnauthorizedRequestException("Token not valid or expired");
|
||||
}
|
||||
|
||||
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 accessToken = await JWTHelper.buildToken(id);
|
||||
|
||||
let refreshCommand: CreateRefreshCommand = {
|
||||
userId: id,
|
||||
isFromPwa: req.isPWA,
|
||||
};
|
||||
refreshToken = await RefreshCommandHandler.create(refreshCommand);
|
||||
let refreshToken = await RefreshCommandHandler.create(refreshCommand);
|
||||
|
||||
res.json({
|
||||
accessToken,
|
||||
|
@ -105,39 +77,16 @@ export async function refresh(req: Request, res: Response): Promise<any> {
|
|||
throw new UnauthorizedRequestException("user not identified with token and refresh");
|
||||
}
|
||||
|
||||
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 accessToken = await JWTHelper.buildToken(tokenUserId);
|
||||
|
||||
let refreshCommand: CreateRefreshCommand = {
|
||||
userId: id,
|
||||
userId: tokenUserId,
|
||||
isFromPwa: req.isPWA,
|
||||
};
|
||||
refreshToken = await RefreshCommandHandler.create(refreshCommand);
|
||||
let refreshToken = await RefreshCommandHandler.create(refreshCommand);
|
||||
|
||||
let removeToken: DeleteRefreshCommand = {
|
||||
userId: id,
|
||||
userId: tokenUserId,
|
||||
token: refresh,
|
||||
};
|
||||
await RefreshCommandHandler.deleteByToken(removeToken);
|
||||
|
|
|
@ -7,17 +7,30 @@ import { CreateRefreshCommand } from "../command/refreshCommand";
|
|||
import speakeasy from "speakeasy";
|
||||
import UnauthorizedRequestException from "../exceptions/unauthorizedRequestException";
|
||||
import QRCode from "qrcode";
|
||||
import { CreateUserCommand } from "../command/userCommand";
|
||||
import UserCommandHandler from "../command/userCommandHandler";
|
||||
import { CreateInviteCommand, DeleteInviteCommand } from "../command/inviteCommand";
|
||||
import InviteCommandHandler from "../command/inviteCommandHandler";
|
||||
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 MailHelper from "../helpers/mailHelper";
|
||||
import InviteService from "../service/inviteService";
|
||||
import UserService from "../service/userService";
|
||||
import InviteService from "../service/user/inviteService";
|
||||
import UserService from "../service/user/userService";
|
||||
import CustomRequestException from "../exceptions/customRequestException";
|
||||
import { CLUB_NAME } from "../env.defaults";
|
||||
import { CreateUserPermissionCommand } from "../command/userPermissionCommand";
|
||||
import UserPermissionCommandHandler from "../command/userPermissionCommandHandler";
|
||||
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));
|
||||
}
|
||||
|
||||
/**
|
||||
* @description start first user
|
||||
|
@ -58,8 +71,7 @@ export async function inviteUser(req: Request, res: Response, isInvite: boolean
|
|||
let token = await InviteCommandHandler.create(createInvite);
|
||||
|
||||
// sendmail
|
||||
let mailhelper = new MailHelper();
|
||||
await mailhelper.sendMail(
|
||||
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}`
|
||||
|
@ -78,7 +90,7 @@ export async function verifyInvite(req: Request, res: Response): Promise<any> {
|
|||
let mail = req.body.mail;
|
||||
let token = req.body.token;
|
||||
|
||||
let { secret } = await InviteService.getByMailAndToken(mail, token);
|
||||
let { secret, username } = await InviteService.getByMailAndToken(mail, token);
|
||||
|
||||
const url = `otpauth://totp/Mitgliederverwaltung ${CLUB_NAME}?secret=${secret}`;
|
||||
|
||||
|
@ -87,6 +99,7 @@ export async function verifyInvite(req: Request, res: Response): Promise<any> {
|
|||
res.json({
|
||||
dataUrl: result,
|
||||
otp: secret,
|
||||
username,
|
||||
});
|
||||
})
|
||||
.catch((err) => {
|
||||
|
@ -124,43 +137,16 @@ export async function finishInvite(req: Request, res: Response, grantAdmin: bool
|
|||
lastname: lastname,
|
||||
mail: mail,
|
||||
secret: secret,
|
||||
isOwner: grantAdmin,
|
||||
};
|
||||
let id = await UserCommandHandler.create(createUser);
|
||||
|
||||
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 accessToken = await JWTHelper.buildToken(id);
|
||||
|
||||
let refreshCommand: CreateRefreshCommand = {
|
||||
userId: id,
|
||||
};
|
||||
refreshToken = await RefreshCommandHandler.create(refreshCommand);
|
||||
let refreshToken = await RefreshCommandHandler.create(refreshCommand);
|
||||
|
||||
let deleteInvite: DeleteInviteCommand = {
|
||||
mail: mail,
|
||||
|
@ -173,3 +159,17 @@ 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);
|
||||
}
|
||||
|
|
53
src/controller/publicController.ts
Normal file
53
src/controller/publicController.ts
Normal file
|
@ -0,0 +1,53 @@
|
|||
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);
|
||||
}
|
||||
}
|
128
src/controller/resetController.ts
Normal file
128
src/controller/resetController.ts
Normal file
|
@ -0,0 +1,128 @@
|
|||
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,
|
||||
});
|
||||
}
|
121
src/controller/userController.ts
Normal file
121
src/controller/userController.ts
Normal file
|
@ -0,0 +1,121 @@
|
|||
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);
|
||||
}
|
|
@ -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 } from "./env.defaults";
|
||||
import { DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME, DB_TYPE, DB_PORT } from "./env.defaults";
|
||||
|
||||
import { user } from "./entity/user";
|
||||
import { user } from "./entity/user/user";
|
||||
import { refresh } from "./entity/refresh";
|
||||
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 { 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 { Initial1724317398939 } from "./migrations/1724317398939-initial";
|
||||
import { RefreshPrimaryChange1724573307851 } from "./migrations/1724573307851-refreshPrimaryChange";
|
||||
|
@ -22,18 +22,57 @@ 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/member";
|
||||
import { memberAwards } from "./entity/memberAwards";
|
||||
import { memberExecutivePositions } from "./entity/memberExecutivePositions";
|
||||
import { memberQualifications } from "./entity/memberQualifications";
|
||||
import { membership } from "./entity/membership";
|
||||
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 { 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: 3306,
|
||||
port: DB_PORT,
|
||||
username: DB_USERNAME,
|
||||
password: DB_PASSWORD,
|
||||
database: DB_NAME,
|
||||
|
@ -44,6 +83,7 @@ const dataSource = new DataSource({
|
|||
user,
|
||||
refresh,
|
||||
invite,
|
||||
reset,
|
||||
userPermission,
|
||||
role,
|
||||
rolePermission,
|
||||
|
@ -58,6 +98,25 @@ 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,
|
||||
|
@ -68,6 +127,25 @@ 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",
|
||||
|
|
13
src/demodata/member.list.data.ts
Normal file
13
src/demodata/member.list.data.ts
Normal file
|
@ -0,0 +1,13 @@
|
|||
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",
|
||||
},
|
||||
]
|
||||
}
|
72
src/demodata/newsletter.data.ts
Normal file
72
src/demodata/newsletter.data.ts
Normal file
|
@ -0,0 +1,72 @@
|
|||
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",
|
||||
},
|
||||
};
|
58
src/demodata/protocol.data.ts
Normal file
58
src/demodata/protocol.data.ts
Normal file
|
@ -0,0 +1,58 @@
|
|||
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,
|
||||
},
|
||||
],
|
||||
};
|
52
src/entity/club/calendar.ts
Normal file
52
src/entity/club/calendar.ts
Normal file
|
@ -0,0 +1,52 @@
|
|||
import {
|
||||
Column,
|
||||
Entity,
|
||||
ManyToOne,
|
||||
PrimaryColumn,
|
||||
PrimaryGeneratedColumn,
|
||||
CreateDateColumn,
|
||||
UpdateDateColumn,
|
||||
AfterUpdate,
|
||||
BeforeUpdate,
|
||||
} from "typeorm";
|
||||
import { calendarType } from "../settings/calendarType";
|
||||
|
||||
@Entity()
|
||||
export class calendar {
|
||||
@PrimaryGeneratedColumn("uuid")
|
||||
id: string;
|
||||
|
||||
@Column({ type: "datetime", nullable: false })
|
||||
starttime: Date;
|
||||
|
||||
@Column({ type: "datetime", nullable: false })
|
||||
endtime: Date;
|
||||
|
||||
@Column({ type: "varchar", length: 255, nullable: false })
|
||||
title: string;
|
||||
|
||||
@Column({ type: "text", nullable: true })
|
||||
content: string;
|
||||
|
||||
@Column({ type: "text", nullable: true })
|
||||
location: string;
|
||||
|
||||
@Column({ type: "boolean", default: false })
|
||||
allDay: boolean;
|
||||
|
||||
@Column({ type: "int", default: 1 })
|
||||
sequence: number;
|
||||
|
||||
@CreateDateColumn()
|
||||
createdAt: Date;
|
||||
|
||||
@UpdateDateColumn()
|
||||
updatedAt: Date;
|
||||
|
||||
@ManyToOne(() => calendarType, (t) => t.calendar, {
|
||||
nullable: false,
|
||||
onDelete: "RESTRICT",
|
||||
onUpdate: "RESTRICT",
|
||||
})
|
||||
type: calendarType;
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
import { Column, Entity, JoinColumn, ManyToOne, PrimaryColumn } from "typeorm";
|
||||
import { Column, Entity, ManyToOne, PrimaryColumn } from "typeorm";
|
||||
import { member } from "./member";
|
||||
import { communicationType } from "./communicationType";
|
||||
import { communicationType } from "../../settings/communicationType";
|
||||
|
||||
@Entity()
|
||||
export class communication {
|
||||
|
@ -10,12 +10,18 @@ export class communication {
|
|||
@Column({ type: "boolean", default: false })
|
||||
preferred: boolean;
|
||||
|
||||
@Column({ type: "boolean", default: false })
|
||||
isSMSAlarming: boolean;
|
||||
|
||||
@Column({ type: "varchar", length: 255, nullable: true })
|
||||
mobile: string;
|
||||
|
||||
@Column({ type: "varchar", length: 255, nullable: true })
|
||||
email: string;
|
||||
|
||||
@Column({ type: "varchar", length: 255, nullable: true })
|
||||
postalCode: string;
|
||||
|
||||
@Column({ type: "varchar", length: 255, nullable: true })
|
||||
city: string;
|
||||
|
||||
|
@ -28,12 +34,11 @@ export class communication {
|
|||
@Column({ type: "varchar", length: 255, nullable: true })
|
||||
streetNumberAddition: string;
|
||||
|
||||
@ManyToOne(() => communicationType, (communicationType) => communicationType.communications, {
|
||||
nullable: false,
|
||||
onDelete: "RESTRICT",
|
||||
onUpdate: "RESTRICT",
|
||||
})
|
||||
type: communicationType;
|
||||
@Column()
|
||||
memberId: number;
|
||||
|
||||
@Column()
|
||||
typeId: number;
|
||||
|
||||
@ManyToOne(() => member, (member) => member.awards, {
|
||||
nullable: false,
|
||||
|
@ -41,4 +46,11 @@ export class communication {
|
|||
onUpdate: "RESTRICT",
|
||||
})
|
||||
member: member;
|
||||
|
||||
@ManyToOne(() => communicationType, (communicationType) => communicationType.communications, {
|
||||
nullable: false,
|
||||
onDelete: "RESTRICT",
|
||||
onUpdate: "RESTRICT",
|
||||
})
|
||||
type: communicationType;
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue