Compare commits
173 commits
anton/expo
...
main
Author | SHA1 | Date | |
---|---|---|---|
1d9970fc56 | |||
29be563942 | |||
fc694aa976 | |||
7c08251ff6 | |||
7a3a8a9d87 | |||
3165eb789f | |||
ebe587756a | |||
b678067874 | |||
eb78934959 | |||
1ab4d93d2b | |||
b55d0554e4 | |||
21cf811a56 | |||
ff651b7d8f | |||
d9132e472b | |||
c661a588c5 | |||
3beeec38f9 | |||
3d8f1da059 | |||
bbfdc69049 | |||
a165231c47 | |||
313785b4ac | |||
0b40b9d92c | |||
d3870b4c8d | |||
ba2155d7c3 | |||
07d31bfe7d | |||
4568bef10e | |||
36ecccd0dc | |||
3f0549bd44 | |||
ca6dbafaf1 | |||
26d2f288e9 | |||
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 |
330 changed files with 12570 additions and 984 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_TYPE = (mysql|sqlite|...)
|
||||||
|
DB_PORT = number
|
||||||
DB_HOST = database_host
|
DB_HOST = database_host
|
||||||
DB_NAME = database_name
|
DB_NAME = database_name
|
||||||
DB_USERNAME = database_username
|
DB_USERNAME = database_username
|
||||||
|
@ -9,6 +10,7 @@ SERVER_PORT = portnumber
|
||||||
JWT_SECRET = ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890
|
JWT_SECRET = ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890
|
||||||
JWT_EXPIRATION = [0-9]*(y|d|h|m|s)
|
JWT_EXPIRATION = [0-9]*(y|d|h|m|s)
|
||||||
REFRESH_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_USERNAME = mail_username
|
||||||
MAIL_PASSWORD = mail_password
|
MAIL_PASSWORD = mail_password
|
||||||
|
@ -16,4 +18,5 @@ MAIL_HOST = mail_hoststring
|
||||||
MAIL_PORT = mail_portnumber
|
MAIL_PORT = mail_portnumber
|
||||||
MAIL_SECURE (true|false) // true for port 465, fals for other ports
|
MAIL_SECURE (true|false) // true for port 465, fals for other ports
|
||||||
|
|
||||||
CLUB_NAME = clubname
|
CLUB_NAME = clubname #default FF Admin
|
||||||
|
CLUB_WEBSITE = https://my-club-website-url
|
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -130,3 +130,6 @@ dist
|
||||||
.yarn/install-state.gz
|
.yarn/install-state.gz
|
||||||
.pnp.*
|
.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.
|
## Einleitung
|
||||||
Login is possible via Username and TOTP.
|
|
||||||
|
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
|
## 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
|
### Docker Compose Setup
|
||||||
2. Access to the internet for sending Mails
|
|
||||||
|
|
||||||
### 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
|
```yaml
|
||||||
2. Create a new Database in MySql named as in the .env file
|
version: "3"
|
||||||
3. Install all packages via `npm install`
|
|
||||||
4. Start the application to create the database schema
|
|
||||||
|
|
||||||
## Testing
|
services:
|
||||||
|
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=ff-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> # default ist auf FF Admin gesetzt
|
||||||
|
- 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)
|
ff-db:
|
||||||
2. Configure type inside src/data-source.ts to run the database-system you like.
|
image: mariadb:11.2
|
||||||
3. Set migrationsRun to false and synchronize to true for rapid prototyping
|
container_name: ff_db
|
||||||
4. Building the schema via CLI:
|
restart: unless-stopped
|
||||||
- Run `npm run update-database` to build the schema using the migrations without starting the application
|
environment:
|
||||||
- Run `npm run synchronize-database` to build the schema without using migrations without starting the application
|
- MYSQL_DATABASE=ffadmin
|
||||||
5. Run `npm run dev` to run inside dev-environment (runs migrations if migrationsRun is set to true)
|
- 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.
|
||||||
|
|
1288
package-lock.json
generated
1288
package-lock.json
generated
File diff suppressed because it is too large
Load diff
12
package.json
12
package.json
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "member-administration-server",
|
"name": "ff-admin-server",
|
||||||
"version": "0.0.2",
|
"version": "1.2.2",
|
||||||
"description": "Feuerwehr/Verein Mitgliederverwaltung Server",
|
"description": "Feuerwehr/Verein Mitgliederverwaltung Server",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -16,7 +16,7 @@
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"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": [
|
"keywords": [
|
||||||
"Feuerwehr"
|
"Feuerwehr"
|
||||||
|
@ -27,13 +27,19 @@
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"dotenv": "^16.4.5",
|
"dotenv": "^16.4.5",
|
||||||
"express": "^5.0.0-beta.3",
|
"express": "^5.0.0-beta.3",
|
||||||
|
"handlebars": "^4.7.8",
|
||||||
|
"ics": "^3.8.1",
|
||||||
"jsonwebtoken": "^9.0.2",
|
"jsonwebtoken": "^9.0.2",
|
||||||
|
"moment": "^2.30.1",
|
||||||
"ms": "^2.1.3",
|
"ms": "^2.1.3",
|
||||||
"mysql": "^2.18.1",
|
"mysql": "^2.18.1",
|
||||||
"node-schedule": "^2.1.1",
|
"node-schedule": "^2.1.1",
|
||||||
"nodemailer": "^6.9.14",
|
"nodemailer": "^6.9.14",
|
||||||
|
"pdf-lib": "^1.17.1",
|
||||||
|
"puppeteer": "^23.11.1",
|
||||||
"qrcode": "^1.5.4",
|
"qrcode": "^1.5.4",
|
||||||
"reflect-metadata": "^0.2.2",
|
"reflect-metadata": "^0.2.2",
|
||||||
|
"rss-parser": "^3.13.0",
|
||||||
"socket.io": "^4.7.5",
|
"socket.io": "^4.7.5",
|
||||||
"speakeasy": "^2.0.0",
|
"speakeasy": "^2.0.0",
|
||||||
"typeorm": "^0.3.20",
|
"typeorm": "^0.3.20",
|
||||||
|
|
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,10 @@
|
||||||
export interface CreateCommunicationCommand {
|
export interface CreateCommunicationCommand {
|
||||||
preferred: boolean;
|
preferred: boolean;
|
||||||
|
isSMSAlarming: boolean;
|
||||||
|
isSendNewsletter: boolean;
|
||||||
mobile: string;
|
mobile: string;
|
||||||
email: string;
|
email: string;
|
||||||
|
postalCode: string;
|
||||||
city: string;
|
city: string;
|
||||||
street: string;
|
street: string;
|
||||||
streetNumber: number;
|
streetNumber: number;
|
||||||
|
@ -13,8 +16,11 @@ export interface CreateCommunicationCommand {
|
||||||
export interface UpdateCommunicationCommand {
|
export interface UpdateCommunicationCommand {
|
||||||
id: number;
|
id: number;
|
||||||
preferred: boolean;
|
preferred: boolean;
|
||||||
|
isSMSAlarming: boolean;
|
||||||
|
isSendNewsletter: boolean;
|
||||||
mobile: string;
|
mobile: string;
|
||||||
email: string;
|
email: string;
|
||||||
|
postalCode: string;
|
||||||
city: string;
|
city: string;
|
||||||
street: string;
|
street: string;
|
||||||
streetNumber: number;
|
streetNumber: number;
|
122
src/command/club/member/communicationCommandHandler.ts
Normal file
122
src/command/club/member/communicationCommandHandler.ts
Normal file
|
@ -0,0 +1,122 @@
|
||||||
|
import { dataSource } from "../../../data-source";
|
||||||
|
import { communication } from "../../../entity/club/member/communication";
|
||||||
|
import InternalException from "../../../exceptions/internalException";
|
||||||
|
import {
|
||||||
|
CreateCommunicationCommand,
|
||||||
|
DeleteCommunicationCommand,
|
||||||
|
UpdateCommunicationCommand,
|
||||||
|
} from "./communicationCommand";
|
||||||
|
|
||||||
|
export default abstract class CommunicationCommandHandler {
|
||||||
|
/**
|
||||||
|
* @description create communication
|
||||||
|
* @param {CreateCommunicationCommand} createCommunication
|
||||||
|
* @returns {Promise<number>}
|
||||||
|
*/
|
||||||
|
static async create(createCommunication: CreateCommunicationCommand): Promise<number> {
|
||||||
|
let insertId = -1;
|
||||||
|
return await dataSource
|
||||||
|
.transaction(async (manager) => {
|
||||||
|
await manager
|
||||||
|
.createQueryBuilder()
|
||||||
|
.insert()
|
||||||
|
.into(communication)
|
||||||
|
.values({
|
||||||
|
preferred: createCommunication.preferred,
|
||||||
|
isSMSAlarming: createCommunication.isSMSAlarming,
|
||||||
|
isSendNewsletter: createCommunication.isSendNewsletter,
|
||||||
|
mobile: createCommunication.mobile,
|
||||||
|
email: createCommunication.email,
|
||||||
|
postalCode: createCommunication.postalCode,
|
||||||
|
city: createCommunication.city,
|
||||||
|
street: createCommunication.street,
|
||||||
|
streetNumber: createCommunication.streetNumber,
|
||||||
|
streetNumberAddition: createCommunication.streetNumberAddition,
|
||||||
|
memberId: createCommunication.memberId,
|
||||||
|
typeId: createCommunication.typeId,
|
||||||
|
})
|
||||||
|
.execute()
|
||||||
|
.then((result) => {
|
||||||
|
insertId = result.identifiers[0].id;
|
||||||
|
});
|
||||||
|
|
||||||
|
await manager
|
||||||
|
.createQueryBuilder()
|
||||||
|
.update(communication)
|
||||||
|
.set({
|
||||||
|
isSendNewsletter: false,
|
||||||
|
})
|
||||||
|
.where("memberId = :memberId", { memberId: createCommunication.memberId })
|
||||||
|
.andWhere("id <> :id", { id: insertId })
|
||||||
|
.execute();
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
return insertId;
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
throw new InternalException("Failed creating communication", err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description update communication
|
||||||
|
* @param {UpdateCommunicationCommand} updateCommunication
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
static async update(updateCommunication: UpdateCommunicationCommand): Promise<void> {
|
||||||
|
return await dataSource
|
||||||
|
.transaction(async (manager) => {
|
||||||
|
await manager
|
||||||
|
.createQueryBuilder()
|
||||||
|
.update(communication)
|
||||||
|
.set({
|
||||||
|
preferred: updateCommunication.preferred,
|
||||||
|
isSMSAlarming: updateCommunication.isSMSAlarming,
|
||||||
|
isSendNewsletter: updateCommunication.isSendNewsletter,
|
||||||
|
mobile: updateCommunication.mobile,
|
||||||
|
email: updateCommunication.email,
|
||||||
|
postalCode: updateCommunication.postalCode,
|
||||||
|
city: updateCommunication.city,
|
||||||
|
street: updateCommunication.street,
|
||||||
|
streetNumber: updateCommunication.streetNumber,
|
||||||
|
streetNumberAddition: updateCommunication.streetNumberAddition,
|
||||||
|
})
|
||||||
|
.where("id = :id", { id: updateCommunication.id })
|
||||||
|
.andWhere("memberId = :memberId", { memberId: updateCommunication.memberId })
|
||||||
|
.execute();
|
||||||
|
|
||||||
|
await manager
|
||||||
|
.createQueryBuilder()
|
||||||
|
.update(communication)
|
||||||
|
.set({
|
||||||
|
isSendNewsletter: false,
|
||||||
|
})
|
||||||
|
.where("memberId = :memberId", { memberId: updateCommunication.memberId })
|
||||||
|
.andWhere("id <> :id", { id: updateCommunication.id })
|
||||||
|
.execute();
|
||||||
|
})
|
||||||
|
.then(() => {})
|
||||||
|
.catch((err) => {
|
||||||
|
throw new InternalException("Failed updating communication", err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description delete communication
|
||||||
|
* @param {DeleteCommunicationCommand} deleteCommunication
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
static async delete(deleteCommunication: DeleteCommunicationCommand): Promise<void> {
|
||||||
|
return await dataSource
|
||||||
|
.createQueryBuilder()
|
||||||
|
.delete()
|
||||||
|
.from(communication)
|
||||||
|
.where("id = :id", { id: deleteCommunication.id })
|
||||||
|
.andWhere("memberId = :memberId", { memberId: deleteCommunication.memberId })
|
||||||
|
.execute()
|
||||||
|
.then(() => {})
|
||||||
|
.catch((err) => {
|
||||||
|
throw new InternalException("Failed deleting communication", err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,14 +1,12 @@
|
||||||
import { dataSource } from "../data-source";
|
import { dataSource } from "../../../data-source";
|
||||||
import { award } from "../entity/award";
|
import { memberAwards } from "../../../entity/club/member/memberAwards";
|
||||||
import { memberAwards } from "../entity/memberAwards";
|
import InternalException from "../../../exceptions/internalException";
|
||||||
import { user } from "../entity/user";
|
|
||||||
import InternalException from "../exceptions/internalException";
|
|
||||||
import { CreateMemberAwardCommand, DeleteMemberAwardCommand, UpdateMemberAwardCommand } from "./memberAwardCommand";
|
import { CreateMemberAwardCommand, DeleteMemberAwardCommand, UpdateMemberAwardCommand } from "./memberAwardCommand";
|
||||||
|
|
||||||
export default abstract class MemberAwardCommandHandler {
|
export default abstract class MemberAwardCommandHandler {
|
||||||
/**
|
/**
|
||||||
* @description create memberAward
|
* @description create memberAward
|
||||||
* @param CreateMemberAwardCommand
|
* @param {CreateMemberAwardCommand} createMemberAward
|
||||||
* @returns {Promise<number>}
|
* @returns {Promise<number>}
|
||||||
*/
|
*/
|
||||||
static async create(createMemberAward: CreateMemberAwardCommand): Promise<number> {
|
static async create(createMemberAward: CreateMemberAwardCommand): Promise<number> {
|
||||||
|
@ -20,16 +18,8 @@ export default abstract class MemberAwardCommandHandler {
|
||||||
given: createMemberAward.given,
|
given: createMemberAward.given,
|
||||||
note: createMemberAward.note,
|
note: createMemberAward.note,
|
||||||
date: createMemberAward.date,
|
date: createMemberAward.date,
|
||||||
member: await dataSource
|
memberId: createMemberAward.memberId,
|
||||||
.getRepository(user)
|
awardId: createMemberAward.awardId,
|
||||||
.createQueryBuilder("user")
|
|
||||||
.where("id = :id", { id: createMemberAward.memberId })
|
|
||||||
.getOneOrFail(),
|
|
||||||
award: await dataSource
|
|
||||||
.getRepository(award)
|
|
||||||
.createQueryBuilder("award")
|
|
||||||
.where("id = :id", { id: createMemberAward.awardId })
|
|
||||||
.getOneOrFail(),
|
|
||||||
})
|
})
|
||||||
.execute()
|
.execute()
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
|
@ -42,7 +32,7 @@ export default abstract class MemberAwardCommandHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description update memberAward
|
* @description update memberAward
|
||||||
* @param UpdateMemberAwardCommand
|
* @param {UpdateMemberAwardCommand} updateMemberAward
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async update(updateMemberAward: UpdateMemberAwardCommand): Promise<void> {
|
static async update(updateMemberAward: UpdateMemberAwardCommand): Promise<void> {
|
||||||
|
@ -53,11 +43,7 @@ export default abstract class MemberAwardCommandHandler {
|
||||||
given: updateMemberAward.given,
|
given: updateMemberAward.given,
|
||||||
note: updateMemberAward.note,
|
note: updateMemberAward.note,
|
||||||
date: updateMemberAward.date,
|
date: updateMemberAward.date,
|
||||||
award: await dataSource
|
award: updateMemberAward.awardId,
|
||||||
.getRepository(award)
|
|
||||||
.createQueryBuilder("award")
|
|
||||||
.where("id = :id", { id: updateMemberAward.awardId })
|
|
||||||
.getOneOrFail(),
|
|
||||||
})
|
})
|
||||||
.where("id = :id", { id: updateMemberAward.id })
|
.where("id = :id", { id: updateMemberAward.id })
|
||||||
.andWhere("memberId = :memberId", { memberId: updateMemberAward.memberId })
|
.andWhere("memberId = :memberId", { memberId: updateMemberAward.memberId })
|
||||||
|
@ -70,16 +56,16 @@ export default abstract class MemberAwardCommandHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description delete memberAward
|
* @description delete memberAward
|
||||||
* @param DeleteMemberAwardCommand
|
* @param {DeleteMemberAwardCommand} deleteMemberAward
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async delete(deletMemberAward: DeleteMemberAwardCommand): Promise<void> {
|
static async delete(deleteMemberAward: DeleteMemberAwardCommand): Promise<void> {
|
||||||
return await dataSource
|
return await dataSource
|
||||||
.createQueryBuilder()
|
.createQueryBuilder()
|
||||||
.delete()
|
.delete()
|
||||||
.from(memberAwards)
|
.from(memberAwards)
|
||||||
.where("id = :id", { id: deletMemberAward.id })
|
.where("id = :id", { id: deleteMemberAward.id })
|
||||||
.andWhere("memberId = :memberId", { memberId: deletMemberAward.memberId })
|
.andWhere("memberId = :memberId", { memberId: deleteMemberAward.memberId })
|
||||||
.execute()
|
.execute()
|
||||||
.then(() => {})
|
.then(() => {})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
|
@ -1,25 +1,20 @@
|
||||||
import { Salutation } from "../enums/salutation";
|
|
||||||
|
|
||||||
export interface CreateMemberCommand {
|
export interface CreateMemberCommand {
|
||||||
salutation: Salutation;
|
salutationId: number;
|
||||||
firstname: string;
|
firstname: string;
|
||||||
lastname: string;
|
lastname: string;
|
||||||
nameaffix: string;
|
nameaffix: string;
|
||||||
birthdate: Date;
|
birthdate: Date;
|
||||||
|
internalId?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UpdateMemberCommand {
|
export interface UpdateMemberCommand {
|
||||||
id: number;
|
id: number;
|
||||||
salutation: Salutation;
|
salutationId: number;
|
||||||
firstname: string;
|
firstname: string;
|
||||||
lastname: string;
|
lastname: string;
|
||||||
nameaffix: string;
|
nameaffix: string;
|
||||||
birthdate: Date;
|
birthdate: Date;
|
||||||
}
|
internalId?: string;
|
||||||
|
|
||||||
export interface UpdateMemberNewsletterCommand {
|
|
||||||
id: number;
|
|
||||||
communicationId: number;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DeleteMemberCommand {
|
export interface DeleteMemberCommand {
|
|
@ -1,19 +1,13 @@
|
||||||
import { dataSource } from "../data-source";
|
import { dataSource } from "../../../data-source";
|
||||||
import { communication } from "../entity/communication";
|
import { communication } from "../../../entity/club/member/communication";
|
||||||
import { member } from "../entity/member";
|
import { member } from "../../../entity/club/member/member";
|
||||||
import InternalException from "../exceptions/internalException";
|
import InternalException from "../../../exceptions/internalException";
|
||||||
import CommunicationService from "../service/communicationService";
|
import { CreateMemberCommand, DeleteMemberCommand, UpdateMemberCommand } from "./memberCommand";
|
||||||
import {
|
|
||||||
CreateMemberCommand,
|
|
||||||
DeleteMemberCommand,
|
|
||||||
UpdateMemberCommand,
|
|
||||||
UpdateMemberNewsletterCommand,
|
|
||||||
} from "./memberCommand";
|
|
||||||
|
|
||||||
export default abstract class MemberCommandHandler {
|
export default abstract class MemberCommandHandler {
|
||||||
/**
|
/**
|
||||||
* @description create member
|
* @description create member
|
||||||
* @param CreateMemberCommand
|
* @param {CreateMemberCommand} createMember
|
||||||
* @returns {Promise<number>}
|
* @returns {Promise<number>}
|
||||||
*/
|
*/
|
||||||
static async create(createMember: CreateMemberCommand): Promise<number> {
|
static async create(createMember: CreateMemberCommand): Promise<number> {
|
||||||
|
@ -22,75 +16,56 @@ export default abstract class MemberCommandHandler {
|
||||||
.insert()
|
.insert()
|
||||||
.into(member)
|
.into(member)
|
||||||
.values({
|
.values({
|
||||||
salutation: createMember.salutation,
|
salutationId: createMember.salutationId,
|
||||||
firstname: createMember.firstname,
|
firstname: createMember.firstname,
|
||||||
lastname: createMember.lastname,
|
lastname: createMember.lastname,
|
||||||
nameaffix: createMember.nameaffix,
|
nameaffix: createMember.nameaffix,
|
||||||
birthdate: createMember.birthdate,
|
birthdate: createMember.birthdate,
|
||||||
|
internalId: createMember.internalId,
|
||||||
})
|
})
|
||||||
.execute()
|
.execute()
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
return result.identifiers[0].id;
|
return result.identifiers[0].id;
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
throw new InternalException("Failed creating member", err);
|
throw new InternalException(
|
||||||
|
`Failed creating member${err.code.includes("ER_DUP_ENTRY") ? " due to duplicate entry for column" : ""}`,
|
||||||
|
err
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description update member
|
* @description update member
|
||||||
* @param UpdateMemberCommand
|
* @param {UpdateMemberCommand} updateMember
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async update(updateMember: UpdateMemberCommand): Promise<void> {
|
static async update(updateMember: UpdateMemberCommand): Promise<void> {
|
||||||
console.log(updateMember);
|
|
||||||
return await dataSource
|
return await dataSource
|
||||||
.createQueryBuilder()
|
.createQueryBuilder()
|
||||||
.update(member)
|
.update(member)
|
||||||
.set({
|
.set({
|
||||||
salutation: updateMember.salutation,
|
salutationId: updateMember.salutationId,
|
||||||
firstname: updateMember.firstname,
|
firstname: updateMember.firstname,
|
||||||
lastname: updateMember.lastname,
|
lastname: updateMember.lastname,
|
||||||
nameaffix: updateMember.nameaffix,
|
nameaffix: updateMember.nameaffix,
|
||||||
birthdate: updateMember.birthdate,
|
birthdate: updateMember.birthdate,
|
||||||
|
internalId: updateMember.internalId,
|
||||||
})
|
})
|
||||||
.where("id = :id", { id: updateMember.id })
|
.where("id = :id", { id: updateMember.id })
|
||||||
.execute()
|
.execute()
|
||||||
.then(() => {})
|
.then(() => {})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
throw new InternalException("Failed updating member", err);
|
throw new InternalException(
|
||||||
});
|
`Failed updating member${err.code.includes("ER_DUP_ENTRY") ? " due to duplicate entry for column" : ""}`,
|
||||||
}
|
err
|
||||||
|
);
|
||||||
/**
|
|
||||||
* @description update member newsletter
|
|
||||||
* @param UpdateMemberCommand
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
static async updateNewsletter(updateMember: UpdateMemberNewsletterCommand): Promise<void> {
|
|
||||||
console.log(updateMember);
|
|
||||||
return await dataSource
|
|
||||||
.createQueryBuilder()
|
|
||||||
.update(member)
|
|
||||||
.set({
|
|
||||||
sendNewsletter: await dataSource
|
|
||||||
.getRepository(communication)
|
|
||||||
.createQueryBuilder("communication")
|
|
||||||
.where("id = :id", { id: updateMember.communicationId })
|
|
||||||
.andWhere("memberId = :memberId", { memberId: updateMember.id })
|
|
||||||
.getOneOrFail(),
|
|
||||||
})
|
|
||||||
.where("id = :id", { id: updateMember.id })
|
|
||||||
.execute()
|
|
||||||
.then(() => {})
|
|
||||||
.catch((err) => {
|
|
||||||
throw new InternalException("Failed updating member", err);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description delete member
|
* @description delete member
|
||||||
* @param DeleteMemberCommand
|
* @param {DeleteMemberCommand} deleteMember
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async delete(deleteMember: DeleteMemberCommand): Promise<void> {
|
static async delete(deleteMember: DeleteMemberCommand): Promise<void> {
|
|
@ -1,8 +1,6 @@
|
||||||
import { dataSource } from "../data-source";
|
import { dataSource } from "../../../data-source";
|
||||||
import { executivePosition } from "../entity/executivePosition";
|
import { memberExecutivePositions } from "../../../entity/club/member/memberExecutivePositions";
|
||||||
import { memberExecutivePositions } from "../entity/memberExecutivePositions";
|
import InternalException from "../../../exceptions/internalException";
|
||||||
import { user } from "../entity/user";
|
|
||||||
import InternalException from "../exceptions/internalException";
|
|
||||||
import {
|
import {
|
||||||
CreateMemberExecutivePositionCommand,
|
CreateMemberExecutivePositionCommand,
|
||||||
DeleteMemberExecutivePositionCommand,
|
DeleteMemberExecutivePositionCommand,
|
||||||
|
@ -12,7 +10,7 @@ import {
|
||||||
export default abstract class MemberExecutivePositionCommandHandler {
|
export default abstract class MemberExecutivePositionCommandHandler {
|
||||||
/**
|
/**
|
||||||
* @description create memberExecutivePosition
|
* @description create memberExecutivePosition
|
||||||
* @param CreateMemberExecutivePositionCommand
|
* @param {CreateMemberExecutivePositionCommand} createMemberExecutivePosition
|
||||||
* @returns {Promise<number>}
|
* @returns {Promise<number>}
|
||||||
*/
|
*/
|
||||||
static async create(createMemberExecutivePosition: CreateMemberExecutivePositionCommand): Promise<number> {
|
static async create(createMemberExecutivePosition: CreateMemberExecutivePositionCommand): Promise<number> {
|
||||||
|
@ -24,16 +22,8 @@ export default abstract class MemberExecutivePositionCommandHandler {
|
||||||
note: createMemberExecutivePosition.note,
|
note: createMemberExecutivePosition.note,
|
||||||
start: createMemberExecutivePosition.start,
|
start: createMemberExecutivePosition.start,
|
||||||
end: createMemberExecutivePosition.end,
|
end: createMemberExecutivePosition.end,
|
||||||
member: await dataSource
|
memberId: createMemberExecutivePosition.memberId,
|
||||||
.getRepository(user)
|
executivePositionId: createMemberExecutivePosition.executivePositionId,
|
||||||
.createQueryBuilder("user")
|
|
||||||
.where("id = :id", { id: createMemberExecutivePosition.memberId })
|
|
||||||
.getOneOrFail(),
|
|
||||||
executivePosition: await dataSource
|
|
||||||
.getRepository(executivePosition)
|
|
||||||
.createQueryBuilder("executivePosition")
|
|
||||||
.where("id = :id", { id: createMemberExecutivePosition.executivePositionId })
|
|
||||||
.getOneOrFail(),
|
|
||||||
})
|
})
|
||||||
.execute()
|
.execute()
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
|
@ -46,7 +36,7 @@ export default abstract class MemberExecutivePositionCommandHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description update memberExecutivePosition
|
* @description update memberExecutivePosition
|
||||||
* @param UpdateMemberExecutivePositionCommand
|
* @param {UpdateMemberExecutivePositionCommand} updateMemberExecutivePosition
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async update(updateMemberExecutivePosition: UpdateMemberExecutivePositionCommand): Promise<void> {
|
static async update(updateMemberExecutivePosition: UpdateMemberExecutivePositionCommand): Promise<void> {
|
||||||
|
@ -57,11 +47,7 @@ export default abstract class MemberExecutivePositionCommandHandler {
|
||||||
note: updateMemberExecutivePosition.note,
|
note: updateMemberExecutivePosition.note,
|
||||||
start: updateMemberExecutivePosition.start,
|
start: updateMemberExecutivePosition.start,
|
||||||
end: updateMemberExecutivePosition.end,
|
end: updateMemberExecutivePosition.end,
|
||||||
executivePosition: await dataSource
|
executivePositionId: updateMemberExecutivePosition.executivePositionId,
|
||||||
.getRepository(executivePosition)
|
|
||||||
.createQueryBuilder("executivePosition")
|
|
||||||
.where("id = :id", { id: updateMemberExecutivePosition.executivePositionId })
|
|
||||||
.getOneOrFail(),
|
|
||||||
})
|
})
|
||||||
.where("id = :id", { id: updateMemberExecutivePosition.id })
|
.where("id = :id", { id: updateMemberExecutivePosition.id })
|
||||||
.andWhere("memberId = :memberId", { memberId: updateMemberExecutivePosition.memberId })
|
.andWhere("memberId = :memberId", { memberId: updateMemberExecutivePosition.memberId })
|
||||||
|
@ -74,16 +60,16 @@ export default abstract class MemberExecutivePositionCommandHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description delete memberExecutivePosition
|
* @description delete memberExecutivePosition
|
||||||
* @param DeleteMemberExecutivePositionCommand
|
* @param {DeleteMemberExecutivePositionCommand} deleteMemberExecutivePosition
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async delete(deletMemberExecutivePosition: DeleteMemberExecutivePositionCommand): Promise<void> {
|
static async delete(deleteMemberExecutivePosition: DeleteMemberExecutivePositionCommand): Promise<void> {
|
||||||
return await dataSource
|
return await dataSource
|
||||||
.createQueryBuilder()
|
.createQueryBuilder()
|
||||||
.delete()
|
.delete()
|
||||||
.from(memberExecutivePositions)
|
.from(memberExecutivePositions)
|
||||||
.where("id = :id", { id: deletMemberExecutivePosition.id })
|
.where("id = :id", { id: deleteMemberExecutivePosition.id })
|
||||||
.andWhere("memberId = :memberId", { memberId: deletMemberExecutivePosition.memberId })
|
.andWhere("memberId = :memberId", { memberId: deleteMemberExecutivePosition.memberId })
|
||||||
.execute()
|
.execute()
|
||||||
.then(() => {})
|
.then(() => {})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
|
@ -1,8 +1,6 @@
|
||||||
import { dataSource } from "../data-source";
|
import { dataSource } from "../../../data-source";
|
||||||
import { qualification } from "../entity/qualification";
|
import { memberQualifications } from "../../../entity/club/member/memberQualifications";
|
||||||
import { memberQualifications } from "../entity/memberQualifications";
|
import InternalException from "../../../exceptions/internalException";
|
||||||
import { user } from "../entity/user";
|
|
||||||
import InternalException from "../exceptions/internalException";
|
|
||||||
import {
|
import {
|
||||||
CreateMemberQualificationCommand,
|
CreateMemberQualificationCommand,
|
||||||
DeleteMemberQualificationCommand,
|
DeleteMemberQualificationCommand,
|
||||||
|
@ -12,7 +10,7 @@ import {
|
||||||
export default abstract class MemberQualificationCommandHandler {
|
export default abstract class MemberQualificationCommandHandler {
|
||||||
/**
|
/**
|
||||||
* @description create memberQualification
|
* @description create memberQualification
|
||||||
* @param CreateMemberQualificationCommand
|
* @param {CreateMemberQualificationCommand} createMemberQualification
|
||||||
* @returns {Promise<number>}
|
* @returns {Promise<number>}
|
||||||
*/
|
*/
|
||||||
static async create(createMemberQualification: CreateMemberQualificationCommand): Promise<number> {
|
static async create(createMemberQualification: CreateMemberQualificationCommand): Promise<number> {
|
||||||
|
@ -23,16 +21,8 @@ export default abstract class MemberQualificationCommandHandler {
|
||||||
.values({
|
.values({
|
||||||
note: createMemberQualification.note,
|
note: createMemberQualification.note,
|
||||||
start: createMemberQualification.start,
|
start: createMemberQualification.start,
|
||||||
member: await dataSource
|
memberId: createMemberQualification.memberId,
|
||||||
.getRepository(user)
|
qualificationId: createMemberQualification.qualificationId,
|
||||||
.createQueryBuilder("user")
|
|
||||||
.where("id = :id", { id: createMemberQualification.memberId })
|
|
||||||
.getOneOrFail(),
|
|
||||||
qualification: await dataSource
|
|
||||||
.getRepository(qualification)
|
|
||||||
.createQueryBuilder("qualification")
|
|
||||||
.where("id = :id", { id: createMemberQualification.qualificationId })
|
|
||||||
.getOneOrFail(),
|
|
||||||
})
|
})
|
||||||
.execute()
|
.execute()
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
|
@ -45,7 +35,7 @@ export default abstract class MemberQualificationCommandHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description update memberQualification
|
* @description update memberQualification
|
||||||
* @param UpdateMemberQualificationCommand
|
* @param {UpdateMemberQualificationCommand} updateMemberQualification
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async update(updateMemberQualification: UpdateMemberQualificationCommand): Promise<void> {
|
static async update(updateMemberQualification: UpdateMemberQualificationCommand): Promise<void> {
|
||||||
|
@ -57,11 +47,7 @@ export default abstract class MemberQualificationCommandHandler {
|
||||||
start: updateMemberQualification.start,
|
start: updateMemberQualification.start,
|
||||||
end: updateMemberQualification.end,
|
end: updateMemberQualification.end,
|
||||||
terminationReason: updateMemberQualification.terminationReason,
|
terminationReason: updateMemberQualification.terminationReason,
|
||||||
qualification: await dataSource
|
qualificationId: updateMemberQualification.qualificationId,
|
||||||
.getRepository(qualification)
|
|
||||||
.createQueryBuilder("qualification")
|
|
||||||
.where("id = :id", { id: updateMemberQualification.qualificationId })
|
|
||||||
.getOneOrFail(),
|
|
||||||
})
|
})
|
||||||
.where("id = :id", { id: updateMemberQualification.id })
|
.where("id = :id", { id: updateMemberQualification.id })
|
||||||
.andWhere("memberId = :memberId", { memberId: updateMemberQualification.memberId })
|
.andWhere("memberId = :memberId", { memberId: updateMemberQualification.memberId })
|
||||||
|
@ -74,16 +60,16 @@ export default abstract class MemberQualificationCommandHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description delete memberQualification
|
* @description delete memberQualification
|
||||||
* @param DeleteMemberQualificationCommand
|
* @param {DeleteMemberQualificationCommand} deleteMemberQualification
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async delete(deletMemberQualification: DeleteMemberQualificationCommand): Promise<void> {
|
static async delete(deleteMemberQualification: DeleteMemberQualificationCommand): Promise<void> {
|
||||||
return await dataSource
|
return await dataSource
|
||||||
.createQueryBuilder()
|
.createQueryBuilder()
|
||||||
.delete()
|
.delete()
|
||||||
.from(memberQualifications)
|
.from(memberQualifications)
|
||||||
.where("id = :id", { id: deletMemberQualification.id })
|
.where("id = :id", { id: deleteMemberQualification.id })
|
||||||
.andWhere("memberId = :memberId", { memberId: deletMemberQualification.memberId })
|
.andWhere("memberId = :memberId", { memberId: deleteMemberQualification.memberId })
|
||||||
.execute()
|
.execute()
|
||||||
.then(() => {})
|
.then(() => {})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
|
@ -1,5 +1,4 @@
|
||||||
export interface CreateMembershipCommand {
|
export interface CreateMembershipCommand {
|
||||||
internalId?: string;
|
|
||||||
start: Date;
|
start: Date;
|
||||||
memberId: number;
|
memberId: number;
|
||||||
statusId: number;
|
statusId: number;
|
||||||
|
@ -7,7 +6,6 @@ export interface CreateMembershipCommand {
|
||||||
|
|
||||||
export interface UpdateMembershipCommand {
|
export interface UpdateMembershipCommand {
|
||||||
id: number;
|
id: number;
|
||||||
internalId?: string;
|
|
||||||
start: Date;
|
start: Date;
|
||||||
end?: Date;
|
end?: Date;
|
||||||
terminationReason?: string;
|
terminationReason?: string;
|
|
@ -1,18 +1,16 @@
|
||||||
import { dataSource } from "../data-source";
|
import { dataSource } from "../../../data-source";
|
||||||
import { membership } from "../entity/membership";
|
import { membership } from "../../../entity/club/member/membership";
|
||||||
import { membershipStatus } from "../entity/membershipStatus";
|
import InternalException from "../../../exceptions/internalException";
|
||||||
import { user } from "../entity/user";
|
|
||||||
import InternalException from "../exceptions/internalException";
|
|
||||||
import { CreateMembershipCommand, DeleteMembershipCommand, UpdateMembershipCommand } from "./membershipCommand";
|
import { CreateMembershipCommand, DeleteMembershipCommand, UpdateMembershipCommand } from "./membershipCommand";
|
||||||
|
|
||||||
export default abstract class MembershipCommandHandler {
|
export default abstract class MembershipCommandHandler {
|
||||||
/**
|
/**
|
||||||
* @description create membership
|
* @description create membership
|
||||||
* @param CreateMembershipCommand
|
* @param {CreateMembershipCommand} createMembership
|
||||||
* @returns {Promise<number>}
|
* @returns {Promise<number>}
|
||||||
*/
|
*/
|
||||||
static async create(createMembership: CreateMembershipCommand): Promise<number> {
|
static async create(createMembership: CreateMembershipCommand): Promise<number> {
|
||||||
let insertid = -1;
|
let insertId = -1;
|
||||||
return await dataSource
|
return await dataSource
|
||||||
.transaction(async (manager) => {
|
.transaction(async (manager) => {
|
||||||
await manager
|
await manager
|
||||||
|
@ -20,37 +18,29 @@ export default abstract class MembershipCommandHandler {
|
||||||
.insert()
|
.insert()
|
||||||
.into(membership)
|
.into(membership)
|
||||||
.values({
|
.values({
|
||||||
internalId: createMembership.internalId,
|
|
||||||
start: createMembership.start,
|
start: createMembership.start,
|
||||||
member: await dataSource
|
memberId: createMembership.memberId,
|
||||||
.getRepository(user)
|
statusId: createMembership.statusId,
|
||||||
.createQueryBuilder("user")
|
|
||||||
.where("id = :id", { id: createMembership.memberId })
|
|
||||||
.getOneOrFail(),
|
|
||||||
status: await dataSource
|
|
||||||
.getRepository(membershipStatus)
|
|
||||||
.createQueryBuilder("membershipStatus")
|
|
||||||
.where("id = :id", { id: createMembership.statusId })
|
|
||||||
.getOneOrFail(),
|
|
||||||
})
|
})
|
||||||
.execute()
|
.execute()
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
insertid = result.identifiers[0].id;
|
insertId = result.identifiers[0].id;
|
||||||
});
|
});
|
||||||
|
|
||||||
await manager
|
await manager
|
||||||
.createQueryBuilder()
|
.createQueryBuilder()
|
||||||
.update(membership)
|
.update(membership)
|
||||||
.set({
|
.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")
|
.where("end IS NULL")
|
||||||
.andWhere("memberId = :memberId", { memberId: createMembership.memberId })
|
.andWhere("memberId = :memberId", { memberId: createMembership.memberId })
|
||||||
.andWhere("id <> :id", { id: insertid })
|
.andWhere("id <> :id", { id: insertId })
|
||||||
.execute();
|
.execute();
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
return insertid;
|
return insertId;
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
throw new InternalException("Failed creating membership", err);
|
throw new InternalException("Failed creating membership", err);
|
||||||
|
@ -59,7 +49,7 @@ export default abstract class MembershipCommandHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description update membership
|
* @description update membership
|
||||||
* @param UpdateMembershipCommand
|
* @param {UpdateMembershipCommand} updateMembership
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async update(updateMembership: UpdateMembershipCommand): Promise<void> {
|
static async update(updateMembership: UpdateMembershipCommand): Promise<void> {
|
||||||
|
@ -67,15 +57,10 @@ export default abstract class MembershipCommandHandler {
|
||||||
.createQueryBuilder()
|
.createQueryBuilder()
|
||||||
.update(membership)
|
.update(membership)
|
||||||
.set({
|
.set({
|
||||||
internalId: updateMembership.internalId,
|
|
||||||
start: updateMembership.start,
|
start: updateMembership.start,
|
||||||
end: updateMembership.end,
|
end: updateMembership.end,
|
||||||
terminationReason: updateMembership.terminationReason,
|
terminationReason: updateMembership.terminationReason,
|
||||||
status: await dataSource
|
statusId: updateMembership.statusId,
|
||||||
.getRepository(membershipStatus)
|
|
||||||
.createQueryBuilder("membershipStatus")
|
|
||||||
.where("id = :id", { id: updateMembership.statusId })
|
|
||||||
.getOneOrFail(),
|
|
||||||
})
|
})
|
||||||
.where("id = :id", { id: updateMembership.id })
|
.where("id = :id", { id: updateMembership.id })
|
||||||
.andWhere("memberId = :memberId", { memberId: updateMembership.memberId })
|
.andWhere("memberId = :memberId", { memberId: updateMembership.memberId })
|
||||||
|
@ -88,16 +73,16 @@ export default abstract class MembershipCommandHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description delete membership
|
* @description delete membership
|
||||||
* @param DeleteMembershipCommand
|
* @param {DeleteMembershipCommand} deleteMembership
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async delete(deletMembership: DeleteMembershipCommand): Promise<void> {
|
static async delete(deleteMembership: DeleteMembershipCommand): Promise<void> {
|
||||||
return await dataSource
|
return await dataSource
|
||||||
.createQueryBuilder()
|
.createQueryBuilder()
|
||||||
.delete()
|
.delete()
|
||||||
.from(membership)
|
.from(membership)
|
||||||
.where("id = :id", { id: deletMembership.id })
|
.where("id = :id", { id: deleteMembership.id })
|
||||||
.andWhere("memberId = :memberId", { memberId: deletMembership.memberId })
|
.andWhere("memberId = :memberId", { memberId: deleteMembership.memberId })
|
||||||
.execute()
|
.execute()
|
||||||
.then(() => {})
|
.then(() => {})
|
||||||
.catch((err) => {
|
.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,96 +0,0 @@
|
||||||
import { dataSource } from "../data-source";
|
|
||||||
import { communication } from "../entity/communication";
|
|
||||||
import { communicationType } from "../entity/communicationType";
|
|
||||||
import { user } from "../entity/user";
|
|
||||||
import InternalException from "../exceptions/internalException";
|
|
||||||
import {
|
|
||||||
CreateCommunicationCommand,
|
|
||||||
DeleteCommunicationCommand,
|
|
||||||
UpdateCommunicationCommand,
|
|
||||||
} from "./communicationCommand";
|
|
||||||
|
|
||||||
export default abstract class CommunicationCommandHandler {
|
|
||||||
/**
|
|
||||||
* @description create communication
|
|
||||||
* @param CreateCommunicationCommand
|
|
||||||
* @returns {Promise<number>}
|
|
||||||
*/
|
|
||||||
static async create(createCommunication: CreateCommunicationCommand): Promise<number> {
|
|
||||||
return await dataSource
|
|
||||||
.createQueryBuilder()
|
|
||||||
.insert()
|
|
||||||
.into(communication)
|
|
||||||
.values({
|
|
||||||
preferred: createCommunication.preferred,
|
|
||||||
mobile: createCommunication.mobile,
|
|
||||||
email: createCommunication.email,
|
|
||||||
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(),
|
|
||||||
})
|
|
||||||
.execute()
|
|
||||||
.then((result) => {
|
|
||||||
return result.identifiers[0].id;
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
throw new InternalException("Failed creating communication", err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description update communication
|
|
||||||
* @param UpdateCommunicationCommand
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
static async update(updateCommunication: UpdateCommunicationCommand): Promise<void> {
|
|
||||||
return await dataSource
|
|
||||||
.createQueryBuilder()
|
|
||||||
.update(communication)
|
|
||||||
.set({
|
|
||||||
preferred: updateCommunication.preferred,
|
|
||||||
mobile: updateCommunication.mobile,
|
|
||||||
email: updateCommunication.email,
|
|
||||||
city: updateCommunication.city,
|
|
||||||
street: updateCommunication.street,
|
|
||||||
streetNumber: updateCommunication.streetNumber,
|
|
||||||
streetNumberAddition: updateCommunication.streetNumberAddition,
|
|
||||||
})
|
|
||||||
.where("id = :id", { id: updateCommunication.id })
|
|
||||||
.andWhere("memberId = :memberId", { memberId: updateCommunication.memberId })
|
|
||||||
.execute()
|
|
||||||
.then(() => {})
|
|
||||||
.catch((err) => {
|
|
||||||
throw new InternalException("Failed updating communication", err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description delete communication
|
|
||||||
* @param DeleteCommunicationCommand
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
static async delete(deletCommunication: DeleteCommunicationCommand): Promise<void> {
|
|
||||||
return await dataSource
|
|
||||||
.createQueryBuilder()
|
|
||||||
.delete()
|
|
||||||
.from(communication)
|
|
||||||
.where("id = :id", { id: deletCommunication.id })
|
|
||||||
.andWhere("memberId = :memberId", { memberId: deletCommunication.memberId })
|
|
||||||
.execute()
|
|
||||||
.then(() => {})
|
|
||||||
.catch((err) => {
|
|
||||||
throw new InternalException("Failed deleting communication", err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,5 +1,6 @@
|
||||||
export interface CreateRefreshCommand {
|
export interface CreateRefreshCommand {
|
||||||
userId: number;
|
userId: number;
|
||||||
|
isFromPwa?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DeleteRefreshCommand {
|
export interface DeleteRefreshCommand {
|
||||||
|
|
|
@ -1,25 +1,19 @@
|
||||||
import { dataSource } from "../data-source";
|
import { dataSource } from "../data-source";
|
||||||
import { refresh } from "../entity/refresh";
|
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 InternalException from "../exceptions/internalException";
|
||||||
import { JWTHelper } from "../helpers/jwtHelper";
|
|
||||||
import { StringHelper } from "../helpers/stringHelper";
|
import { StringHelper } from "../helpers/stringHelper";
|
||||||
import UserService from "../service/userService";
|
import UserService from "../service/user/userService";
|
||||||
import { JWTRefresh } from "../type/jwtTypes";
|
|
||||||
import { CreateRefreshCommand, DeleteRefreshCommand } from "./refreshCommand";
|
import { CreateRefreshCommand, DeleteRefreshCommand } from "./refreshCommand";
|
||||||
import ms from "ms";
|
import ms from "ms";
|
||||||
|
|
||||||
export default abstract class RefreshCommandHandler {
|
export default abstract class RefreshCommandHandler {
|
||||||
/**
|
/**
|
||||||
* @description create and save refreshToken to user
|
* @description create and save refreshToken to user
|
||||||
* @param CreateRefreshCommand
|
* @param {CreateRefreshCommand} createRefresh
|
||||||
* @returns {Promise<string>}
|
* @returns {Promise<string>}
|
||||||
*/
|
*/
|
||||||
static async create(createRefresh: CreateRefreshCommand): 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);
|
const refreshToken = StringHelper.random(32);
|
||||||
|
|
||||||
return await dataSource
|
return await dataSource
|
||||||
|
@ -29,7 +23,9 @@ export default abstract class RefreshCommandHandler {
|
||||||
.values({
|
.values({
|
||||||
token: refreshToken,
|
token: refreshToken,
|
||||||
user: await UserService.getById(createRefresh.userId),
|
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()
|
.execute()
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
|
@ -42,7 +38,7 @@ export default abstract class RefreshCommandHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description delete refresh by user and token
|
* @description delete refresh by user and token
|
||||||
* @param DeleteRefreshCommand
|
* @param {DeleteRefreshCommand} deleteRefresh
|
||||||
* @returns {Promise<any>}
|
* @returns {Promise<any>}
|
||||||
*/
|
*/
|
||||||
static async deleteByToken(deleteRefresh: DeleteRefreshCommand): 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 { dataSource } from "../../../data-source";
|
||||||
import { award } from "../entity/award";
|
import { award } from "../../../entity/settings/award";
|
||||||
import InternalException from "../exceptions/internalException";
|
import InternalException from "../../../exceptions/internalException";
|
||||||
import { CreateAwardCommand, DeleteAwardCommand, UpdateAwardCommand } from "./awardCommand";
|
import { CreateAwardCommand, DeleteAwardCommand, UpdateAwardCommand } from "./awardCommand";
|
||||||
|
|
||||||
export default abstract class AwardCommandHandler {
|
export default abstract class AwardCommandHandler {
|
||||||
/**
|
/**
|
||||||
* @description create award
|
* @description create award
|
||||||
* @param CreateAwardCommand
|
* @param {CreateAwardCommand} createAward
|
||||||
* @returns {Promise<number>}
|
* @returns {Promise<number>}
|
||||||
*/
|
*/
|
||||||
static async create(createAward: CreateAwardCommand): Promise<number> {
|
static async create(createAward: CreateAwardCommand): Promise<number> {
|
||||||
|
@ -28,7 +28,7 @@ export default abstract class AwardCommandHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description update award
|
* @description update award
|
||||||
* @param UpdateAwardCommand
|
* @param {UpdateAwardCommand} updateAward
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async update(updateAward: UpdateAwardCommand): Promise<void> {
|
static async update(updateAward: UpdateAwardCommand): Promise<void> {
|
||||||
|
@ -48,19 +48,22 @@ export default abstract class AwardCommandHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description delete award
|
* @description delete award
|
||||||
* @param DeleteAwardCommand
|
* @param {DeleteAwardCommand} deleteAward
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async delete(deletAward: DeleteAwardCommand): Promise<void> {
|
static async delete(deleteAward: DeleteAwardCommand): Promise<void> {
|
||||||
return await dataSource
|
return await dataSource
|
||||||
.createQueryBuilder()
|
.createQueryBuilder()
|
||||||
.delete()
|
.delete()
|
||||||
.from(award)
|
.from(award)
|
||||||
.where("id = :id", { id: deletAward.id })
|
.where("id = :id", { id: deleteAward.id })
|
||||||
.execute()
|
.execute()
|
||||||
.then(() => {})
|
.then(() => {})
|
||||||
.catch((err) => {
|
.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 {
|
export interface CreateCommunicationTypeCommand {
|
||||||
type: string;
|
type: string;
|
|
@ -1,6 +1,6 @@
|
||||||
import { dataSource } from "../data-source";
|
import { dataSource } from "../../../data-source";
|
||||||
import { communicationType } from "../entity/communicationType";
|
import { communicationType } from "../../../entity/settings/communicationType";
|
||||||
import InternalException from "../exceptions/internalException";
|
import InternalException from "../../../exceptions/internalException";
|
||||||
import {
|
import {
|
||||||
CreateCommunicationTypeCommand,
|
CreateCommunicationTypeCommand,
|
||||||
DeleteCommunicationTypeCommand,
|
DeleteCommunicationTypeCommand,
|
||||||
|
@ -10,7 +10,7 @@ import {
|
||||||
export default abstract class CommunicationTypeCommandHandler {
|
export default abstract class CommunicationTypeCommandHandler {
|
||||||
/**
|
/**
|
||||||
* @description create communicationType
|
* @description create communicationType
|
||||||
* @param CreateCommunicationTypeCommand
|
* @param {CreateCommunicationTypeCommand} createCommunicationType
|
||||||
* @returns {Promise<number>}
|
* @returns {Promise<number>}
|
||||||
*/
|
*/
|
||||||
static async create(createCommunicationType: CreateCommunicationTypeCommand): Promise<number> {
|
static async create(createCommunicationType: CreateCommunicationTypeCommand): Promise<number> {
|
||||||
|
@ -33,7 +33,7 @@ export default abstract class CommunicationTypeCommandHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description update communicationType
|
* @description update communicationType
|
||||||
* @param UpdateCommunicationTypeCommand
|
* @param {UpdateCommunicationTypeCommand} updateCommunicationType
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async update(updateCommunicationType: UpdateCommunicationTypeCommand): Promise<void> {
|
static async update(updateCommunicationType: UpdateCommunicationTypeCommand): Promise<void> {
|
||||||
|
@ -54,19 +54,24 @@ export default abstract class CommunicationTypeCommandHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description delete communicationType
|
* @description delete communicationType
|
||||||
* @param DeleteCommunicationTypeCommand
|
* @param {DeleteCommunicationTypeCommand} deleteCommunicationType
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async delete(deletCommunicationType: DeleteCommunicationTypeCommand): Promise<void> {
|
static async delete(deleteCommunicationType: DeleteCommunicationTypeCommand): Promise<void> {
|
||||||
return await dataSource
|
return await dataSource
|
||||||
.createQueryBuilder()
|
.createQueryBuilder()
|
||||||
.delete()
|
.delete()
|
||||||
.from(communicationType)
|
.from(communicationType)
|
||||||
.where("id = :id", { id: deletCommunicationType.id })
|
.where("id = :id", { id: deleteCommunicationType.id })
|
||||||
.execute()
|
.execute()
|
||||||
.then(() => {})
|
.then(() => {})
|
||||||
.catch((err) => {
|
.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 { dataSource } from "../../../data-source";
|
||||||
import { executivePosition } from "../entity/executivePosition";
|
import { executivePosition } from "../../../entity/settings/executivePosition";
|
||||||
import InternalException from "../exceptions/internalException";
|
import InternalException from "../../../exceptions/internalException";
|
||||||
import {
|
import {
|
||||||
CreateExecutivePositionCommand,
|
CreateExecutivePositionCommand,
|
||||||
DeleteExecutivePositionCommand,
|
DeleteExecutivePositionCommand,
|
||||||
|
@ -10,7 +10,7 @@ import {
|
||||||
export default abstract class ExecutivePositionCommandHandler {
|
export default abstract class ExecutivePositionCommandHandler {
|
||||||
/**
|
/**
|
||||||
* @description create executivePosition
|
* @description create executivePosition
|
||||||
* @param CreateExecutivePositionCommand
|
* @param {CreateExecutivePositionCommand} createExecutivePosition
|
||||||
* @returns {Promise<number>}
|
* @returns {Promise<number>}
|
||||||
*/
|
*/
|
||||||
static async create(createExecutivePosition: CreateExecutivePositionCommand): Promise<number> {
|
static async create(createExecutivePosition: CreateExecutivePositionCommand): Promise<number> {
|
||||||
|
@ -32,7 +32,7 @@ export default abstract class ExecutivePositionCommandHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description update executivePosition
|
* @description update executivePosition
|
||||||
* @param UpdateExecutivePositionCommand
|
* @param {UpdateExecutivePositionCommand} updateExecutivePosition
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async update(updateExecutivePosition: UpdateExecutivePositionCommand): Promise<void> {
|
static async update(updateExecutivePosition: UpdateExecutivePositionCommand): Promise<void> {
|
||||||
|
@ -52,19 +52,24 @@ export default abstract class ExecutivePositionCommandHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description delete executivePosition
|
* @description delete executivePosition
|
||||||
* @param DeleteExecutivePositionCommand
|
* @param {DeleteExecutivePositionCommand} deleteExecutivePosition
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async delete(deletExecutivePosition: DeleteExecutivePositionCommand): Promise<void> {
|
static async delete(deleteExecutivePosition: DeleteExecutivePositionCommand): Promise<void> {
|
||||||
return await dataSource
|
return await dataSource
|
||||||
.createQueryBuilder()
|
.createQueryBuilder()
|
||||||
.delete()
|
.delete()
|
||||||
.from(executivePosition)
|
.from(executivePosition)
|
||||||
.where("id = :id", { id: deletExecutivePosition.id })
|
.where("id = :id", { id: deleteExecutivePosition.id })
|
||||||
.execute()
|
.execute()
|
||||||
.then(() => {})
|
.then(() => {})
|
||||||
.catch((err) => {
|
.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 { dataSource } from "../../../data-source";
|
||||||
import { membershipStatus } from "../entity/membershipStatus";
|
import { membershipStatus } from "../../../entity/settings/membershipStatus";
|
||||||
import InternalException from "../exceptions/internalException";
|
import InternalException from "../../../exceptions/internalException";
|
||||||
import {
|
import {
|
||||||
CreateMembershipStatusCommand,
|
CreateMembershipStatusCommand,
|
||||||
DeleteMembershipStatusCommand,
|
DeleteMembershipStatusCommand,
|
||||||
|
@ -10,7 +10,7 @@ import {
|
||||||
export default abstract class MembershipStatusCommandHandler {
|
export default abstract class MembershipStatusCommandHandler {
|
||||||
/**
|
/**
|
||||||
* @description create membershipStatus
|
* @description create membershipStatus
|
||||||
* @param CreateMembershipStatusCommand
|
* @param {CreateMembershipStatusCommand} createMembershipStatus
|
||||||
* @returns {Promise<number>}
|
* @returns {Promise<number>}
|
||||||
*/
|
*/
|
||||||
static async create(createMembershipStatus: CreateMembershipStatusCommand): Promise<number> {
|
static async create(createMembershipStatus: CreateMembershipStatusCommand): Promise<number> {
|
||||||
|
@ -32,7 +32,7 @@ export default abstract class MembershipStatusCommandHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description update membershipStatus
|
* @description update membershipStatus
|
||||||
* @param UpdateMembershipStatusCommand
|
* @param {UpdateMembershipStatusCommand} updateMembershipStatus
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async update(updateMembershipStatus: UpdateMembershipStatusCommand): Promise<void> {
|
static async update(updateMembershipStatus: UpdateMembershipStatusCommand): Promise<void> {
|
||||||
|
@ -52,19 +52,24 @@ export default abstract class MembershipStatusCommandHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description delete membershipStatus
|
* @description delete membershipStatus
|
||||||
* @param DeleteMembershipStatusCommand
|
* @param {DeleteMembershipStatusCommand} deleteMembershipStatus
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async delete(deletMembershipStatus: DeleteMembershipStatusCommand): Promise<void> {
|
static async delete(deleteMembershipStatus: DeleteMembershipStatusCommand): Promise<void> {
|
||||||
return await dataSource
|
return await dataSource
|
||||||
.createQueryBuilder()
|
.createQueryBuilder()
|
||||||
.delete()
|
.delete()
|
||||||
.from(membershipStatus)
|
.from(membershipStatus)
|
||||||
.where("id = :id", { id: deletMembershipStatus.id })
|
.where("id = :id", { id: deleteMembershipStatus.id })
|
||||||
.execute()
|
.execute()
|
||||||
.then(() => {})
|
.then(() => {})
|
||||||
.catch((err) => {
|
.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 { dataSource } from "../../../data-source";
|
||||||
import { qualification } from "../entity/qualification";
|
import { qualification } from "../../../entity/settings/qualification";
|
||||||
import InternalException from "../exceptions/internalException";
|
import InternalException from "../../../exceptions/internalException";
|
||||||
import {
|
import {
|
||||||
CreateQualificationCommand,
|
CreateQualificationCommand,
|
||||||
DeleteQualificationCommand,
|
DeleteQualificationCommand,
|
||||||
|
@ -10,7 +10,7 @@ import {
|
||||||
export default abstract class QualificationCommandHandler {
|
export default abstract class QualificationCommandHandler {
|
||||||
/**
|
/**
|
||||||
* @description create qualification
|
* @description create qualification
|
||||||
* @param CreateQualificationCommand
|
* @param {CreateQualificationCommand} createQualification
|
||||||
* @returns {Promise<number>}
|
* @returns {Promise<number>}
|
||||||
*/
|
*/
|
||||||
static async create(createQualification: CreateQualificationCommand): Promise<number> {
|
static async create(createQualification: CreateQualificationCommand): Promise<number> {
|
||||||
|
@ -33,7 +33,7 @@ export default abstract class QualificationCommandHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description update qualification
|
* @description update qualification
|
||||||
* @param UpdateQualificationCommand
|
* @param {UpdateQualificationCommand} updateQualification
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async update(updateQualification: UpdateQualificationCommand): Promise<void> {
|
static async update(updateQualification: UpdateQualificationCommand): Promise<void> {
|
||||||
|
@ -54,19 +54,22 @@ export default abstract class QualificationCommandHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description delete qualification
|
* @description delete qualification
|
||||||
* @param DeleteQualificationCommand
|
* @param {DeleteQualificationCommand} deleteQualification
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async delete(deletQualification: DeleteQualificationCommand): Promise<void> {
|
static async delete(deleteQualification: DeleteQualificationCommand): Promise<void> {
|
||||||
return await dataSource
|
return await dataSource
|
||||||
.createQueryBuilder()
|
.createQueryBuilder()
|
||||||
.delete()
|
.delete()
|
||||||
.from(qualification)
|
.from(qualification)
|
||||||
.where("id = :id", { id: deletQualification.id })
|
.where("id = :id", { id: deleteQualification.id })
|
||||||
.execute()
|
.execute()
|
||||||
.then(() => {})
|
.then(() => {})
|
||||||
.catch((err) => {
|
.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
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
12
src/command/settings/salutation/salutationCommand.ts
Normal file
12
src/command/settings/salutation/salutationCommand.ts
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
export interface CreateSalutationCommand {
|
||||||
|
salutation: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface UpdateSalutationCommand {
|
||||||
|
id: number;
|
||||||
|
salutation: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface DeleteSalutationCommand {
|
||||||
|
id: number;
|
||||||
|
}
|
69
src/command/settings/salutation/salutationCommandHandler.ts
Normal file
69
src/command/settings/salutation/salutationCommandHandler.ts
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
import { dataSource } from "../../../data-source";
|
||||||
|
import { salutation } from "../../../entity/settings/salutation";
|
||||||
|
import InternalException from "../../../exceptions/internalException";
|
||||||
|
import { CreateSalutationCommand, DeleteSalutationCommand, UpdateSalutationCommand } from "./salutationCommand";
|
||||||
|
|
||||||
|
export default abstract class SalutationCommandHandler {
|
||||||
|
/**
|
||||||
|
* @description create salutation
|
||||||
|
* @param {CreateSalutationCommand} createSalutation
|
||||||
|
* @returns {Promise<number>}
|
||||||
|
*/
|
||||||
|
static async create(createSalutation: CreateSalutationCommand): Promise<number> {
|
||||||
|
return await dataSource
|
||||||
|
.createQueryBuilder()
|
||||||
|
.insert()
|
||||||
|
.into(salutation)
|
||||||
|
.values({
|
||||||
|
salutation: createSalutation.salutation,
|
||||||
|
})
|
||||||
|
.execute()
|
||||||
|
.then((result) => {
|
||||||
|
return result.identifiers[0].id;
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
throw new InternalException("Failed creating salutation", err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description update salutation
|
||||||
|
* @param {UpdateSalutationCommand} updateSalutation
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
static async update(updateSalutation: UpdateSalutationCommand): Promise<void> {
|
||||||
|
return await dataSource
|
||||||
|
.createQueryBuilder()
|
||||||
|
.update(salutation)
|
||||||
|
.set({
|
||||||
|
salutation: updateSalutation.salutation,
|
||||||
|
})
|
||||||
|
.where("id = :id", { id: updateSalutation.id })
|
||||||
|
.execute()
|
||||||
|
.then(() => {})
|
||||||
|
.catch((err) => {
|
||||||
|
throw new InternalException("Failed updating salutation", err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description delete salutation
|
||||||
|
* @param {DeleteSalutationCommand} deleteSalutation
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
static async delete(deleteSalutation: DeleteSalutationCommand): Promise<void> {
|
||||||
|
return await dataSource
|
||||||
|
.createQueryBuilder()
|
||||||
|
.delete()
|
||||||
|
.from(salutation)
|
||||||
|
.where("id = :id", { id: deleteSalutation.id })
|
||||||
|
.execute()
|
||||||
|
.then(() => {})
|
||||||
|
.catch((err) => {
|
||||||
|
throw new InternalException(
|
||||||
|
`Failed deleting salutation ${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 { dataSource } from "../../../data-source";
|
||||||
import { role } from "../entity/role";
|
import { role } from "../../../entity/user/role";
|
||||||
import InternalException from "../exceptions/internalException";
|
import InternalException from "../../../exceptions/internalException";
|
||||||
import { CreateRoleCommand, DeleteRoleCommand, UpdateRoleCommand } from "./roleCommand";
|
import { CreateRoleCommand, DeleteRoleCommand, UpdateRoleCommand } from "./roleCommand";
|
||||||
|
|
||||||
export default abstract class RoleCommandHandler {
|
export default abstract class RoleCommandHandler {
|
||||||
/**
|
/**
|
||||||
* @description create role
|
* @description create role
|
||||||
* @param CreateRoleCommand
|
* @param {CreateRoleCommand} createRole
|
||||||
* @returns {Promise<number>}
|
* @returns {Promise<number>}
|
||||||
*/
|
*/
|
||||||
static async create(createRole: CreateRoleCommand): Promise<number> {
|
static async create(createRole: CreateRoleCommand): Promise<number> {
|
||||||
|
@ -28,7 +28,7 @@ export default abstract class RoleCommandHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description update role
|
* @description update role
|
||||||
* @param UpdateRoleCommand
|
* @param {UpdateRoleCommand} updateRole
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async update(updateRole: UpdateRoleCommand): Promise<void> {
|
static async update(updateRole: UpdateRoleCommand): Promise<void> {
|
||||||
|
@ -48,7 +48,7 @@ export default abstract class RoleCommandHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description delete role
|
* @description delete role
|
||||||
* @param DeleteRoleCommand
|
* @param {DeleteRoleCommand} deleteRole
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async delete(deleteRole: DeleteRoleCommand): 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 {
|
export interface CreateRolePermissionCommand {
|
||||||
permission: PermissionString;
|
permission: PermissionString;
|
|
@ -1,22 +1,21 @@
|
||||||
import { DeleteResult, EntityManager, InsertResult } from "typeorm";
|
import { DeleteResult, EntityManager, InsertResult } from "typeorm";
|
||||||
import { dataSource } from "../data-source";
|
import { dataSource } from "../../../data-source";
|
||||||
import { rolePermission } from "../entity/role_permission";
|
import { rolePermission } from "../../../entity/user/role_permission";
|
||||||
import InternalException from "../exceptions/internalException";
|
import InternalException from "../../../exceptions/internalException";
|
||||||
import RoleService from "../service/roleService";
|
import RoleService from "../../../service/user/roleService";
|
||||||
import {
|
import {
|
||||||
CreateRolePermissionCommand,
|
CreateRolePermissionCommand,
|
||||||
DeleteRolePermissionCommand,
|
DeleteRolePermissionCommand,
|
||||||
UpdateRolePermissionsCommand,
|
UpdateRolePermissionsCommand,
|
||||||
} from "./rolePermissionCommand";
|
} from "./rolePermissionCommand";
|
||||||
import PermissionHelper from "../helpers/permissionHelper";
|
import PermissionHelper from "../../../helpers/permissionHelper";
|
||||||
import RolePermissionService from "../service/rolePermissionService";
|
import RolePermissionService from "../../../service/user/rolePermissionService";
|
||||||
import { role } from "../entity/role";
|
import { PermissionString } from "../../../type/permissionTypes";
|
||||||
import { PermissionString } from "../type/permissionTypes";
|
|
||||||
|
|
||||||
export default abstract class RolePermissionCommandHandler {
|
export default abstract class RolePermissionCommandHandler {
|
||||||
/**
|
/**
|
||||||
* @description update role permissions
|
* @description update role permissions
|
||||||
* @param UpdateRolePermissionsCommand
|
* @param {UpdateRolePermissionsCommand} updateRolePermissions
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async updatePermissions(updateRolePermissions: UpdateRolePermissionsCommand): Promise<void> {
|
static async updatePermissions(updateRolePermissions: UpdateRolePermissionsCommand): Promise<void> {
|
||||||
|
@ -75,7 +74,7 @@ export default abstract class RolePermissionCommandHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description grant permission to user
|
* @description grant permission to user
|
||||||
* @param CreateRolePermissionCommand
|
* @param {CreateRolePermissionCommand} createPermission
|
||||||
* @returns {Promise<number>}
|
* @returns {Promise<number>}
|
||||||
*/
|
*/
|
||||||
static async create(createPermission: CreateRolePermissionCommand): Promise<number> {
|
static async create(createPermission: CreateRolePermissionCommand): Promise<number> {
|
||||||
|
@ -98,7 +97,7 @@ export default abstract class RolePermissionCommandHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description remove permission from role
|
* @description remove permission from role
|
||||||
* @param DeleteRolePermissionCommand
|
* @param {DeleteRolePermissionCommand} deletePermission
|
||||||
* @returns {Promise<any>}
|
* @returns {Promise<any>}
|
||||||
*/
|
*/
|
||||||
static async delete(deletePermission: DeleteRolePermissionCommand): Promise<any> {
|
static async delete(deletePermission: DeleteRolePermissionCommand): Promise<any> {
|
||||||
|
@ -109,7 +108,7 @@ export default abstract class RolePermissionCommandHandler {
|
||||||
.where("roleId = :id", { id: deletePermission.roleId })
|
.where("roleId = :id", { id: deletePermission.roleId })
|
||||||
.andWhere("permission = :permission", { permission: deletePermission.permission })
|
.andWhere("permission = :permission", { permission: deletePermission.permission })
|
||||||
.execute()
|
.execute()
|
||||||
.then((res) => {})
|
.then(() => {})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
throw new InternalException("failed role permission removal", err);
|
throw new InternalException("failed role permission removal", err);
|
||||||
});
|
});
|
|
@ -1,7 +1,7 @@
|
||||||
import { dataSource } from "../data-source";
|
import { dataSource } from "../../../data-source";
|
||||||
import { invite } from "../entity/invite";
|
import { invite } from "../../../entity/user/invite";
|
||||||
import InternalException from "../exceptions/internalException";
|
import InternalException from "../../../exceptions/internalException";
|
||||||
import { StringHelper } from "../helpers/stringHelper";
|
import { StringHelper } from "../../../helpers/stringHelper";
|
||||||
import { CreateInviteCommand, DeleteInviteCommand } from "./inviteCommand";
|
import { CreateInviteCommand, DeleteInviteCommand } from "./inviteCommand";
|
||||||
|
|
||||||
export default abstract class InviteCommandHandler {
|
export default abstract class InviteCommandHandler {
|
||||||
|
@ -37,7 +37,7 @@ export default abstract class InviteCommandHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description delete invite by mail and token
|
* @description delete invite by mail and token
|
||||||
* @param DeleteRefreshCommand
|
* @param DeleteInviteCommand
|
||||||
* @returns {Promise<any>}
|
* @returns {Promise<any>}
|
||||||
*/
|
*/
|
||||||
static async deleteByTokenAndMail(deleteInvite: DeleteInviteCommand): 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);
|
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;
|
firstname: string;
|
||||||
lastname: string;
|
lastname: string;
|
||||||
secret: string;
|
secret: string;
|
||||||
|
isOwner: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UpdateUserCommand {
|
export interface UpdateUserCommand {
|
||||||
|
@ -14,6 +15,16 @@ export interface UpdateUserCommand {
|
||||||
lastname: string;
|
lastname: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface UpdateUserSecretCommand {
|
||||||
|
id: number;
|
||||||
|
secret: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface TransferUserOwnerCommand {
|
||||||
|
fromId: number;
|
||||||
|
toId: number;
|
||||||
|
}
|
||||||
|
|
||||||
export interface UpdateUserRolesCommand {
|
export interface UpdateUserRolesCommand {
|
||||||
id: number;
|
id: number;
|
||||||
roleIds: Array<number>;
|
roleIds: Array<number>;
|
|
@ -1,14 +1,21 @@
|
||||||
import { EntityManager } from "typeorm";
|
import { EntityManager } from "typeorm";
|
||||||
import { dataSource } from "../data-source";
|
import { dataSource } from "../../../data-source";
|
||||||
import { user } from "../entity/user";
|
import { user } from "../../../entity/user/user";
|
||||||
import InternalException from "../exceptions/internalException";
|
import InternalException from "../../../exceptions/internalException";
|
||||||
import { CreateUserCommand, DeleteUserCommand, UpdateUserCommand, UpdateUserRolesCommand } from "./userCommand";
|
import {
|
||||||
import UserService from "../service/userService";
|
CreateUserCommand,
|
||||||
|
DeleteUserCommand,
|
||||||
|
TransferUserOwnerCommand,
|
||||||
|
UpdateUserCommand,
|
||||||
|
UpdateUserRolesCommand,
|
||||||
|
UpdateUserSecretCommand,
|
||||||
|
} from "./userCommand";
|
||||||
|
import UserService from "../../../service/user/userService";
|
||||||
|
|
||||||
export default abstract class UserCommandHandler {
|
export default abstract class UserCommandHandler {
|
||||||
/**
|
/**
|
||||||
* @description create user
|
* @description create user
|
||||||
* @param CreateUserCommand
|
* @param {CreateUserCommand} createUser
|
||||||
* @returns {Promise<number>}
|
* @returns {Promise<number>}
|
||||||
*/
|
*/
|
||||||
static async create(createUser: CreateUserCommand): Promise<number> {
|
static async create(createUser: CreateUserCommand): Promise<number> {
|
||||||
|
@ -22,6 +29,7 @@ export default abstract class UserCommandHandler {
|
||||||
firstname: createUser.firstname,
|
firstname: createUser.firstname,
|
||||||
lastname: createUser.lastname,
|
lastname: createUser.lastname,
|
||||||
secret: createUser.secret,
|
secret: createUser.secret,
|
||||||
|
isOwner: createUser.isOwner,
|
||||||
})
|
})
|
||||||
.execute()
|
.execute()
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
|
@ -34,7 +42,7 @@ export default abstract class UserCommandHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description update user
|
* @description update user
|
||||||
* @param UpdateUserCommand
|
* @param {UpdateUserCommand} updateUser
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async update(updateUser: UpdateUserCommand): 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
|
* @description update user roles
|
||||||
* @param UpdateUserRolesCommand
|
* @param {UpdateUserRolesCommand} updateUserRoles
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async updateRoles(updateUserRoles: UpdateUserRolesCommand): 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);
|
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
|
* @description delete user
|
||||||
* @param DeleteUserCommand
|
* @param DeleteUserCommand
|
|
@ -1,4 +1,4 @@
|
||||||
import { PermissionString } from "../type/permissionTypes";
|
import { PermissionString } from "../../../type/permissionTypes";
|
||||||
|
|
||||||
export interface CreateUserPermissionCommand {
|
export interface CreateUserPermissionCommand {
|
||||||
permission: PermissionString;
|
permission: PermissionString;
|
|
@ -1,21 +1,21 @@
|
||||||
import { DeleteResult, EntityManager, InsertResult } from "typeorm";
|
import { DeleteResult, EntityManager, InsertResult } from "typeorm";
|
||||||
import { dataSource } from "../data-source";
|
import { dataSource } from "../../../data-source";
|
||||||
import { user } from "../entity/user";
|
import { user } from "../../../entity/user/user";
|
||||||
import { userPermission } from "../entity/user_permission";
|
import { userPermission } from "../../../entity/user/user_permission";
|
||||||
import InternalException from "../exceptions/internalException";
|
import InternalException from "../../../exceptions/internalException";
|
||||||
import {
|
import {
|
||||||
CreateUserPermissionCommand,
|
CreateUserPermissionCommand,
|
||||||
DeleteUserPermissionCommand,
|
DeleteUserPermissionCommand,
|
||||||
UpdateUserPermissionsCommand,
|
UpdateUserPermissionsCommand,
|
||||||
} from "./userPermissionCommand";
|
} from "./userPermissionCommand";
|
||||||
import UserPermissionService from "../service/userPermissionService";
|
import UserPermissionService from "../../../service/user/userPermissionService";
|
||||||
import PermissionHelper from "../helpers/permissionHelper";
|
import PermissionHelper from "../../../helpers/permissionHelper";
|
||||||
import { PermissionString } from "../type/permissionTypes";
|
import { PermissionString } from "../../../type/permissionTypes";
|
||||||
|
|
||||||
export default abstract class UserPermissionCommandHandler {
|
export default abstract class UserPermissionCommandHandler {
|
||||||
/**
|
/**
|
||||||
* @description update user permissions
|
* @description update user permissions
|
||||||
* @param UpdateUserPermissionsCommand
|
* @param {UpdateUserPermissionsCommand} updateUserPermissions
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async updatePermissions(updateUserPermissions: UpdateUserPermissionsCommand): Promise<void> {
|
static async updatePermissions(updateUserPermissions: UpdateUserPermissionsCommand): Promise<void> {
|
||||||
|
@ -75,7 +75,7 @@ export default abstract class UserPermissionCommandHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description grant permission to user
|
* @description grant permission to user
|
||||||
* @param CreateUserPermissionCommand
|
* @param {CreateUserPermissionCommand} createPermission
|
||||||
* @returns {Promise<number>}
|
* @returns {Promise<number>}
|
||||||
*/
|
*/
|
||||||
static async create(createPermission: CreateUserPermissionCommand): Promise<number> {
|
static async create(createPermission: CreateUserPermissionCommand): Promise<number> {
|
||||||
|
@ -98,7 +98,7 @@ export default abstract class UserPermissionCommandHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description remove permission to user
|
* @description remove permission to user
|
||||||
* @param DeleteUserPermissionCommand
|
* @param {DeleteUserPermissionCommand} deletePermission
|
||||||
* @returns {Promise<any>}
|
* @returns {Promise<any>}
|
||||||
*/
|
*/
|
||||||
static async delete(deletePermission: DeleteUserPermissionCommand): Promise<any> {
|
static async delete(deletePermission: DeleteUserPermissionCommand): Promise<any> {
|
19
src/command/user/webapi/webapiCommand.ts
Normal file
19
src/command/user/webapi/webapiCommand.ts
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
export interface CreateWebapiCommand {
|
||||||
|
title: string;
|
||||||
|
token: string;
|
||||||
|
expiry?: Date;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface UpdateWebapiCommand {
|
||||||
|
id: number;
|
||||||
|
title: string;
|
||||||
|
expiry?: Date;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface UpdateLastUsageWebapiCommand {
|
||||||
|
id: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface DeleteWebapiCommand {
|
||||||
|
id: number;
|
||||||
|
}
|
100
src/command/user/webapi/webapiCommandHandler.ts
Normal file
100
src/command/user/webapi/webapiCommandHandler.ts
Normal file
|
@ -0,0 +1,100 @@
|
||||||
|
import { dataSource } from "../../../data-source";
|
||||||
|
import { webapi } from "../../../entity/user/webapi";
|
||||||
|
import InternalException from "../../../exceptions/internalException";
|
||||||
|
import {
|
||||||
|
CreateWebapiCommand,
|
||||||
|
DeleteWebapiCommand,
|
||||||
|
UpdateLastUsageWebapiCommand,
|
||||||
|
UpdateWebapiCommand,
|
||||||
|
} from "./webapiCommand";
|
||||||
|
|
||||||
|
export default abstract class WebapiCommandHandler {
|
||||||
|
/**
|
||||||
|
* @description create api
|
||||||
|
* @param {CreateWebapiCommand} createWebapi
|
||||||
|
* @returns {Promise<number>}
|
||||||
|
*/
|
||||||
|
static async create(createWebapi: CreateWebapiCommand): Promise<number> {
|
||||||
|
return await dataSource
|
||||||
|
.createQueryBuilder()
|
||||||
|
.insert()
|
||||||
|
.into(webapi)
|
||||||
|
.values({
|
||||||
|
token: createWebapi.token,
|
||||||
|
title: createWebapi.title,
|
||||||
|
expiry: createWebapi.expiry,
|
||||||
|
})
|
||||||
|
.execute()
|
||||||
|
.then((result) => {
|
||||||
|
return result.identifiers[0].token;
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
throw new InternalException(
|
||||||
|
`Failed creating api${err.code.includes("ER_DUP_ENTRY") ? " due to duplicate entry for column" : ""}`,
|
||||||
|
err
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description update api
|
||||||
|
* @param {UpdateWebapiCommand} updateWebapi
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
static async update(updateWebapi: UpdateWebapiCommand): Promise<void> {
|
||||||
|
return await dataSource
|
||||||
|
.createQueryBuilder()
|
||||||
|
.update(webapi)
|
||||||
|
.set({
|
||||||
|
title: updateWebapi.title,
|
||||||
|
expiry: updateWebapi.expiry,
|
||||||
|
})
|
||||||
|
.where("id = :id", { id: updateWebapi.id })
|
||||||
|
.execute()
|
||||||
|
.then(() => {})
|
||||||
|
.catch((err) => {
|
||||||
|
throw new InternalException(
|
||||||
|
`Failed updating api${err.code.includes("ER_DUP_ENTRY") ? " due to duplicate entry for column" : ""}`,
|
||||||
|
err
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description update api usage
|
||||||
|
* @param {UpdateLastUsageWebapiCommand} updateWebapi
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
static async updateUsage(updateWebapi: UpdateLastUsageWebapiCommand): Promise<void> {
|
||||||
|
return await dataSource
|
||||||
|
.createQueryBuilder()
|
||||||
|
.update(webapi)
|
||||||
|
.set({
|
||||||
|
lastUsage: new Date(),
|
||||||
|
})
|
||||||
|
.where("id = :id", { id: updateWebapi.id })
|
||||||
|
.execute()
|
||||||
|
.then(() => {})
|
||||||
|
.catch((err) => {
|
||||||
|
throw new InternalException(`Failed updating api last usage`, err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description delete api
|
||||||
|
* @param {DeleteWebapiCommand} deleteWebapi
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
static async delete(deleteWebapi: DeleteWebapiCommand): Promise<void> {
|
||||||
|
return await dataSource
|
||||||
|
.createQueryBuilder()
|
||||||
|
.delete()
|
||||||
|
.from(webapi)
|
||||||
|
.where("id = :id", { id: deleteWebapi.id })
|
||||||
|
.execute()
|
||||||
|
.then(() => {})
|
||||||
|
.catch((err) => {
|
||||||
|
throw new InternalException("Failed deleting api", err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
16
src/command/user/webapi/webapiPermissionCommand.ts
Normal file
16
src/command/user/webapi/webapiPermissionCommand.ts
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
import { PermissionString } from "../../../type/permissionTypes";
|
||||||
|
|
||||||
|
export interface CreateWebapiPermissionCommand {
|
||||||
|
permission: PermissionString;
|
||||||
|
webapiId: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface DeleteWebapiPermissionCommand {
|
||||||
|
permission: PermissionString;
|
||||||
|
webapiId: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface UpdateWebapiPermissionsCommand {
|
||||||
|
webapiId: number;
|
||||||
|
permissions: Array<PermissionString>;
|
||||||
|
}
|
119
src/command/user/webapi/webapiPermissionCommandHandler.ts
Normal file
119
src/command/user/webapi/webapiPermissionCommandHandler.ts
Normal file
|
@ -0,0 +1,119 @@
|
||||||
|
import { DeleteResult, EntityManager, InsertResult } from "typeorm";
|
||||||
|
import { dataSource } from "../../../data-source";
|
||||||
|
import { webapiPermission } from "../../../entity/user/webapi_permission";
|
||||||
|
import InternalException from "../../../exceptions/internalException";
|
||||||
|
import WebapiService from "../../../service/user/webapiService";
|
||||||
|
import {
|
||||||
|
CreateWebapiPermissionCommand,
|
||||||
|
DeleteWebapiPermissionCommand,
|
||||||
|
UpdateWebapiPermissionsCommand,
|
||||||
|
} from "./webapiPermissionCommand";
|
||||||
|
import PermissionHelper from "../../../helpers/permissionHelper";
|
||||||
|
import WebapiPermissionService from "../../../service/user/webapiPermissionService";
|
||||||
|
import { PermissionString } from "../../../type/permissionTypes";
|
||||||
|
|
||||||
|
export default abstract class WebapiPermissionCommandHandler {
|
||||||
|
/**
|
||||||
|
* @description update api permissions
|
||||||
|
* @param {UpdateWebapiPermissionsCommand} updateWebapiPermissions
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
static async updatePermissions(updateWebapiPermissions: UpdateWebapiPermissionsCommand): Promise<void> {
|
||||||
|
let currentPermissions = (await WebapiPermissionService.getByApi(updateWebapiPermissions.webapiId)).map(
|
||||||
|
(r) => r.permission
|
||||||
|
);
|
||||||
|
return await dataSource.manager
|
||||||
|
.transaction(async (manager) => {
|
||||||
|
let newPermissions = PermissionHelper.getWhatToAdd(currentPermissions, updateWebapiPermissions.permissions);
|
||||||
|
let removePermissions = PermissionHelper.getWhatToRemove(
|
||||||
|
currentPermissions,
|
||||||
|
updateWebapiPermissions.permissions
|
||||||
|
);
|
||||||
|
if (newPermissions.length != 0) {
|
||||||
|
await this.updatePermissionsAdd(manager, updateWebapiPermissions.webapiId, newPermissions);
|
||||||
|
}
|
||||||
|
if (removePermissions.length != 0) {
|
||||||
|
await this.updatePermissionsRemove(manager, updateWebapiPermissions.webapiId, removePermissions);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(() => {})
|
||||||
|
.catch((err) => {
|
||||||
|
throw new InternalException("Failed saving api permissions", err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static async updatePermissionsAdd(
|
||||||
|
manager: EntityManager,
|
||||||
|
webapiId: number,
|
||||||
|
permissions: Array<PermissionString>
|
||||||
|
): Promise<InsertResult> {
|
||||||
|
return await manager
|
||||||
|
.createQueryBuilder()
|
||||||
|
.insert()
|
||||||
|
.into(webapiPermission)
|
||||||
|
.values(
|
||||||
|
permissions.map((p) => ({
|
||||||
|
permission: p,
|
||||||
|
webapiId: webapiId,
|
||||||
|
}))
|
||||||
|
)
|
||||||
|
.orIgnore()
|
||||||
|
.execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static async updatePermissionsRemove(
|
||||||
|
manager: EntityManager,
|
||||||
|
webapiId: number,
|
||||||
|
permissions: Array<PermissionString>
|
||||||
|
): Promise<DeleteResult> {
|
||||||
|
return await manager
|
||||||
|
.createQueryBuilder()
|
||||||
|
.delete()
|
||||||
|
.from(webapiPermission)
|
||||||
|
.where("webapiId = :id", { id: webapiId })
|
||||||
|
.andWhere("permission IN (:...permission)", { permission: permissions })
|
||||||
|
.execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description grant permission to user
|
||||||
|
* @param {CreateWebapiPermissionCommand} createPermission
|
||||||
|
* @returns {Promise<number>}
|
||||||
|
*/
|
||||||
|
static async create(createPermission: CreateWebapiPermissionCommand): Promise<number> {
|
||||||
|
return await dataSource
|
||||||
|
.createQueryBuilder()
|
||||||
|
.insert()
|
||||||
|
.into(webapiPermission)
|
||||||
|
.values({
|
||||||
|
permission: createPermission.permission,
|
||||||
|
webapiId: createPermission.webapiId,
|
||||||
|
})
|
||||||
|
.execute()
|
||||||
|
.then((result) => {
|
||||||
|
return result.identifiers[0].id;
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
throw new InternalException("Failed saving api permission", err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description remove permission from api
|
||||||
|
* @param {DeleteWebapiPermissionCommand} deletePermission
|
||||||
|
* @returns {Promise<any>}
|
||||||
|
*/
|
||||||
|
static async delete(deletePermission: DeleteWebapiPermissionCommand): Promise<any> {
|
||||||
|
return await dataSource
|
||||||
|
.createQueryBuilder()
|
||||||
|
.delete()
|
||||||
|
.from(webapiPermission)
|
||||||
|
.where("webapiId = :id", { id: deletePermission.webapiId })
|
||||||
|
.andWhere("permission = :permission", { permission: deletePermission.permission })
|
||||||
|
.execute()
|
||||||
|
.then(() => {})
|
||||||
|
.catch((err) => {
|
||||||
|
throw new InternalException("failed api permission removal", err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
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,54 @@
|
||||||
import { Request, Response } from "express";
|
import { Request, Response } from "express";
|
||||||
import MemberService from "../../service/memberService";
|
import MemberService from "../../../service/club/member/memberService";
|
||||||
import MemberFactory from "../../factory/admin/member";
|
import MemberFactory from "../../../factory/admin/club/member/member";
|
||||||
import MembershipService from "../../service/membershipService";
|
import MembershipService from "../../../service/club/member/membershipService";
|
||||||
import MembershipFactory from "../../factory/admin/membership";
|
import MembershipFactory from "../../../factory/admin/club/member/membership";
|
||||||
import MemberAwardService from "../../service/memberAwardService";
|
import MemberAwardService from "../../../service/club/member/memberAwardService";
|
||||||
import MemberAwardFactory from "../../factory/admin/memberAward";
|
import MemberAwardFactory from "../../../factory/admin/club/member/memberAward";
|
||||||
import MemberQualificationService from "../../service/memberQualificationService";
|
import MemberQualificationService from "../../../service/club/member/memberQualificationService";
|
||||||
import MemberQualificationFactory from "../../factory/admin/memberQualification";
|
import MemberQualificationFactory from "../../../factory/admin/club/member/memberQualification";
|
||||||
import MemberExecutivePositionService from "../../service/memberExecutivePositionService";
|
import MemberExecutivePositionService from "../../../service/club/member/memberExecutivePositionService";
|
||||||
import MemberExecutivePositionFactory from "../../factory/admin/memberExecutivePosition";
|
import MemberExecutivePositionFactory from "../../../factory/admin/club/member/memberExecutivePosition";
|
||||||
import CommunicationService from "../../service/communicationService";
|
import CommunicationService from "../../../service/club/member/communicationService";
|
||||||
import CommunicationFactory from "../../factory/admin/communication";
|
import CommunicationFactory from "../../../factory/admin/club/member/communication";
|
||||||
import {
|
import {
|
||||||
CreateMemberCommand,
|
CreateMemberCommand,
|
||||||
DeleteMemberCommand,
|
DeleteMemberCommand,
|
||||||
UpdateMemberCommand,
|
UpdateMemberCommand,
|
||||||
UpdateMemberNewsletterCommand,
|
} from "../../../command/club/member/memberCommand";
|
||||||
} from "../../command/memberCommand";
|
import MemberCommandHandler from "../../../command/club/member/memberCommandHandler";
|
||||||
import MemberCommandHandler from "../../command/memberCommandHandler";
|
|
||||||
import {
|
import {
|
||||||
CreateMembershipCommand,
|
CreateMembershipCommand,
|
||||||
DeleteMembershipCommand,
|
DeleteMembershipCommand,
|
||||||
UpdateMembershipCommand,
|
UpdateMembershipCommand,
|
||||||
} from "../../command/membershipCommand";
|
} from "../../../command/club/member/membershipCommand";
|
||||||
import MembershipCommandHandler from "../../command/membershipCommandHandler";
|
import MembershipCommandHandler from "../../../command/club/member/membershipCommandHandler";
|
||||||
import {
|
import {
|
||||||
CreateMemberAwardCommand,
|
CreateMemberAwardCommand,
|
||||||
DeleteMemberAwardCommand,
|
DeleteMemberAwardCommand,
|
||||||
UpdateMemberAwardCommand,
|
UpdateMemberAwardCommand,
|
||||||
} from "../../command/memberAwardCommand";
|
} from "../../../command/club/member/memberAwardCommand";
|
||||||
import MemberAwardCommandHandler from "../../command/memberAwardCommandHandler";
|
import MemberAwardCommandHandler from "../../../command/club/member/memberAwardCommandHandler";
|
||||||
import {
|
import {
|
||||||
CreateMemberExecutivePositionCommand,
|
CreateMemberExecutivePositionCommand,
|
||||||
DeleteMemberExecutivePositionCommand,
|
DeleteMemberExecutivePositionCommand,
|
||||||
UpdateMemberExecutivePositionCommand,
|
UpdateMemberExecutivePositionCommand,
|
||||||
} from "../../command/memberExecutivePositionCommand";
|
} from "../../../command/club/member/memberExecutivePositionCommand";
|
||||||
import MemberExecutivePositionCommandHandler from "../../command/memberExecutivePositionCommandHandler";
|
import MemberExecutivePositionCommandHandler from "../../../command/club/member/memberExecutivePositionCommandHandler";
|
||||||
import {
|
import {
|
||||||
CreateMemberQualificationCommand,
|
CreateMemberQualificationCommand,
|
||||||
DeleteMemberQualificationCommand,
|
DeleteMemberQualificationCommand,
|
||||||
UpdateMemberQualificationCommand,
|
UpdateMemberQualificationCommand,
|
||||||
} from "../../command/memberQualificationCommand";
|
} from "../../../command/club/member/memberQualificationCommand";
|
||||||
import MemberQualificationCommandHandler from "../../command/memberQualificationCommandHandler";
|
import MemberQualificationCommandHandler from "../../../command/club/member/memberQualificationCommandHandler";
|
||||||
import {
|
import {
|
||||||
CreateCommunicationCommand,
|
CreateCommunicationCommand,
|
||||||
DeleteCommunicationCommand,
|
DeleteCommunicationCommand,
|
||||||
UpdateCommunicationCommand,
|
UpdateCommunicationCommand,
|
||||||
} from "../../command/communicationCommand";
|
} from "../../../command/club/member/communicationCommand";
|
||||||
import CommunicationCommandHandler from "../../command/communicationCommandHandler";
|
import CommunicationCommandHandler from "../../../command/club/member/communicationCommandHandler";
|
||||||
|
import { PdfExport } from "../../../helpers/pdfExport";
|
||||||
|
import { PermissionModule } from "../../../type/permissionTypes";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description get all members
|
* @description get all members
|
||||||
|
@ -58,7 +59,14 @@ import CommunicationCommandHandler from "../../command/communicationCommandHandl
|
||||||
export async function getAllMembers(req: Request, res: Response): Promise<any> {
|
export async function getAllMembers(req: Request, res: Response): Promise<any> {
|
||||||
let offset = parseInt((req.query.offset as string) ?? "0");
|
let offset = parseInt((req.query.offset as string) ?? "0");
|
||||||
let count = parseInt((req.query.count as string) ?? "25");
|
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({
|
res.json({
|
||||||
members: MemberFactory.mapToBase(members),
|
members: MemberFactory.mapToBase(members),
|
||||||
|
@ -81,6 +89,19 @@ export async function getMemberById(req: Request, res: Response): Promise<any> {
|
||||||
res.json(MemberFactory.mapToSingle(member));
|
res.json(MemberFactory.mapToSingle(member));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description get member statistics by id
|
||||||
|
* @param req {Request} Express req object
|
||||||
|
* @param res {Response} Express res object
|
||||||
|
* @returns {Promise<*>}
|
||||||
|
*/
|
||||||
|
export async function getMemberStatisticsById(req: Request, res: Response): Promise<any> {
|
||||||
|
const memberId = parseInt(req.params.id);
|
||||||
|
let member = await MemberService.getStatisticsById(memberId);
|
||||||
|
|
||||||
|
res.json(MemberFactory.mapToMemberStatistic(member));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description get memberships by member
|
* @description get memberships by member
|
||||||
* @param req {Request} Express req object
|
* @param req {Request} Express req object
|
||||||
|
@ -94,6 +115,19 @@ export async function getMembershipsByMember(req: Request, res: Response): Promi
|
||||||
res.json(MembershipFactory.mapToBase(memberships));
|
res.json(MembershipFactory.mapToBase(memberships));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description get member statistics by id
|
||||||
|
* @param req {Request} Express req object
|
||||||
|
* @param res {Response} Express res object
|
||||||
|
* @returns {Promise<*>}
|
||||||
|
*/
|
||||||
|
export async function getMembershipStatisticsById(req: Request, res: Response): Promise<any> {
|
||||||
|
const memberId = parseInt(req.params.memberId);
|
||||||
|
let member = await MembershipService.getStatisticsById(memberId);
|
||||||
|
|
||||||
|
res.json(MembershipFactory.mapToBaseStatistics(member));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description get membership by member and record
|
* @description get membership by member and record
|
||||||
* @param req {Request} Express req object
|
* @param req {Request} Express req object
|
||||||
|
@ -216,6 +250,33 @@ export async function getCommunicationByMemberAndRecord(req: Request, res: Respo
|
||||||
res.json(CommunicationFactory.mapToSingle(communication));
|
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
|
* @description create member
|
||||||
* @param req {Request} Express req object
|
* @param req {Request} Express req object
|
||||||
|
@ -223,18 +284,20 @@ export async function getCommunicationByMemberAndRecord(req: Request, res: Respo
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<*>}
|
||||||
*/
|
*/
|
||||||
export async function createMember(req: Request, res: Response): Promise<any> {
|
export async function createMember(req: Request, res: Response): Promise<any> {
|
||||||
const salutation = req.body.salutation;
|
const salutationId = parseInt(req.body.salutationId);
|
||||||
const firstname = req.body.firstname;
|
const firstname = req.body.firstname;
|
||||||
const lastname = req.body.lastname;
|
const lastname = req.body.lastname;
|
||||||
const nameaffix = req.body.nameaffix;
|
const nameaffix = req.body.nameaffix;
|
||||||
const birthdate = req.body.birthdate;
|
const birthdate = req.body.birthdate;
|
||||||
|
const internalId = req.body.internalId;
|
||||||
|
|
||||||
let createMember: CreateMemberCommand = {
|
let createMember: CreateMemberCommand = {
|
||||||
salutation,
|
salutationId,
|
||||||
firstname,
|
firstname,
|
||||||
lastname,
|
lastname,
|
||||||
nameaffix,
|
nameaffix,
|
||||||
birthdate,
|
birthdate,
|
||||||
|
internalId,
|
||||||
};
|
};
|
||||||
let memberId = await MemberCommandHandler.create(createMember);
|
let memberId = await MemberCommandHandler.create(createMember);
|
||||||
|
|
||||||
|
@ -249,12 +312,10 @@ export async function createMember(req: Request, res: Response): Promise<any> {
|
||||||
*/
|
*/
|
||||||
export async function addMembershipToMember(req: Request, res: Response): Promise<any> {
|
export async function addMembershipToMember(req: Request, res: Response): Promise<any> {
|
||||||
const memberId = parseInt(req.params.memberId);
|
const memberId = parseInt(req.params.memberId);
|
||||||
const internalId = req.body.internalId;
|
|
||||||
const start = req.body.start;
|
const start = req.body.start;
|
||||||
const statusId = req.body.statusId;
|
const statusId = req.body.statusId;
|
||||||
|
|
||||||
let createMembership: CreateMembershipCommand = {
|
let createMembership: CreateMembershipCommand = {
|
||||||
internalId,
|
|
||||||
start,
|
start,
|
||||||
memberId,
|
memberId,
|
||||||
statusId,
|
statusId,
|
||||||
|
@ -346,19 +407,24 @@ export async function addExecutivePositionToMember(req: Request, res: Response):
|
||||||
export async function addCommunicationToMember(req: Request, res: Response): Promise<any> {
|
export async function addCommunicationToMember(req: Request, res: Response): Promise<any> {
|
||||||
const memberId = parseInt(req.params.memberId);
|
const memberId = parseInt(req.params.memberId);
|
||||||
const preferred = req.body.preferred;
|
const preferred = req.body.preferred;
|
||||||
|
const isSMSAlarming = req.body.isSMSAlarming;
|
||||||
|
const isSendNewsletter = req.body.isNewsletterMain;
|
||||||
const mobile = req.body.mobile;
|
const mobile = req.body.mobile;
|
||||||
const email = req.body.email;
|
const email = req.body.email;
|
||||||
|
const postalCode = req.body.postalCode;
|
||||||
const city = req.body.city;
|
const city = req.body.city;
|
||||||
const street = req.body.street;
|
const street = req.body.street;
|
||||||
const streetNumber = req.body.streetNumber;
|
const streetNumber = req.body.streetNumber;
|
||||||
const streetNumberAddition = req.body.streetNumberAddition;
|
const streetNumberAddition = req.body.streetNumberAddition;
|
||||||
const typeId = req.body.typeId;
|
const typeId = req.body.typeId;
|
||||||
const isNewsletterMain = req.body.isNewsletterMain;
|
|
||||||
|
|
||||||
let createCommunication: CreateCommunicationCommand = {
|
let createCommunication: CreateCommunicationCommand = {
|
||||||
preferred,
|
preferred,
|
||||||
|
isSMSAlarming,
|
||||||
|
isSendNewsletter,
|
||||||
mobile,
|
mobile,
|
||||||
email,
|
email,
|
||||||
|
postalCode,
|
||||||
city,
|
city,
|
||||||
street,
|
street,
|
||||||
streetNumber,
|
streetNumber,
|
||||||
|
@ -368,14 +434,6 @@ export async function addCommunicationToMember(req: Request, res: Response): Pro
|
||||||
};
|
};
|
||||||
let id = await CommunicationCommandHandler.create(createCommunication);
|
let id = await CommunicationCommandHandler.create(createCommunication);
|
||||||
|
|
||||||
if (isNewsletterMain) {
|
|
||||||
let updateNewsletter: UpdateMemberNewsletterCommand = {
|
|
||||||
id: memberId,
|
|
||||||
communicationId: id,
|
|
||||||
};
|
|
||||||
await MemberCommandHandler.updateNewsletter(updateNewsletter);
|
|
||||||
}
|
|
||||||
|
|
||||||
res.sendStatus(204);
|
res.sendStatus(204);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -387,19 +445,21 @@ export async function addCommunicationToMember(req: Request, res: Response): Pro
|
||||||
*/
|
*/
|
||||||
export async function updateMemberById(req: Request, res: Response): Promise<any> {
|
export async function updateMemberById(req: Request, res: Response): Promise<any> {
|
||||||
const memberId = parseInt(req.params.id);
|
const memberId = parseInt(req.params.id);
|
||||||
const salutation = req.body.salutation;
|
const salutationId = parseInt(req.body.salutationId);
|
||||||
const firstname = req.body.firstname;
|
const firstname = req.body.firstname;
|
||||||
const lastname = req.body.lastname;
|
const lastname = req.body.lastname;
|
||||||
const nameaffix = req.body.nameaffix;
|
const nameaffix = req.body.nameaffix;
|
||||||
const birthdate = req.body.birthdate;
|
const birthdate = req.body.birthdate;
|
||||||
|
const internalId = req.body.internalId;
|
||||||
|
|
||||||
let updateMember: UpdateMemberCommand = {
|
let updateMember: UpdateMemberCommand = {
|
||||||
id: memberId,
|
id: memberId,
|
||||||
salutation,
|
salutationId,
|
||||||
firstname,
|
firstname,
|
||||||
lastname,
|
lastname,
|
||||||
nameaffix,
|
nameaffix,
|
||||||
birthdate,
|
birthdate,
|
||||||
|
internalId,
|
||||||
};
|
};
|
||||||
await MemberCommandHandler.update(updateMember);
|
await MemberCommandHandler.update(updateMember);
|
||||||
|
|
||||||
|
@ -415,7 +475,6 @@ export async function updateMemberById(req: Request, res: Response): Promise<any
|
||||||
export async function updateMembershipOfMember(req: Request, res: Response): Promise<any> {
|
export async function updateMembershipOfMember(req: Request, res: Response): Promise<any> {
|
||||||
const memberId = parseInt(req.params.memberId);
|
const memberId = parseInt(req.params.memberId);
|
||||||
const recordId = parseInt(req.params.recordId);
|
const recordId = parseInt(req.params.recordId);
|
||||||
const internalId = req.body.internalId;
|
|
||||||
const start = req.body.start;
|
const start = req.body.start;
|
||||||
const end = req.body.end || null;
|
const end = req.body.end || null;
|
||||||
const terminationReason = req.body.terminationReason;
|
const terminationReason = req.body.terminationReason;
|
||||||
|
@ -423,7 +482,6 @@ export async function updateMembershipOfMember(req: Request, res: Response): Pro
|
||||||
|
|
||||||
let updateMembership: UpdateMembershipCommand = {
|
let updateMembership: UpdateMembershipCommand = {
|
||||||
id: recordId,
|
id: recordId,
|
||||||
internalId,
|
|
||||||
start,
|
start,
|
||||||
end,
|
end,
|
||||||
terminationReason,
|
terminationReason,
|
||||||
|
@ -528,20 +586,24 @@ export async function updateCommunicationOfMember(req: Request, res: Response):
|
||||||
const memberId = parseInt(req.params.memberId);
|
const memberId = parseInt(req.params.memberId);
|
||||||
const recordId = parseInt(req.params.recordId);
|
const recordId = parseInt(req.params.recordId);
|
||||||
const preferred = req.body.preferred;
|
const preferred = req.body.preferred;
|
||||||
|
const isSMSAlarming = req.body.isSMSAlarming;
|
||||||
|
const isSendNewsletter = req.body.isNewsletterMain;
|
||||||
const mobile = req.body.mobile;
|
const mobile = req.body.mobile;
|
||||||
const email = req.body.email;
|
const email = req.body.email;
|
||||||
|
const postalCode = req.body.postalCode;
|
||||||
const city = req.body.city;
|
const city = req.body.city;
|
||||||
const street = req.body.street;
|
const street = req.body.street;
|
||||||
const streetNumber = req.body.streetNumber;
|
const streetNumber = req.body.streetNumber;
|
||||||
const streetNumberAddition = req.body.streetNumberAddition;
|
const streetNumberAddition = req.body.streetNumberAddition;
|
||||||
const typeId = req.body.typeId;
|
|
||||||
const isNewsletterMain = req.body.isNewsletterMain;
|
|
||||||
|
|
||||||
let updateCommunication: UpdateCommunicationCommand = {
|
let updateCommunication: UpdateCommunicationCommand = {
|
||||||
id: recordId,
|
id: recordId,
|
||||||
preferred,
|
preferred,
|
||||||
|
isSMSAlarming,
|
||||||
|
isSendNewsletter,
|
||||||
mobile,
|
mobile,
|
||||||
email,
|
email,
|
||||||
|
postalCode,
|
||||||
city,
|
city,
|
||||||
street,
|
street,
|
||||||
streetNumber,
|
streetNumber,
|
||||||
|
@ -550,14 +612,6 @@ export async function updateCommunicationOfMember(req: Request, res: Response):
|
||||||
};
|
};
|
||||||
await CommunicationCommandHandler.update(updateCommunication);
|
await CommunicationCommandHandler.update(updateCommunication);
|
||||||
|
|
||||||
if (isNewsletterMain) {
|
|
||||||
let updateNewsletter: UpdateMemberNewsletterCommand = {
|
|
||||||
id: memberId,
|
|
||||||
communicationId: recordId,
|
|
||||||
};
|
|
||||||
await MemberCommandHandler.updateNewsletter(updateNewsletter);
|
|
||||||
}
|
|
||||||
|
|
||||||
res.sendStatus(204);
|
res.sendStatus(204);
|
||||||
}
|
}
|
||||||
|
|
387
src/controller/admin/club/newsletterController.ts
Normal file
387
src/controller/admin/club/newsletterController.ts
Normal file
|
@ -0,0 +1,387 @@
|
||||||
|
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";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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: "Anrede",
|
||||||
|
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: "Anrede",
|
||||||
|
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 { Request, Response } from "express";
|
||||||
import AwardService from "../../service/awardService";
|
import AwardService from "../../../service/settings/awardService";
|
||||||
import AwardFactory from "../../factory/admin/award";
|
import AwardFactory from "../../../factory/admin/settings/award";
|
||||||
import { CreateAwardCommand, DeleteAwardCommand, UpdateAwardCommand } from "../../command/awardCommand";
|
import { CreateAwardCommand, DeleteAwardCommand, UpdateAwardCommand } from "../../../command/settings/award/awardCommand";
|
||||||
import AwardCommandHandler from "../../command/awardCommandHandler";
|
import AwardCommandHandler from "../../../command/settings/award/awardCommandHandler";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description get all awards
|
* @description get all awards
|
|
@ -1,13 +1,13 @@
|
||||||
import { Request, Response } from "express";
|
import { Request, Response } from "express";
|
||||||
import CommunicationTypeService from "../../service/communicationTypeService";
|
import CommunicationTypeService from "../../../service/settings/communicationTypeService";
|
||||||
import CommunicationTypeFactory from "../../factory/admin/communicationType";
|
import CommunicationTypeFactory from "../../../factory/admin/settings/communicationType";
|
||||||
import CommunicationService from "../../service/communicationService";
|
import CommunicationService from "../../../service/club/member/communicationService";
|
||||||
import {
|
import {
|
||||||
CreateCommunicationTypeCommand,
|
CreateCommunicationTypeCommand,
|
||||||
DeleteCommunicationTypeCommand,
|
DeleteCommunicationTypeCommand,
|
||||||
UpdateCommunicationTypeCommand,
|
UpdateCommunicationTypeCommand,
|
||||||
} from "../../command/communicationTypeCommand";
|
} from "../../../command/settings/communicationType/communicationTypeCommand";
|
||||||
import CommunicationTypeCommandHandler from "../../command/communicationTypeCommandHandler";
|
import CommunicationTypeCommandHandler from "../../../command/settings/communicationType/communicationTypeCommandHandler";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description get all communicationTypes
|
* @description get all communicationTypes
|
|
@ -1,12 +1,12 @@
|
||||||
import { Request, Response } from "express";
|
import { Request, Response } from "express";
|
||||||
import ExecutivePositionService from "../../service/executivePositionService";
|
import ExecutivePositionService from "../../../service/settings/executivePositionService";
|
||||||
import ExecutivePositionFactory from "../../factory/admin/executivePosition";
|
import ExecutivePositionFactory from "../../../factory/admin/settings/executivePosition";
|
||||||
import {
|
import {
|
||||||
CreateExecutivePositionCommand,
|
CreateExecutivePositionCommand,
|
||||||
DeleteExecutivePositionCommand,
|
DeleteExecutivePositionCommand,
|
||||||
UpdateExecutivePositionCommand,
|
UpdateExecutivePositionCommand,
|
||||||
} from "../../command/executivePositionCommand";
|
} from "../../../command/settings/executivePosition/executivePositionCommand";
|
||||||
import ExecutivePositionCommandHandler from "../../command/executivePositionCommandHandler";
|
import ExecutivePositionCommandHandler from "../../../command/settings/executivePosition/executivePositionCommandHandler";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description get all executivePositions
|
* @description get all executivePositions
|
|
@ -1,12 +1,12 @@
|
||||||
import { Request, Response } from "express";
|
import { Request, Response } from "express";
|
||||||
import MembershipStatusService from "../../service/membershipStatusService";
|
import MembershipStatusService from "../../../service/settings/membershipStatusService";
|
||||||
import MembershipStatusFactory from "../../factory/admin/membershipStatus";
|
import MembershipStatusFactory from "../../../factory/admin/settings/membershipStatus";
|
||||||
import {
|
import {
|
||||||
CreateMembershipStatusCommand,
|
CreateMembershipStatusCommand,
|
||||||
DeleteMembershipStatusCommand,
|
DeleteMembershipStatusCommand,
|
||||||
UpdateMembershipStatusCommand,
|
UpdateMembershipStatusCommand,
|
||||||
} from "../../command/membershipStatusCommand";
|
} from "../../../command/settings/membershipStatus/membershipStatusCommand";
|
||||||
import MembershipStatusCommandHandler from "../../command/membershipStatusCommandHandler";
|
import MembershipStatusCommandHandler from "../../../command/settings/membershipStatus/membershipStatusCommandHandler";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description get all membershipStatus
|
* @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 { Request, Response } from "express";
|
||||||
import QualificationService from "../../service/qualification";
|
import QualificationService from "../../../service/settings/qualification";
|
||||||
import QualificationFactory from "../../factory/admin/qualification";
|
import QualificationFactory from "../../../factory/admin/settings/qualification";
|
||||||
import {
|
import {
|
||||||
CreateQualificationCommand,
|
CreateQualificationCommand,
|
||||||
DeleteQualificationCommand,
|
DeleteQualificationCommand,
|
||||||
UpdateQualificationCommand,
|
UpdateQualificationCommand,
|
||||||
} from "../../command/qualificationCommand";
|
} from "../../../command/settings/qualification/qualificationCommand";
|
||||||
import QualificationCommandHandler from "../../command/qualificationCommandHandler";
|
import QualificationCommandHandler from "../../../command/settings/qualification/qualificationCommandHandler";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description get all qualifications
|
* @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);
|
||||||
|
}
|
87
src/controller/admin/settings/salutationController.ts
Normal file
87
src/controller/admin/settings/salutationController.ts
Normal file
|
@ -0,0 +1,87 @@
|
||||||
|
import { Request, Response } from "express";
|
||||||
|
import SalutationService from "../../../service/settings/salutationService";
|
||||||
|
import SalutationFactory from "../../../factory/admin/settings/salutation";
|
||||||
|
import {
|
||||||
|
CreateSalutationCommand,
|
||||||
|
DeleteSalutationCommand,
|
||||||
|
UpdateSalutationCommand,
|
||||||
|
} from "../../../command/settings/salutation/salutationCommand";
|
||||||
|
import SalutationCommandHandler from "../../../command/settings/salutation/salutationCommandHandler";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description get all salutations
|
||||||
|
* @param req {Request} Express req object
|
||||||
|
* @param res {Response} Express res object
|
||||||
|
* @returns {Promise<*>}
|
||||||
|
*/
|
||||||
|
export async function getAllSalutations(req: Request, res: Response): Promise<any> {
|
||||||
|
let salutations = await SalutationService.getAll();
|
||||||
|
|
||||||
|
res.json(SalutationFactory.mapToBase(salutations));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description get salutation by id
|
||||||
|
* @param req {Request} Express req object
|
||||||
|
* @param res {Response} Express res object
|
||||||
|
* @returns {Promise<*>}
|
||||||
|
*/
|
||||||
|
export async function getSalutationById(req: Request, res: Response): Promise<any> {
|
||||||
|
const id = parseInt(req.params.id);
|
||||||
|
let salutation = await SalutationService.getById(id);
|
||||||
|
|
||||||
|
res.json(SalutationFactory.mapToSingle(salutation));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description create new salutation
|
||||||
|
* @param req {Request} Express req object
|
||||||
|
* @param res {Response} Express res object
|
||||||
|
* @returns {Promise<*>}
|
||||||
|
*/
|
||||||
|
export async function createSalutation(req: Request, res: Response): Promise<any> {
|
||||||
|
const salutation = req.body.salutation;
|
||||||
|
|
||||||
|
let createSalutation: CreateSalutationCommand = {
|
||||||
|
salutation: salutation,
|
||||||
|
};
|
||||||
|
await SalutationCommandHandler.create(createSalutation);
|
||||||
|
|
||||||
|
res.sendStatus(204);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description update salutation
|
||||||
|
* @param req {Request} Express req object
|
||||||
|
* @param res {Response} Express res object
|
||||||
|
* @returns {Promise<*>}
|
||||||
|
*/
|
||||||
|
export async function updateSalutation(req: Request, res: Response): Promise<any> {
|
||||||
|
const id = parseInt(req.params.id);
|
||||||
|
const salutation = req.body.salutation;
|
||||||
|
|
||||||
|
let updateSalutation: UpdateSalutationCommand = {
|
||||||
|
id: id,
|
||||||
|
salutation: salutation,
|
||||||
|
};
|
||||||
|
await SalutationCommandHandler.update(updateSalutation);
|
||||||
|
|
||||||
|
res.sendStatus(204);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description delete salutation
|
||||||
|
* @param req {Request} Express req object
|
||||||
|
* @param res {Response} Express res object
|
||||||
|
* @returns {Promise<*>}
|
||||||
|
*/
|
||||||
|
export async function deleteSalutation(req: Request, res: Response): Promise<any> {
|
||||||
|
const id = parseInt(req.params.id);
|
||||||
|
|
||||||
|
let deleteSalutation: DeleteSalutationCommand = {
|
||||||
|
id: id,
|
||||||
|
};
|
||||||
|
await SalutationCommandHandler.delete(deleteSalutation);
|
||||||
|
|
||||||
|
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 { Request, Response } from "express";
|
||||||
import RoleService from "../../service/roleService";
|
import RoleService from "../../../service/user/roleService";
|
||||||
import RoleFactory from "../../factory/admin/role";
|
import RoleFactory from "../../../factory/admin/user/role";
|
||||||
import RolePermissionService from "../../service/rolePermissionService";
|
import RolePermissionService from "../../../service/user/rolePermissionService";
|
||||||
import PermissionHelper from "../../helpers/permissionHelper";
|
import PermissionHelper from "../../../helpers/permissionHelper";
|
||||||
import { CreateRoleCommand, DeleteRoleCommand, UpdateRoleCommand } from "../../command/roleCommand";
|
import { CreateRoleCommand, DeleteRoleCommand, UpdateRoleCommand } from "../../../command/user/role/roleCommand";
|
||||||
import RoleCommandHandler from "../../command/roleCommandHandler";
|
import RoleCommandHandler from "../../../command/user/role/roleCommandHandler";
|
||||||
import { UpdateRolePermissionsCommand } from "../../command/rolePermissionCommand";
|
import { UpdateRolePermissionsCommand } from "../../../command/user/role/rolePermissionCommand";
|
||||||
import RolePermissionCommandHandler from "../../command/rolePermissionCommandHandler";
|
import RolePermissionCommandHandler from "../../../command/user/role/rolePermissionCommandHandler";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description get All roles
|
* @description get All roles
|
|
@ -1,15 +1,16 @@
|
||||||
import { Request, Response } from "express";
|
import { Request, Response } from "express";
|
||||||
import UserService from "../../service/userService";
|
import UserService from "../../../service/user/userService";
|
||||||
import UserFactory from "../../factory/admin/user";
|
import UserFactory from "../../../factory/admin/user/user";
|
||||||
import UserPermissionService from "../../service/userPermissionService";
|
import UserPermissionService from "../../../service/user/userPermissionService";
|
||||||
import PermissionHelper from "../../helpers/permissionHelper";
|
import PermissionHelper from "../../../helpers/permissionHelper";
|
||||||
import RoleFactory from "../../factory/admin/role";
|
import RoleFactory from "../../../factory/admin/user/role";
|
||||||
import { DeleteUserCommand, UpdateUserCommand, UpdateUserRolesCommand } from "../../command/userCommand";
|
import { DeleteUserCommand, UpdateUserCommand, UpdateUserRolesCommand } from "../../../command/user/user/userCommand";
|
||||||
import UserCommandHandler from "../../command/userCommandHandler";
|
import UserCommandHandler from "../../../command/user/user/userCommandHandler";
|
||||||
import MailHelper from "../../helpers/mailHelper";
|
import MailHelper from "../../../helpers/mailHelper";
|
||||||
import { CLUB_NAME } from "../../env.defaults";
|
import { CLUB_NAME } from "../../../env.defaults";
|
||||||
import { UpdateUserPermissionsCommand } from "../../command/userPermissionCommand";
|
import { UpdateUserPermissionsCommand } from "../../../command/user/user/userPermissionCommand";
|
||||||
import UserPermissionCommandHandler from "../../command/userPermissionCommandHandler";
|
import UserPermissionCommandHandler from "../../../command/user/user/userPermissionCommandHandler";
|
||||||
|
import BadRequestException from "../../../exceptions/badRequestException";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description get All users
|
* @description get All users
|
||||||
|
@ -137,7 +138,11 @@ export async function updateUserRoles(req: Request, res: Response): Promise<any>
|
||||||
export async function deleteUser(req: Request, res: Response): Promise<any> {
|
export async function deleteUser(req: Request, res: Response): Promise<any> {
|
||||||
const id = parseInt(req.params.id);
|
const id = parseInt(req.params.id);
|
||||||
|
|
||||||
let user = await UserService.getById(id);
|
let { mail, isOwner } = await UserService.getById(id);
|
||||||
|
|
||||||
|
if (isOwner) {
|
||||||
|
throw new BadRequestException("Owner cannot be deleted");
|
||||||
|
}
|
||||||
|
|
||||||
let deleteUser: DeleteUserCommand = {
|
let deleteUser: DeleteUserCommand = {
|
||||||
id: id,
|
id: id,
|
||||||
|
@ -146,9 +151,8 @@ export async function deleteUser(req: Request, res: Response): Promise<any> {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// sendmail
|
// sendmail
|
||||||
let mailhelper = new MailHelper();
|
await MailHelper.sendMail(
|
||||||
await mailhelper.sendMail(
|
mail,
|
||||||
user.mail,
|
|
||||||
`Email Bestätigung für Mitglieder Admin-Portal von ${CLUB_NAME}`,
|
`Email Bestätigung für Mitglieder Admin-Portal von ${CLUB_NAME}`,
|
||||||
`Ihr Nutzerkonto des Adminportals wurde erfolgreich gelöscht.`
|
`Ihr Nutzerkonto des Adminportals wurde erfolgreich gelöscht.`
|
||||||
);
|
);
|
155
src/controller/admin/user/webapiController.ts
Normal file
155
src/controller/admin/user/webapiController.ts
Normal file
|
@ -0,0 +1,155 @@
|
||||||
|
import { Request, Response } from "express";
|
||||||
|
import WebapiService from "../../../service/user/webapiService";
|
||||||
|
import ApiFactory from "../../../factory/admin/user/webapi";
|
||||||
|
import WebapiPermissionService from "../../../service/user/webapiPermissionService";
|
||||||
|
import PermissionHelper from "../../../helpers/permissionHelper";
|
||||||
|
import {
|
||||||
|
CreateWebapiCommand,
|
||||||
|
DeleteWebapiCommand,
|
||||||
|
UpdateWebapiCommand,
|
||||||
|
} from "../../../command/user/webapi/webapiCommand";
|
||||||
|
import WebapiCommandHandler from "../../../command/user/webapi/webapiCommandHandler";
|
||||||
|
import { UpdateWebapiPermissionsCommand } from "../../../command/user/webapi/webapiPermissionCommand";
|
||||||
|
import WebapiPermissionCommandHandler from "../../../command/user/webapi/webapiPermissionCommandHandler";
|
||||||
|
import { JWTHelper } from "../../../helpers/jwtHelper";
|
||||||
|
import { CLUB_NAME } from "../../../env.defaults";
|
||||||
|
import { StringHelper } from "../../../helpers/stringHelper";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description get All apis
|
||||||
|
* @param req {Request} Express req object
|
||||||
|
* @param res {Response} Express res object
|
||||||
|
* @returns {Promise<*>}
|
||||||
|
*/
|
||||||
|
export async function getAllWebapis(req: Request, res: Response): Promise<any> {
|
||||||
|
let apis = await WebapiService.getAll();
|
||||||
|
|
||||||
|
res.json(ApiFactory.mapToBase(apis));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description get api by id
|
||||||
|
* @param req {Request} Express req object
|
||||||
|
* @param res {Response} Express res object
|
||||||
|
* @returns {Promise<*>}
|
||||||
|
*/
|
||||||
|
export async function getWebapiById(req: Request, res: Response): Promise<any> {
|
||||||
|
const id = parseInt(req.params.id);
|
||||||
|
let api = await WebapiService.getById(id);
|
||||||
|
|
||||||
|
res.json(ApiFactory.mapToSingle(api));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description get api token by id
|
||||||
|
* @param req {Request} Express req object
|
||||||
|
* @param res {Response} Express res object
|
||||||
|
* @returns {Promise<*>}
|
||||||
|
*/
|
||||||
|
export async function getWebapiTokenById(req: Request, res: Response): Promise<any> {
|
||||||
|
const id = parseInt(req.params.id);
|
||||||
|
let { token } = await WebapiService.getTokenById(id);
|
||||||
|
|
||||||
|
res.send(token);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description get permissions by api
|
||||||
|
* @param req {Request} Express req object
|
||||||
|
* @param res {Response} Express res object
|
||||||
|
* @returns {Promise<*>}
|
||||||
|
*/
|
||||||
|
export async function getWebapiPermissions(req: Request, res: Response): Promise<any> {
|
||||||
|
const id = parseInt(req.params.id);
|
||||||
|
let permissions = await WebapiPermissionService.getByApi(id);
|
||||||
|
|
||||||
|
res.json(PermissionHelper.convertToObject(permissions.map((p) => p.permission)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description create new api
|
||||||
|
* @param req {Request} Express req object
|
||||||
|
* @param res {Response} Express res object
|
||||||
|
* @returns {Promise<*>}
|
||||||
|
*/
|
||||||
|
export async function createWebapi(req: Request, res: Response): Promise<any> {
|
||||||
|
let title = req.body.title;
|
||||||
|
let expiry = req.body.expiry || null;
|
||||||
|
|
||||||
|
let token = await JWTHelper.create(
|
||||||
|
{
|
||||||
|
iss: CLUB_NAME,
|
||||||
|
sub: "api_token_retrieve",
|
||||||
|
aud: StringHelper.random(32),
|
||||||
|
},
|
||||||
|
{ useExpiration: false }
|
||||||
|
);
|
||||||
|
|
||||||
|
let createApi: CreateWebapiCommand = {
|
||||||
|
token: token,
|
||||||
|
title: title,
|
||||||
|
expiry: expiry,
|
||||||
|
};
|
||||||
|
await WebapiCommandHandler.create(createApi);
|
||||||
|
|
||||||
|
res.sendStatus(204);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description update api data
|
||||||
|
* @param req {Request} Express req object
|
||||||
|
* @param res {Response} Express res object
|
||||||
|
* @returns {Promise<*>}
|
||||||
|
*/
|
||||||
|
export async function updateWebapi(req: Request, res: Response): Promise<any> {
|
||||||
|
const id = parseInt(req.params.id);
|
||||||
|
let title = req.body.title;
|
||||||
|
let expiry = req.body.expiry || null;
|
||||||
|
|
||||||
|
let updateApi: UpdateWebapiCommand = {
|
||||||
|
id: id,
|
||||||
|
title: title,
|
||||||
|
expiry: expiry,
|
||||||
|
};
|
||||||
|
await WebapiCommandHandler.update(updateApi);
|
||||||
|
|
||||||
|
res.sendStatus(204);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description update api assigned permission strings
|
||||||
|
* @param req {Request} Express req object
|
||||||
|
* @param res {Response} Express res object
|
||||||
|
* @returns {Promise<*>}
|
||||||
|
*/
|
||||||
|
export async function updateWebapiPermissions(req: Request, res: Response): Promise<any> {
|
||||||
|
const id = parseInt(req.params.id);
|
||||||
|
let permissions = req.body.permissions;
|
||||||
|
|
||||||
|
let permissionStrings = PermissionHelper.convertToStringArray(permissions);
|
||||||
|
|
||||||
|
let updateApiPermissions: UpdateWebapiPermissionsCommand = {
|
||||||
|
webapiId: id,
|
||||||
|
permissions: permissionStrings,
|
||||||
|
};
|
||||||
|
await WebapiPermissionCommandHandler.updatePermissions(updateApiPermissions);
|
||||||
|
|
||||||
|
res.sendStatus(204);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description delete api by id
|
||||||
|
* @param req {Request} Express req object
|
||||||
|
* @param res {Response} Express res object
|
||||||
|
* @returns {Promise<*>}
|
||||||
|
*/
|
||||||
|
export async function deleteWebapi(req: Request, res: Response): Promise<any> {
|
||||||
|
const id = parseInt(req.params.id);
|
||||||
|
|
||||||
|
let deleteApi: DeleteWebapiCommand = {
|
||||||
|
id: id,
|
||||||
|
};
|
||||||
|
await WebapiCommandHandler.delete(deleteApi);
|
||||||
|
|
||||||
|
res.sendStatus(204);
|
||||||
|
}
|
|
@ -4,13 +4,10 @@ import { JWTToken } from "../type/jwtTypes";
|
||||||
import InternalException from "../exceptions/internalException";
|
import InternalException from "../exceptions/internalException";
|
||||||
import RefreshCommandHandler from "../command/refreshCommandHandler";
|
import RefreshCommandHandler from "../command/refreshCommandHandler";
|
||||||
import { CreateRefreshCommand, DeleteRefreshCommand } from "../command/refreshCommand";
|
import { CreateRefreshCommand, DeleteRefreshCommand } from "../command/refreshCommand";
|
||||||
import UserService from "../service/userService";
|
import UserService from "../service/user/userService";
|
||||||
import speakeasy from "speakeasy";
|
import speakeasy from "speakeasy";
|
||||||
import UnauthorizedRequestException from "../exceptions/unauthorizedRequestException";
|
import UnauthorizedRequestException from "../exceptions/unauthorizedRequestException";
|
||||||
import RefreshService from "../service/refreshService";
|
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
|
* @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 username = req.body.username;
|
||||||
let totp = req.body.totp;
|
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({
|
let valid = speakeasy.totp.verify({
|
||||||
secret: secret,
|
secret: secret,
|
||||||
|
@ -35,38 +32,13 @@ export async function login(req: Request, res: Response): Promise<any> {
|
||||||
throw new UnauthorizedRequestException("Token not valid or expired");
|
throw new UnauthorizedRequestException("Token not valid or expired");
|
||||||
}
|
}
|
||||||
|
|
||||||
let userPermissions = await UserPermissionService.getByUser(id);
|
let accessToken = await JWTHelper.buildToken(id);
|
||||||
let userPermissionStrings = userPermissions.map((e) => e.permission);
|
|
||||||
let userRoles = await UserService.getAssignedRolesByUserId(id);
|
|
||||||
let rolePermissions = userRoles.length != 0 ? await RolePermissionService.getByRoles(userRoles.map((e) => e.id)) : [];
|
|
||||||
let rolePermissionStrings = rolePermissions.map((e) => e.permission);
|
|
||||||
let permissionObject = PermissionHelper.convertToObject([...userPermissionStrings, ...rolePermissionStrings]);
|
|
||||||
|
|
||||||
let jwtData: JWTToken = {
|
|
||||||
userId: id,
|
|
||||||
mail: mail,
|
|
||||||
username: username,
|
|
||||||
firstname: firstname,
|
|
||||||
lastname: lastname,
|
|
||||||
permissions: permissionObject,
|
|
||||||
};
|
|
||||||
|
|
||||||
let accessToken: string;
|
|
||||||
let refreshToken: string;
|
|
||||||
|
|
||||||
JWTHelper.create(jwtData)
|
|
||||||
.then((result) => {
|
|
||||||
accessToken = result;
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
console.log(err);
|
|
||||||
throw new InternalException("Failed accessToken creation", err);
|
|
||||||
});
|
|
||||||
|
|
||||||
let refreshCommand: CreateRefreshCommand = {
|
let refreshCommand: CreateRefreshCommand = {
|
||||||
userId: id,
|
userId: id,
|
||||||
|
isFromPwa: req.isPWA,
|
||||||
};
|
};
|
||||||
refreshToken = await RefreshCommandHandler.create(refreshCommand);
|
let refreshToken = await RefreshCommandHandler.create(refreshCommand);
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
accessToken,
|
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");
|
throw new UnauthorizedRequestException("user not identified with token and refresh");
|
||||||
}
|
}
|
||||||
|
|
||||||
let { id, username, mail, firstname, lastname } = await UserService.getById(tokenUserId);
|
let accessToken = await JWTHelper.buildToken(tokenUserId);
|
||||||
|
|
||||||
let permissions = await UserPermissionService.getByUser(id);
|
|
||||||
let permissionStrings = permissions.map((e) => e.permission);
|
|
||||||
let permissionObject = PermissionHelper.convertToObject(permissionStrings);
|
|
||||||
|
|
||||||
let jwtData: JWTToken = {
|
|
||||||
userId: id,
|
|
||||||
mail: mail,
|
|
||||||
username: username,
|
|
||||||
firstname: firstname,
|
|
||||||
lastname: lastname,
|
|
||||||
permissions: permissionObject,
|
|
||||||
};
|
|
||||||
|
|
||||||
let accessToken: string;
|
|
||||||
let refreshToken: string;
|
|
||||||
|
|
||||||
JWTHelper.create(jwtData)
|
|
||||||
.then((result) => {
|
|
||||||
accessToken = result;
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
throw new InternalException("Failed accessToken creation", err);
|
|
||||||
});
|
|
||||||
|
|
||||||
let refreshCommand: CreateRefreshCommand = {
|
let refreshCommand: CreateRefreshCommand = {
|
||||||
userId: id,
|
userId: tokenUserId,
|
||||||
|
isFromPwa: req.isPWA,
|
||||||
};
|
};
|
||||||
refreshToken = await RefreshCommandHandler.create(refreshCommand);
|
let refreshToken = await RefreshCommandHandler.create(refreshCommand);
|
||||||
|
|
||||||
let removeToken: DeleteRefreshCommand = {
|
let removeToken: DeleteRefreshCommand = {
|
||||||
userId: id,
|
userId: tokenUserId,
|
||||||
token: refresh,
|
token: refresh,
|
||||||
};
|
};
|
||||||
await RefreshCommandHandler.deleteByToken(removeToken);
|
await RefreshCommandHandler.deleteByToken(removeToken);
|
||||||
|
|
|
@ -7,17 +7,30 @@ import { CreateRefreshCommand } from "../command/refreshCommand";
|
||||||
import speakeasy from "speakeasy";
|
import speakeasy from "speakeasy";
|
||||||
import UnauthorizedRequestException from "../exceptions/unauthorizedRequestException";
|
import UnauthorizedRequestException from "../exceptions/unauthorizedRequestException";
|
||||||
import QRCode from "qrcode";
|
import QRCode from "qrcode";
|
||||||
import { CreateUserCommand } from "../command/userCommand";
|
import { CreateUserCommand } from "../command/user/user/userCommand";
|
||||||
import UserCommandHandler from "../command/userCommandHandler";
|
import UserCommandHandler from "../command/user/user/userCommandHandler";
|
||||||
import { CreateInviteCommand, DeleteInviteCommand } from "../command/inviteCommand";
|
import { CreateInviteCommand, DeleteInviteCommand } from "../command/user/user/inviteCommand";
|
||||||
import InviteCommandHandler from "../command/inviteCommandHandler";
|
import InviteCommandHandler from "../command/user/user/inviteCommandHandler";
|
||||||
import MailHelper from "../helpers/mailHelper";
|
import MailHelper from "../helpers/mailHelper";
|
||||||
import InviteService from "../service/inviteService";
|
import InviteService from "../service/user/inviteService";
|
||||||
import UserService from "../service/userService";
|
import UserService from "../service/user/userService";
|
||||||
import CustomRequestException from "../exceptions/customRequestException";
|
import CustomRequestException from "../exceptions/customRequestException";
|
||||||
import { CLUB_NAME } from "../env.defaults";
|
import { CLUB_NAME } from "../env.defaults";
|
||||||
import { CreateUserPermissionCommand } from "../command/userPermissionCommand";
|
import { CreateUserPermissionCommand } from "../command/user/user/userPermissionCommand";
|
||||||
import UserPermissionCommandHandler from "../command/userPermissionCommandHandler";
|
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
|
* @description start first user
|
||||||
|
@ -58,8 +71,7 @@ export async function inviteUser(req: Request, res: Response, isInvite: boolean
|
||||||
let token = await InviteCommandHandler.create(createInvite);
|
let token = await InviteCommandHandler.create(createInvite);
|
||||||
|
|
||||||
// sendmail
|
// sendmail
|
||||||
let mailhelper = new MailHelper();
|
await MailHelper.sendMail(
|
||||||
await mailhelper.sendMail(
|
|
||||||
mail,
|
mail,
|
||||||
`Email Bestätigung für Mitglieder Admin-Portal von ${CLUB_NAME}`,
|
`Email Bestätigung für Mitglieder Admin-Portal von ${CLUB_NAME}`,
|
||||||
`Öffne folgenden Link: ${origin}/${isInvite ? "invite" : "setup"}/verify?mail=${mail}&token=${token}`
|
`Ö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 mail = req.body.mail;
|
||||||
let token = req.body.token;
|
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}`;
|
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({
|
res.json({
|
||||||
dataUrl: result,
|
dataUrl: result,
|
||||||
otp: secret,
|
otp: secret,
|
||||||
|
username,
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
|
@ -124,43 +137,16 @@ export async function finishInvite(req: Request, res: Response, grantAdmin: bool
|
||||||
lastname: lastname,
|
lastname: lastname,
|
||||||
mail: mail,
|
mail: mail,
|
||||||
secret: secret,
|
secret: secret,
|
||||||
|
isOwner: grantAdmin,
|
||||||
};
|
};
|
||||||
let id = await UserCommandHandler.create(createUser);
|
let id = await UserCommandHandler.create(createUser);
|
||||||
|
|
||||||
if (grantAdmin) {
|
let accessToken = await JWTHelper.buildToken(id);
|
||||||
let createPermission: CreateUserPermissionCommand = {
|
|
||||||
permission: "*",
|
|
||||||
userId: id,
|
|
||||||
};
|
|
||||||
await UserPermissionCommandHandler.create(createPermission);
|
|
||||||
}
|
|
||||||
|
|
||||||
let jwtData: JWTToken = {
|
|
||||||
userId: id,
|
|
||||||
mail: mail,
|
|
||||||
username: username,
|
|
||||||
firstname: firstname,
|
|
||||||
lastname: lastname,
|
|
||||||
permissions: {
|
|
||||||
...(grantAdmin ? { admin: true } : {}),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
let accessToken: string;
|
|
||||||
let refreshToken: string;
|
|
||||||
|
|
||||||
JWTHelper.create(jwtData)
|
|
||||||
.then((result) => {
|
|
||||||
accessToken = result;
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
throw new InternalException("Failed accessToken creation", err);
|
|
||||||
});
|
|
||||||
|
|
||||||
let refreshCommand: CreateRefreshCommand = {
|
let refreshCommand: CreateRefreshCommand = {
|
||||||
userId: id,
|
userId: id,
|
||||||
};
|
};
|
||||||
refreshToken = await RefreshCommandHandler.create(refreshCommand);
|
let refreshToken = await RefreshCommandHandler.create(refreshCommand);
|
||||||
|
|
||||||
let deleteInvite: DeleteInviteCommand = {
|
let deleteInvite: DeleteInviteCommand = {
|
||||||
mail: mail,
|
mail: mail,
|
||||||
|
@ -173,3 +159,17 @@ export async function finishInvite(req: Request, res: Response, grantAdmin: bool
|
||||||
refreshToken,
|
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);
|
||||||
|
}
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue