Compare commits
4 commits
main
...
anton/expo
Author | SHA1 | Date | |
---|---|---|---|
bfd630ec26 | |||
223c47133b | |||
|
36d47b0d12 | ||
5503749705 |
319 changed files with 995 additions and 11732 deletions
|
@ -1,6 +0,0 @@
|
||||||
# NodeJs
|
|
||||||
node_modules/
|
|
||||||
dist/
|
|
||||||
.git/
|
|
||||||
files/
|
|
||||||
.env
|
|
|
@ -1,5 +1,4 @@
|
||||||
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
|
||||||
|
@ -10,7 +9,6 @@ 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
|
||||||
|
@ -18,5 +16,4 @@ 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 #default FF Admin
|
CLUB_NAME = clubname
|
||||||
CLUB_WEBSITE = https://my-club-website-url
|
|
5
.gitignore
vendored
5
.gitignore
vendored
|
@ -130,6 +130,5 @@ dist
|
||||||
.yarn/install-state.gz
|
.yarn/install-state.gz
|
||||||
.pnp.*
|
.pnp.*
|
||||||
|
|
||||||
files
|
# WebStorm
|
||||||
|
.idea/
|
||||||
.idea
|
|
||||||
|
|
46
Dockerfile
46
Dockerfile
|
@ -1,46 +0,0 @@
|
||||||
FROM node:18-alpine AS build
|
|
||||||
|
|
||||||
RUN apk add --no-cache \
|
|
||||||
chromium \
|
|
||||||
nss \
|
|
||||||
freetype \
|
|
||||||
harfbuzz \
|
|
||||||
ca-certificates \
|
|
||||||
ttf-freefont
|
|
||||||
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
COPY package*.json ./
|
|
||||||
|
|
||||||
ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser
|
|
||||||
|
|
||||||
RUN npm install
|
|
||||||
|
|
||||||
COPY . /app
|
|
||||||
|
|
||||||
RUN npm run build
|
|
||||||
|
|
||||||
FROM node:18-alpine AS prod
|
|
||||||
|
|
||||||
RUN apk add --no-cache \
|
|
||||||
chromium \
|
|
||||||
nss \
|
|
||||||
freetype \
|
|
||||||
harfbuzz \
|
|
||||||
ca-certificates \
|
|
||||||
ttf-freefont
|
|
||||||
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
RUN mkdir -p /app/export
|
|
||||||
|
|
||||||
ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser
|
|
||||||
|
|
||||||
COPY --from=build /app/src/templates /app/src/templates
|
|
||||||
COPY --from=build /app/dist /app/dist
|
|
||||||
COPY --from=build /app/node_modules /app/node_modules
|
|
||||||
COPY --from=build /app/package.json /app/package.json
|
|
||||||
|
|
||||||
EXPOSE 5000
|
|
||||||
|
|
||||||
CMD [ "npm", "run", "start" ]
|
|
102
README.md
102
README.md
|
@ -1,92 +1,30 @@
|
||||||
# ff-admin-server
|
# member-administration-server
|
||||||
|
|
||||||
Administration für Feuerwehren und Vereine (Backend).
|
Memberadministration
|
||||||
|
|
||||||
## Einleitung
|
Authentications is realized via JWT-Tokens. The server is able to send Mails to the members.
|
||||||
|
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
|
||||||
|
|
||||||
Das Image exposed nur den Port 5000. Die Env-Variable SERVER_PORT kann nur im lokal ausführenden dev-Kontext verwendet werden.
|
### Requirements
|
||||||
|
|
||||||
### Docker Compose Setup
|
1. MySql Database
|
||||||
|
2. Access to the internet for sending Mails
|
||||||
|
|
||||||
Um den Container hochzufahren, erstellen Sie eine `docker-compose.yml` Datei mit folgendem Inhalt:
|
### Configuration
|
||||||
|
|
||||||
```yaml
|
1. Copy the .env.example file to .env and fill in the required information
|
||||||
version: "3"
|
2. Create a new Database in MySql named as in the .env file
|
||||||
|
3. Install all packages via `npm install`
|
||||||
|
4. Start the application to create the database schema
|
||||||
|
|
||||||
services:
|
## Testing
|
||||||
ff-ff-admin-server:
|
|
||||||
image: docker.registry.jk-effects.cloud/ehrenamt/ff-admin/server:latest
|
|
||||||
container_name: ff_member_administration_server
|
|
||||||
restart: unless-stopped
|
|
||||||
environment:
|
|
||||||
- DB_TYPE=<mysql|sqlite> # default ist auf mysql gesetzt
|
|
||||||
- DB_HOST=ffm-db
|
|
||||||
- DB_PORT=<number> # default ist auf 3306 gesetzt
|
|
||||||
- DB_NAME=ffadmin
|
|
||||||
- DB_USERNAME=administration_backend
|
|
||||||
- DB_PASSWORD=<dbuserpasswd>
|
|
||||||
- JWT_SECRET=<tobemodified>
|
|
||||||
- JWT_EXPIRATION=<number[m|d] - bsp.:15m> # default ist auf 15m gesetzt
|
|
||||||
- REFRESH_EXPIRATION=<number[m|d] - bsp.:1d> # default ist auf 1d gesetzt
|
|
||||||
- PWA_REFRESH_EXPIRATION=<number[m|d] - bsp.:5d> # default ist auf 5d gesetzt
|
|
||||||
- MAIL_USERNAME=<mailadress|username>
|
|
||||||
- MAIL_PASSWORD=<password>
|
|
||||||
- MAIL_HOST=<url>
|
|
||||||
- MAIL_PORT=<port> # default ist auf 578 gesetzt
|
|
||||||
- MAIL_SECURE=<boolean> # default ist auf false gesetzt
|
|
||||||
- CLUB_NAME=<tobemodified> # default ist auf FF Admin gesetzt
|
|
||||||
- CLUB_WEBSITE=<tobemodified>
|
|
||||||
volumes:
|
|
||||||
- <volume|local path>:/app/files
|
|
||||||
networks:
|
|
||||||
- ff_internal
|
|
||||||
depends_on:
|
|
||||||
- ff-db
|
|
||||||
|
|
||||||
ff-db:
|
1. Install the database-system-package you like (e.g. mysql, mariadb, postgresql, sqlite3)
|
||||||
image: mariadb:11.2
|
2. Configure type inside src/data-source.ts to run the database-system you like.
|
||||||
container_name: ff_db
|
3. Set migrationsRun to false and synchronize to true for rapid prototyping
|
||||||
restart: unless-stopped
|
4. Building the schema via CLI:
|
||||||
environment:
|
- Run `npm run update-database` to build the schema using the migrations without starting the application
|
||||||
- MYSQL_DATABASE=ffadmin
|
- Run `npm run synchronize-database` to build the schema without using migrations without starting the application
|
||||||
- MYSQL_USER=administration_backend
|
5. Run `npm run dev` to run inside dev-environment (runs migrations if migrationsRun is set to true)
|
||||||
- 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": "ff-admin-server",
|
"name": "member-administration-server",
|
||||||
"version": "1.2.0",
|
"version": "0.0.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/ff-admin-server.git"
|
"url": "https://forgejo.jk-effects.cloud/Ehrenamt/member-administration-server.git"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"Feuerwehr"
|
"Feuerwehr"
|
||||||
|
@ -27,19 +27,13 @@
|
||||||
"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",
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import { dataSource } from "../../../data-source";
|
import { dataSource } from "../data-source";
|
||||||
import { award } from "../../../entity/settings/award";
|
import { award } from "../entity/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} createAward
|
* @param CreateAwardCommand
|
||||||
* @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} updateAward
|
* @param UpdateAwardCommand
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async update(updateAward: UpdateAwardCommand): Promise<void> {
|
static async update(updateAward: UpdateAwardCommand): Promise<void> {
|
||||||
|
@ -48,22 +48,19 @@ export default abstract class AwardCommandHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description delete award
|
* @description delete award
|
||||||
* @param {DeleteAwardCommand} deleteAward
|
* @param DeleteAwardCommand
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async delete(deleteAward: DeleteAwardCommand): Promise<void> {
|
static async delete(deletAward: DeleteAwardCommand): Promise<void> {
|
||||||
return await dataSource
|
return await dataSource
|
||||||
.createQueryBuilder()
|
.createQueryBuilder()
|
||||||
.delete()
|
.delete()
|
||||||
.from(award)
|
.from(award)
|
||||||
.where("id = :id", { id: deleteAward.id })
|
.where("id = :id", { id: deletAward.id })
|
||||||
.execute()
|
.execute()
|
||||||
.then(() => {})
|
.then(() => {})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
throw new InternalException(
|
throw new InternalException("Failed deleting award", err);
|
||||||
`Failed deleting award ${err.code.includes("ER_ROW_IS_REFERENCED") ? " due to referenced data" : ""}`,
|
|
||||||
err
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,24 +0,0 @@
|
||||||
export interface CreateCalendarCommand {
|
|
||||||
starttime: Date;
|
|
||||||
endtime: Date;
|
|
||||||
title: string;
|
|
||||||
content: string;
|
|
||||||
location: string;
|
|
||||||
allDay: boolean;
|
|
||||||
typeId: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface UpdateCalendarCommand {
|
|
||||||
id: string;
|
|
||||||
starttime: Date;
|
|
||||||
endtime: Date;
|
|
||||||
title: string;
|
|
||||||
content: string;
|
|
||||||
location: string;
|
|
||||||
allDay: boolean;
|
|
||||||
typeId: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface DeleteCalendarCommand {
|
|
||||||
id: string;
|
|
||||||
}
|
|
|
@ -1,96 +0,0 @@
|
||||||
import { dataSource } from "../../../data-source";
|
|
||||||
import { calendar } from "../../../entity/club/calendar";
|
|
||||||
import { calendarType } from "../../../entity/settings/calendarType";
|
|
||||||
import InternalException from "../../../exceptions/internalException";
|
|
||||||
import { CreateCalendarCommand, DeleteCalendarCommand, UpdateCalendarCommand } from "./calendarCommand";
|
|
||||||
|
|
||||||
export default abstract class CalendarCommandHandler {
|
|
||||||
/**
|
|
||||||
* @description create calendar
|
|
||||||
* @param {CreateCalendarCommand} createCalendar
|
|
||||||
* @returns {Promise<number>}
|
|
||||||
*/
|
|
||||||
static async create(createCalendar: CreateCalendarCommand): Promise<number> {
|
|
||||||
return await dataSource
|
|
||||||
.createQueryBuilder()
|
|
||||||
.insert()
|
|
||||||
.into(calendar)
|
|
||||||
.values({
|
|
||||||
starttime: createCalendar.starttime,
|
|
||||||
endtime: createCalendar.endtime,
|
|
||||||
title: createCalendar.title,
|
|
||||||
content: createCalendar.content,
|
|
||||||
location: createCalendar.location,
|
|
||||||
allDay: createCalendar.allDay,
|
|
||||||
type: await dataSource
|
|
||||||
.getRepository(calendarType)
|
|
||||||
.createQueryBuilder("type")
|
|
||||||
.where("id = :id", { id: createCalendar.typeId })
|
|
||||||
.getOneOrFail(),
|
|
||||||
})
|
|
||||||
.execute()
|
|
||||||
.then((result) => {
|
|
||||||
return result.identifiers[0].id;
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
throw new InternalException("Failed creating calendar", err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description update calendar
|
|
||||||
* @param {UpdateCalendarCommand} updateCalendar
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
static async update(updateCalendar: UpdateCalendarCommand): Promise<void> {
|
|
||||||
let sequence = await dataSource
|
|
||||||
.getRepository(calendar)
|
|
||||||
.createQueryBuilder("calendar")
|
|
||||||
.where("id = :id", { id: updateCalendar.id })
|
|
||||||
.getOneOrFail()
|
|
||||||
.then((res) => {
|
|
||||||
return res.sequence;
|
|
||||||
});
|
|
||||||
return await dataSource
|
|
||||||
.createQueryBuilder()
|
|
||||||
.update(calendar)
|
|
||||||
.set({
|
|
||||||
starttime: updateCalendar.starttime,
|
|
||||||
endtime: updateCalendar.endtime,
|
|
||||||
title: updateCalendar.title,
|
|
||||||
content: updateCalendar.content,
|
|
||||||
location: updateCalendar.location,
|
|
||||||
allDay: updateCalendar.allDay,
|
|
||||||
type: await dataSource
|
|
||||||
.getRepository(calendarType)
|
|
||||||
.createQueryBuilder("type")
|
|
||||||
.where("id = :id", { id: updateCalendar.typeId })
|
|
||||||
.getOneOrFail(),
|
|
||||||
sequence: sequence + 1,
|
|
||||||
})
|
|
||||||
.where("id = :id", { id: updateCalendar.id })
|
|
||||||
.execute()
|
|
||||||
.then(() => {})
|
|
||||||
.catch((err) => {
|
|
||||||
throw new InternalException("Failed updating award", err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description delete calendar
|
|
||||||
* @param {DeleteCalendarCommand} deleteCalendar
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
static async delete(deleteCalendar: DeleteCalendarCommand): Promise<void> {
|
|
||||||
return await dataSource
|
|
||||||
.createQueryBuilder()
|
|
||||||
.delete()
|
|
||||||
.from(calendar)
|
|
||||||
.where("id = :id", { id: deleteCalendar.id })
|
|
||||||
.execute()
|
|
||||||
.then(() => {})
|
|
||||||
.catch((err) => {
|
|
||||||
throw new InternalException("Failed deleting calendar", err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,18 +0,0 @@
|
||||||
export interface CreateNewsletterCommand {
|
|
||||||
title: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface SynchronizeNewsletterCommand {
|
|
||||||
id: number;
|
|
||||||
title: string;
|
|
||||||
description: string;
|
|
||||||
newsletterTitle: string;
|
|
||||||
newsletterText: string;
|
|
||||||
newsletterSignatur: string;
|
|
||||||
recipientsByQueryId?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface SendNewsletterCommand {
|
|
||||||
id: number;
|
|
||||||
isSent: boolean;
|
|
||||||
}
|
|
|
@ -1,73 +0,0 @@
|
||||||
import { dataSource } from "../../../data-source";
|
|
||||||
import { newsletter } from "../../../entity/club/newsletter/newsletter";
|
|
||||||
import InternalException from "../../../exceptions/internalException";
|
|
||||||
import { CreateNewsletterCommand, SendNewsletterCommand, SynchronizeNewsletterCommand } from "./newsletterCommand";
|
|
||||||
|
|
||||||
export default abstract class NewsletterCommandHandler {
|
|
||||||
/**
|
|
||||||
* @description create newsletter
|
|
||||||
* @param {CreateNewsletterCommand} createNewsletter
|
|
||||||
* @returns {Promise<number>}
|
|
||||||
*/
|
|
||||||
static async create(createNewsletter: CreateNewsletterCommand): Promise<number> {
|
|
||||||
return await dataSource
|
|
||||||
.createQueryBuilder()
|
|
||||||
.insert()
|
|
||||||
.into(newsletter)
|
|
||||||
.values({
|
|
||||||
title: createNewsletter.title,
|
|
||||||
})
|
|
||||||
.execute()
|
|
||||||
.then((result) => {
|
|
||||||
return result.identifiers[0].id;
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
throw new InternalException("Failed creating newsletter", err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description sync newsletter
|
|
||||||
* @param {SynchronizeNewsletterCommand} syncNewsletter
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
static async sync(syncNewsletter: SynchronizeNewsletterCommand): Promise<void> {
|
|
||||||
return await dataSource
|
|
||||||
.createQueryBuilder()
|
|
||||||
.update(newsletter)
|
|
||||||
.set({
|
|
||||||
title: syncNewsletter.title,
|
|
||||||
description: syncNewsletter.description,
|
|
||||||
newsletterTitle: syncNewsletter.newsletterTitle,
|
|
||||||
newsletterText: syncNewsletter.newsletterText,
|
|
||||||
newsletterSignatur: syncNewsletter.newsletterSignatur,
|
|
||||||
recipientsByQueryId: syncNewsletter.recipientsByQueryId,
|
|
||||||
})
|
|
||||||
.where("id = :id", { id: syncNewsletter.id })
|
|
||||||
.execute()
|
|
||||||
.then(() => {})
|
|
||||||
.catch((err) => {
|
|
||||||
throw new InternalException("Failed synching newsletter", err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description send newsletter
|
|
||||||
* @param {SendNewsletterCommand} syncNewsletter
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
static async send(syncNewsletter: SendNewsletterCommand): Promise<void> {
|
|
||||||
return await dataSource
|
|
||||||
.createQueryBuilder()
|
|
||||||
.update(newsletter)
|
|
||||||
.set({
|
|
||||||
isSent: syncNewsletter.isSent,
|
|
||||||
})
|
|
||||||
.where("id = :id", { id: syncNewsletter.id })
|
|
||||||
.execute()
|
|
||||||
.then(() => {})
|
|
||||||
.catch((err) => {
|
|
||||||
throw new InternalException("Failed setting newsletter send state", err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,10 +0,0 @@
|
||||||
export interface SynchronizeNewsletterDatesCommand {
|
|
||||||
newsletterId: number;
|
|
||||||
dates: Array<NewsletterDateCommand>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface NewsletterDateCommand {
|
|
||||||
calendarId: string;
|
|
||||||
diffTitle?: string;
|
|
||||||
diffDescription?: string;
|
|
||||||
}
|
|
|
@ -1,97 +0,0 @@
|
||||||
import { DeleteResult, EntityManager, InsertResult, UpdateResult } from "typeorm";
|
|
||||||
import { dataSource } from "../../../data-source";
|
|
||||||
import InternalException from "../../../exceptions/internalException";
|
|
||||||
import NewsletterDatesService from "../../../service/club/newsletter/newsletterDatesService";
|
|
||||||
import { NewsletterDateCommand, SynchronizeNewsletterDatesCommand } from "./newsletterDatesCommand";
|
|
||||||
import { newsletterDates } from "../../../entity/club/newsletter/newsletterDates";
|
|
||||||
|
|
||||||
export default abstract class NewsletterDatesCommandHandler {
|
|
||||||
/**
|
|
||||||
* @description sync newsletter dates
|
|
||||||
* @param {SynchronizeNewsletterDatesCommand} syncNewsletterDates
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
static async sync(syncNewsletterDates: SynchronizeNewsletterDatesCommand): Promise<void> {
|
|
||||||
let currentDates = await NewsletterDatesService.getAll(syncNewsletterDates.newsletterId);
|
|
||||||
|
|
||||||
return await dataSource.manager
|
|
||||||
.transaction(async (manager) => {
|
|
||||||
let newDates = syncNewsletterDates.dates.filter(
|
|
||||||
(r) => !currentDates.some((cd) => cd.calendarId == r.calendarId)
|
|
||||||
);
|
|
||||||
let removeDates = currentDates.filter(
|
|
||||||
(r) => !syncNewsletterDates.dates.some((cd) => cd.calendarId == r.calendarId)
|
|
||||||
);
|
|
||||||
let keptDates = syncNewsletterDates.dates.filter(
|
|
||||||
(r) =>
|
|
||||||
currentDates.some((cd) => cd.calendarId == r.calendarId) &&
|
|
||||||
!removeDates.some((cd) => cd.calendarId == r.calendarId)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (newDates.length != 0) {
|
|
||||||
await this.syncPresenceAdd(manager, syncNewsletterDates.newsletterId, newDates);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (removeDates.length != 0) {
|
|
||||||
await this.syncPresenceRemove(manager, syncNewsletterDates.newsletterId, removeDates);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const date of keptDates) {
|
|
||||||
await this.syncPresenceUpdate(manager, syncNewsletterDates.newsletterId, date);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.then(() => {})
|
|
||||||
.catch((err) => {
|
|
||||||
throw new InternalException("Failed syncing newsletter dates", err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private static async syncPresenceAdd(
|
|
||||||
manager: EntityManager,
|
|
||||||
newsletterId: number,
|
|
||||||
dates: Array<NewsletterDateCommand>
|
|
||||||
): Promise<InsertResult> {
|
|
||||||
return await manager
|
|
||||||
.createQueryBuilder()
|
|
||||||
.insert()
|
|
||||||
.into(newsletterDates)
|
|
||||||
.values(
|
|
||||||
dates.map((d) => ({
|
|
||||||
...d,
|
|
||||||
newsletterId: newsletterId,
|
|
||||||
}))
|
|
||||||
)
|
|
||||||
.execute();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static async syncPresenceUpdate(
|
|
||||||
manager: EntityManager,
|
|
||||||
newsletterId: number,
|
|
||||||
date: NewsletterDateCommand
|
|
||||||
): Promise<UpdateResult> {
|
|
||||||
return await manager
|
|
||||||
.createQueryBuilder()
|
|
||||||
.update(newsletterDates)
|
|
||||||
.set({
|
|
||||||
diffTitle: date.diffTitle,
|
|
||||||
diffDescription: date.diffDescription,
|
|
||||||
})
|
|
||||||
.where("calendarId = :calendarId", { calendarId: date.calendarId })
|
|
||||||
.andWhere("newsletterId = :newsletterId", { newsletterId })
|
|
||||||
.execute();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static async syncPresenceRemove(
|
|
||||||
manager: EntityManager,
|
|
||||||
newsletterId: number,
|
|
||||||
dates: Array<NewsletterDateCommand>
|
|
||||||
): Promise<DeleteResult> {
|
|
||||||
return await manager
|
|
||||||
.createQueryBuilder()
|
|
||||||
.delete()
|
|
||||||
.from(newsletterDates)
|
|
||||||
.where("calendarId IN (:...ids)", { ids: dates.map((d) => d.calendarId) })
|
|
||||||
.andWhere("newsletterId = :newsletterId", { newsletterId })
|
|
||||||
.execute();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,4 +0,0 @@
|
||||||
export interface SynchronizeNewsletterRecipientsCommand {
|
|
||||||
newsletterId: number;
|
|
||||||
recipients: Array<number>;
|
|
||||||
}
|
|
|
@ -1,73 +0,0 @@
|
||||||
import { DeleteResult, EntityManager, InsertResult, UpdateResult } from "typeorm";
|
|
||||||
import { dataSource } from "../../../data-source";
|
|
||||||
import InternalException from "../../../exceptions/internalException";
|
|
||||||
import NewsletterRecipientsService from "../../../service/club/newsletter/newsletterRecipientsService";
|
|
||||||
import { SynchronizeNewsletterRecipientsCommand } from "./newsletterRecipientsCommand";
|
|
||||||
import { newsletterRecipients } from "../../../entity/club/newsletter/newsletterRecipients";
|
|
||||||
|
|
||||||
export default abstract class NewsletterRecipientsCommandHandler {
|
|
||||||
/**
|
|
||||||
* @description sync newsletterRecipients
|
|
||||||
* @param {SynchronizeNewsletterRecipientsCommand} syncNewsletterRecipients
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
static async sync(syncNewsletterRecipients: SynchronizeNewsletterRecipientsCommand): Promise<void> {
|
|
||||||
let currentRecipients = (await NewsletterRecipientsService.getAll(syncNewsletterRecipients.newsletterId)).map(
|
|
||||||
(r) => r.memberId
|
|
||||||
);
|
|
||||||
|
|
||||||
return await dataSource.manager
|
|
||||||
.transaction(async (manager) => {
|
|
||||||
let newRecipients = syncNewsletterRecipients.recipients.filter(
|
|
||||||
(r) => !currentRecipients.map((np) => np).includes(r)
|
|
||||||
);
|
|
||||||
let removeRecipients = currentRecipients.filter(
|
|
||||||
(r) => !syncNewsletterRecipients.recipients.map((np) => np).includes(r)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (newRecipients.length != 0) {
|
|
||||||
await this.syncPresenceAdd(manager, syncNewsletterRecipients.newsletterId, newRecipients);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (removeRecipients.length != 0) {
|
|
||||||
await this.syncPresenceRemove(manager, syncNewsletterRecipients.newsletterId, removeRecipients);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.then(() => {})
|
|
||||||
.catch((err) => {
|
|
||||||
throw new InternalException("Failed syncing newsletter recipients", err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private static async syncPresenceAdd(
|
|
||||||
manager: EntityManager,
|
|
||||||
newsletterId: number,
|
|
||||||
recipients: Array<number>
|
|
||||||
): Promise<InsertResult> {
|
|
||||||
return await manager
|
|
||||||
.createQueryBuilder()
|
|
||||||
.insert()
|
|
||||||
.into(newsletterRecipients)
|
|
||||||
.values(
|
|
||||||
recipients.map((r) => ({
|
|
||||||
memberId: r,
|
|
||||||
newsletterId: newsletterId,
|
|
||||||
}))
|
|
||||||
)
|
|
||||||
.execute();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static async syncPresenceRemove(
|
|
||||||
manager: EntityManager,
|
|
||||||
newsletterId: number,
|
|
||||||
recipients: Array<number>
|
|
||||||
): Promise<DeleteResult> {
|
|
||||||
return await manager
|
|
||||||
.createQueryBuilder()
|
|
||||||
.delete()
|
|
||||||
.from(newsletterRecipients)
|
|
||||||
.where("memberId IN (:...ids)", { ids: recipients })
|
|
||||||
.andWhere("newsletterId = :newsletterId", { newsletterId })
|
|
||||||
.execute();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,6 +0,0 @@
|
||||||
export interface SynchronizeProtocolAgendaCommand {
|
|
||||||
id?: number;
|
|
||||||
topic: string;
|
|
||||||
context: string;
|
|
||||||
protocolId: number;
|
|
||||||
}
|
|
|
@ -1,49 +0,0 @@
|
||||||
import { dataSource } from "../../../data-source";
|
|
||||||
import { protocolAgenda } from "../../../entity/club/protocol/protocolAgenda";
|
|
||||||
import InternalException from "../../../exceptions/internalException";
|
|
||||||
import { SynchronizeProtocolAgendaCommand } from "./protocolAgendaCommand";
|
|
||||||
|
|
||||||
export default abstract class ProtocolAgendaCommandHandler {
|
|
||||||
/**
|
|
||||||
* @description create protocolAgenda
|
|
||||||
* @param {number} protocolId
|
|
||||||
* @returns {Promise<number>}
|
|
||||||
*/
|
|
||||||
static async create(protocolId: number): Promise<number> {
|
|
||||||
return await dataSource
|
|
||||||
.createQueryBuilder()
|
|
||||||
.insert()
|
|
||||||
.into(protocolAgenda)
|
|
||||||
.values({
|
|
||||||
topic: "",
|
|
||||||
context: "",
|
|
||||||
protocolId,
|
|
||||||
})
|
|
||||||
.execute()
|
|
||||||
.then((result) => {
|
|
||||||
return result.identifiers[0].id;
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
throw new InternalException("Failed creating protocol", err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description sync protocolAgenda
|
|
||||||
* @param {Array<SynchronizeProtocolAgendaCommand>} syncProtocolAgenda
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
static async sync(syncProtocolAgenda: Array<SynchronizeProtocolAgendaCommand>): Promise<void> {
|
|
||||||
return await dataSource
|
|
||||||
.createQueryBuilder()
|
|
||||||
.insert()
|
|
||||||
.into(protocolAgenda)
|
|
||||||
.values(syncProtocolAgenda)
|
|
||||||
.orUpdate(["topic", "context"], ["id"])
|
|
||||||
.execute()
|
|
||||||
.then(() => {})
|
|
||||||
.catch((err) => {
|
|
||||||
throw new InternalException("Failed creating protocol", err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,13 +0,0 @@
|
||||||
export interface CreateProtocolCommand {
|
|
||||||
title: string;
|
|
||||||
date: Date;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface SynchronizeProtocolCommand {
|
|
||||||
id: number;
|
|
||||||
title: string;
|
|
||||||
date: Date;
|
|
||||||
starttime: Date;
|
|
||||||
endtime: Date;
|
|
||||||
summary: string;
|
|
||||||
}
|
|
|
@ -1,53 +0,0 @@
|
||||||
import { dataSource } from "../../../data-source";
|
|
||||||
import { protocol } from "../../../entity/club/protocol/protocol";
|
|
||||||
import InternalException from "../../../exceptions/internalException";
|
|
||||||
import { CreateProtocolCommand, SynchronizeProtocolCommand } from "./protocolCommand";
|
|
||||||
|
|
||||||
export default abstract class ProtocolCommandHandler {
|
|
||||||
/**
|
|
||||||
* @description create protocol
|
|
||||||
* @param {CreateProtocolCommand} createProtocol
|
|
||||||
* @returns {Promise<number>}
|
|
||||||
*/
|
|
||||||
static async create(createProtocol: CreateProtocolCommand): Promise<number> {
|
|
||||||
return await dataSource
|
|
||||||
.createQueryBuilder()
|
|
||||||
.insert()
|
|
||||||
.into(protocol)
|
|
||||||
.values({
|
|
||||||
title: createProtocol.title,
|
|
||||||
date: createProtocol.date,
|
|
||||||
})
|
|
||||||
.execute()
|
|
||||||
.then((result) => {
|
|
||||||
return result.identifiers[0].id;
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
throw new InternalException("Failed creating protocol", err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description sync protocol
|
|
||||||
* @param {SynchronizeProtocolCommand} syncProtocol
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
static async sync(syncProtocol: SynchronizeProtocolCommand): Promise<void> {
|
|
||||||
return await dataSource
|
|
||||||
.createQueryBuilder()
|
|
||||||
.update(protocol)
|
|
||||||
.set({
|
|
||||||
title: syncProtocol.title,
|
|
||||||
date: syncProtocol.date,
|
|
||||||
starttime: syncProtocol.starttime,
|
|
||||||
endtime: syncProtocol.endtime,
|
|
||||||
summary: syncProtocol.summary,
|
|
||||||
})
|
|
||||||
.where("id = :id", { id: syncProtocol.id })
|
|
||||||
.execute()
|
|
||||||
.then(() => {})
|
|
||||||
.catch((err) => {
|
|
||||||
throw new InternalException("Failed creating protocol", err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,6 +0,0 @@
|
||||||
export interface SynchronizeProtocolDecisionCommand {
|
|
||||||
id?: number;
|
|
||||||
topic: string;
|
|
||||||
context: string;
|
|
||||||
protocolId: number;
|
|
||||||
}
|
|
|
@ -1,48 +0,0 @@
|
||||||
import { dataSource } from "../../../data-source";
|
|
||||||
import { protocolDecision } from "../../../entity/club/protocol/protocolDecision";
|
|
||||||
import InternalException from "../../../exceptions/internalException";
|
|
||||||
import { SynchronizeProtocolDecisionCommand } from "./protocolDecisionCommand";
|
|
||||||
|
|
||||||
export default abstract class ProtocolDecisionCommandHandler {
|
|
||||||
/**
|
|
||||||
* @description create protocolDecision
|
|
||||||
* @param {number} protocolId
|
|
||||||
* @returns {Promise<number>}
|
|
||||||
*/
|
|
||||||
static async create(protocolId: number): Promise<number> {
|
|
||||||
return await dataSource
|
|
||||||
.createQueryBuilder()
|
|
||||||
.insert()
|
|
||||||
.into(protocolDecision)
|
|
||||||
.values({
|
|
||||||
topic: "",
|
|
||||||
context: "",
|
|
||||||
protocolId,
|
|
||||||
})
|
|
||||||
.execute()
|
|
||||||
.then((result) => {
|
|
||||||
return result.identifiers[0].id;
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
throw new InternalException("Failed creating protocol", err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @description sync protocolDecision
|
|
||||||
* @param {Array<SynchronizeProtocolDecisionCommand>} syncProtocolDecisions
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
static async sync(syncProtocolDecisions: Array<SynchronizeProtocolDecisionCommand>): Promise<void> {
|
|
||||||
return await dataSource
|
|
||||||
.createQueryBuilder()
|
|
||||||
.insert()
|
|
||||||
.into(protocolDecision)
|
|
||||||
.values(syncProtocolDecisions)
|
|
||||||
.orUpdate(["topic", "context"], ["id"])
|
|
||||||
.execute()
|
|
||||||
.then(() => {})
|
|
||||||
.catch((err) => {
|
|
||||||
throw new InternalException("Failed creating protocol", err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,10 +0,0 @@
|
||||||
export interface SynchronizeProtocolPresenceCommand {
|
|
||||||
members: Array<ProtocolPresenceCommand>;
|
|
||||||
protocolId: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ProtocolPresenceCommand {
|
|
||||||
memberId: number;
|
|
||||||
absent: boolean;
|
|
||||||
excused: boolean;
|
|
||||||
}
|
|
|
@ -1,97 +0,0 @@
|
||||||
import { DeleteResult, EntityManager, InsertResult, UpdateResult } from "typeorm";
|
|
||||||
import { dataSource } from "../../../data-source";
|
|
||||||
import { protocolPresence } from "../../../entity/club/protocol/protocolPresence";
|
|
||||||
import InternalException from "../../../exceptions/internalException";
|
|
||||||
import ProtocolPresenceService from "../../../service/club/protocol/protocolPrecenseService";
|
|
||||||
import { ProtocolPresenceCommand, SynchronizeProtocolPresenceCommand } from "./protocolPresenceCommand";
|
|
||||||
|
|
||||||
export default abstract class ProtocolPresenceCommandHandler {
|
|
||||||
/**
|
|
||||||
* @description sync protocolPresence
|
|
||||||
* @param {SynchronizeProtocolPresenceCommand} syncProtocolPresences
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
static async sync(syncProtocolPresences: SynchronizeProtocolPresenceCommand): Promise<void> {
|
|
||||||
let currentPresence = await ProtocolPresenceService.getAll(syncProtocolPresences.protocolId);
|
|
||||||
|
|
||||||
return await dataSource.manager
|
|
||||||
.transaction(async (manager) => {
|
|
||||||
let newMembers = syncProtocolPresences.members.filter(
|
|
||||||
(r) => !currentPresence.some((cp) => cp.memberId == r.memberId)
|
|
||||||
);
|
|
||||||
let removeMembers = currentPresence.filter(
|
|
||||||
(r) => !syncProtocolPresences.members.some((cp) => cp.memberId == r.memberId)
|
|
||||||
);
|
|
||||||
let keptMembers = syncProtocolPresences.members.filter(
|
|
||||||
(m) =>
|
|
||||||
currentPresence.some((cd) => cd.memberId == m.memberId) &&
|
|
||||||
!removeMembers.some((cd) => cd.memberId == m.memberId)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (newMembers.length != 0) {
|
|
||||||
await this.syncPresenceAdd(manager, syncProtocolPresences.protocolId, newMembers);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (removeMembers.length != 0) {
|
|
||||||
await this.syncPresenceRemove(manager, syncProtocolPresences.protocolId, removeMembers);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const member of keptMembers) {
|
|
||||||
await this.syncPresenceUpdate(manager, syncProtocolPresences.protocolId, member);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.then(() => {})
|
|
||||||
.catch((err) => {
|
|
||||||
throw new InternalException("Failed saving protocol presence", err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private static async syncPresenceAdd(
|
|
||||||
manager: EntityManager,
|
|
||||||
protocolId: number,
|
|
||||||
memberIds: Array<ProtocolPresenceCommand>
|
|
||||||
): Promise<InsertResult> {
|
|
||||||
return await manager
|
|
||||||
.createQueryBuilder()
|
|
||||||
.insert()
|
|
||||||
.into(protocolPresence)
|
|
||||||
.values(
|
|
||||||
memberIds.map((m) => ({
|
|
||||||
...m,
|
|
||||||
protocolId,
|
|
||||||
}))
|
|
||||||
)
|
|
||||||
.execute();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static async syncPresenceUpdate(
|
|
||||||
manager: EntityManager,
|
|
||||||
protocolId: number,
|
|
||||||
member: ProtocolPresenceCommand
|
|
||||||
): Promise<UpdateResult> {
|
|
||||||
return await manager
|
|
||||||
.createQueryBuilder()
|
|
||||||
.update(protocolPresence)
|
|
||||||
.set({
|
|
||||||
absent: member.absent,
|
|
||||||
excused: member.excused,
|
|
||||||
})
|
|
||||||
.where("memberId = :memberId", { memberId: member.memberId })
|
|
||||||
.andWhere("protocolId = :protocolId", { protocolId })
|
|
||||||
.execute();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static async syncPresenceRemove(
|
|
||||||
manager: EntityManager,
|
|
||||||
protocolId: number,
|
|
||||||
members: Array<ProtocolPresenceCommand>
|
|
||||||
): Promise<DeleteResult> {
|
|
||||||
return await manager
|
|
||||||
.createQueryBuilder()
|
|
||||||
.delete()
|
|
||||||
.from(protocolPresence)
|
|
||||||
.where("memberId IN (:...ids)", { ids: members.map((m) => m.memberId) })
|
|
||||||
.andWhere("protocolId = :protocolId", { protocolId })
|
|
||||||
.execute();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,6 +0,0 @@
|
||||||
export interface CreateProtocolPrintoutCommand {
|
|
||||||
title: string;
|
|
||||||
iteration: number;
|
|
||||||
filename: string;
|
|
||||||
protocolId: number;
|
|
||||||
}
|
|
|
@ -1,31 +0,0 @@
|
||||||
import { dataSource } from "../../../data-source";
|
|
||||||
import { protocolPrintout } from "../../../entity/club/protocol/protocolPrintout";
|
|
||||||
import InternalException from "../../../exceptions/internalException";
|
|
||||||
import { CreateProtocolPrintoutCommand } from "./protocolPrintoutCommand";
|
|
||||||
|
|
||||||
export default abstract class ProtocolPrintoutCommandHandler {
|
|
||||||
/**
|
|
||||||
* @description create protocolPrintout
|
|
||||||
* @param {CreateProtocolPrintoutCommand} printout
|
|
||||||
* @returns {Promise<number>}
|
|
||||||
*/
|
|
||||||
static async create(printout: CreateProtocolPrintoutCommand): Promise<number> {
|
|
||||||
return await dataSource
|
|
||||||
.createQueryBuilder()
|
|
||||||
.insert()
|
|
||||||
.into(protocolPrintout)
|
|
||||||
.values({
|
|
||||||
title: printout.title,
|
|
||||||
iteration: printout.iteration,
|
|
||||||
filename: printout.filename,
|
|
||||||
protocolId: printout.protocolId,
|
|
||||||
})
|
|
||||||
.execute()
|
|
||||||
.then((result) => {
|
|
||||||
return result.identifiers[0].id;
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
throw new InternalException("Failed creating protocol", err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,9 +0,0 @@
|
||||||
export interface SynchronizeProtocolVotingCommand {
|
|
||||||
id: number;
|
|
||||||
topic: string;
|
|
||||||
context: string;
|
|
||||||
favour: number;
|
|
||||||
abstain: number;
|
|
||||||
against: number;
|
|
||||||
protocolId: number;
|
|
||||||
}
|
|
|
@ -1,48 +0,0 @@
|
||||||
import { dataSource } from "../../../data-source";
|
|
||||||
import { protocolVoting } from "../../../entity/club/protocol/protocolVoting";
|
|
||||||
import InternalException from "../../../exceptions/internalException";
|
|
||||||
import { SynchronizeProtocolVotingCommand } from "./protocolVotingCommand";
|
|
||||||
|
|
||||||
export default abstract class ProtocolVotingCommandHandler {
|
|
||||||
/**
|
|
||||||
* @description create protocolVoting
|
|
||||||
* @param {number} protocolId
|
|
||||||
* @returns {Promise<number>}
|
|
||||||
*/
|
|
||||||
static async create(protocolId: number): Promise<number> {
|
|
||||||
return await dataSource
|
|
||||||
.createQueryBuilder()
|
|
||||||
.insert()
|
|
||||||
.into(protocolVoting)
|
|
||||||
.values({
|
|
||||||
topic: "",
|
|
||||||
context: "",
|
|
||||||
protocolId,
|
|
||||||
})
|
|
||||||
.execute()
|
|
||||||
.then((result) => {
|
|
||||||
return result.identifiers[0].id;
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
throw new InternalException("Failed creating protocol", err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @description sync protocolVoting
|
|
||||||
* @param {Array<SynchronizeProtocolVotingCommand>} syncProtocolVotings
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
static async sync(syncProtocolVotings: Array<SynchronizeProtocolVotingCommand>): Promise<void> {
|
|
||||||
return await dataSource
|
|
||||||
.createQueryBuilder()
|
|
||||||
.insert()
|
|
||||||
.into(protocolVoting)
|
|
||||||
.values(syncProtocolVotings)
|
|
||||||
.orUpdate(["topic", "context", "favour", "abstain", "against"], ["id"])
|
|
||||||
.execute()
|
|
||||||
.then(() => {})
|
|
||||||
.catch((err) => {
|
|
||||||
throw new InternalException("Failed creating protocol", err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,9 +1,7 @@
|
||||||
export interface CreateCommunicationCommand {
|
export interface CreateCommunicationCommand {
|
||||||
preferred: boolean;
|
preferred: boolean;
|
||||||
isSMSAlarming: boolean;
|
|
||||||
mobile: string;
|
mobile: string;
|
||||||
email: string;
|
email: string;
|
||||||
postalCode: string;
|
|
||||||
city: string;
|
city: string;
|
||||||
street: string;
|
street: string;
|
||||||
streetNumber: number;
|
streetNumber: number;
|
||||||
|
@ -15,10 +13,8 @@ export interface CreateCommunicationCommand {
|
||||||
export interface UpdateCommunicationCommand {
|
export interface UpdateCommunicationCommand {
|
||||||
id: number;
|
id: number;
|
||||||
preferred: boolean;
|
preferred: boolean;
|
||||||
isSMSAlarming: boolean;
|
|
||||||
mobile: string;
|
mobile: string;
|
||||||
email: string;
|
email: string;
|
||||||
postalCode: string;
|
|
||||||
city: string;
|
city: string;
|
||||||
street: string;
|
street: string;
|
||||||
streetNumber: number;
|
streetNumber: number;
|
|
@ -1,6 +1,8 @@
|
||||||
import { dataSource } from "../../../data-source";
|
import { dataSource } from "../data-source";
|
||||||
import { communication } from "../../../entity/club/member/communication";
|
import { communication } from "../entity/communication";
|
||||||
import InternalException from "../../../exceptions/internalException";
|
import { communicationType } from "../entity/communicationType";
|
||||||
|
import { user } from "../entity/user";
|
||||||
|
import InternalException from "../exceptions/internalException";
|
||||||
import {
|
import {
|
||||||
CreateCommunicationCommand,
|
CreateCommunicationCommand,
|
||||||
DeleteCommunicationCommand,
|
DeleteCommunicationCommand,
|
||||||
|
@ -10,7 +12,7 @@ import {
|
||||||
export default abstract class CommunicationCommandHandler {
|
export default abstract class CommunicationCommandHandler {
|
||||||
/**
|
/**
|
||||||
* @description create communication
|
* @description create communication
|
||||||
* @param {CreateCommunicationCommand} createCommunication
|
* @param CreateCommunicationCommand
|
||||||
* @returns {Promise<number>}
|
* @returns {Promise<number>}
|
||||||
*/
|
*/
|
||||||
static async create(createCommunication: CreateCommunicationCommand): Promise<number> {
|
static async create(createCommunication: CreateCommunicationCommand): Promise<number> {
|
||||||
|
@ -20,16 +22,22 @@ export default abstract class CommunicationCommandHandler {
|
||||||
.into(communication)
|
.into(communication)
|
||||||
.values({
|
.values({
|
||||||
preferred: createCommunication.preferred,
|
preferred: createCommunication.preferred,
|
||||||
isSMSAlarming: createCommunication.isSMSAlarming,
|
|
||||||
mobile: createCommunication.mobile,
|
mobile: createCommunication.mobile,
|
||||||
email: createCommunication.email,
|
email: createCommunication.email,
|
||||||
postalCode: createCommunication.postalCode,
|
|
||||||
city: createCommunication.city,
|
city: createCommunication.city,
|
||||||
street: createCommunication.street,
|
street: createCommunication.street,
|
||||||
streetNumber: createCommunication.streetNumber,
|
streetNumber: createCommunication.streetNumber,
|
||||||
streetNumberAddition: createCommunication.streetNumberAddition,
|
streetNumberAddition: createCommunication.streetNumberAddition,
|
||||||
memberId: createCommunication.memberId,
|
member: await dataSource
|
||||||
typeId: createCommunication.typeId,
|
.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()
|
.execute()
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
|
@ -42,7 +50,7 @@ export default abstract class CommunicationCommandHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description update communication
|
* @description update communication
|
||||||
* @param {UpdateCommunicationCommand} updateCommunication
|
* @param UpdateCommunicationCommand
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async update(updateCommunication: UpdateCommunicationCommand): Promise<void> {
|
static async update(updateCommunication: UpdateCommunicationCommand): Promise<void> {
|
||||||
|
@ -51,10 +59,8 @@ export default abstract class CommunicationCommandHandler {
|
||||||
.update(communication)
|
.update(communication)
|
||||||
.set({
|
.set({
|
||||||
preferred: updateCommunication.preferred,
|
preferred: updateCommunication.preferred,
|
||||||
isSMSAlarming: updateCommunication.isSMSAlarming,
|
|
||||||
mobile: updateCommunication.mobile,
|
mobile: updateCommunication.mobile,
|
||||||
email: updateCommunication.email,
|
email: updateCommunication.email,
|
||||||
postalCode: updateCommunication.postalCode,
|
|
||||||
city: updateCommunication.city,
|
city: updateCommunication.city,
|
||||||
street: updateCommunication.street,
|
street: updateCommunication.street,
|
||||||
streetNumber: updateCommunication.streetNumber,
|
streetNumber: updateCommunication.streetNumber,
|
||||||
|
@ -71,16 +77,16 @@ export default abstract class CommunicationCommandHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description delete communication
|
* @description delete communication
|
||||||
* @param {DeleteCommunicationCommand} deleteCommunication
|
* @param DeleteCommunicationCommand
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async delete(deleteCommunication: DeleteCommunicationCommand): Promise<void> {
|
static async delete(deletCommunication: DeleteCommunicationCommand): Promise<void> {
|
||||||
return await dataSource
|
return await dataSource
|
||||||
.createQueryBuilder()
|
.createQueryBuilder()
|
||||||
.delete()
|
.delete()
|
||||||
.from(communication)
|
.from(communication)
|
||||||
.where("id = :id", { id: deleteCommunication.id })
|
.where("id = :id", { id: deletCommunication.id })
|
||||||
.andWhere("memberId = :memberId", { memberId: deleteCommunication.memberId })
|
.andWhere("memberId = :memberId", { memberId: deletCommunication.memberId })
|
||||||
.execute()
|
.execute()
|
||||||
.then(() => {})
|
.then(() => {})
|
||||||
.catch((err) => {
|
.catch((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/settings/communicationType";
|
import { communicationType } from "../entity/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} createCommunicationType
|
* @param CreateCommunicationTypeCommand
|
||||||
* @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} updateCommunicationType
|
* @param UpdateCommunicationTypeCommand
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async update(updateCommunicationType: UpdateCommunicationTypeCommand): Promise<void> {
|
static async update(updateCommunicationType: UpdateCommunicationTypeCommand): Promise<void> {
|
||||||
|
@ -54,24 +54,19 @@ export default abstract class CommunicationTypeCommandHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description delete communicationType
|
* @description delete communicationType
|
||||||
* @param {DeleteCommunicationTypeCommand} deleteCommunicationType
|
* @param DeleteCommunicationTypeCommand
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async delete(deleteCommunicationType: DeleteCommunicationTypeCommand): Promise<void> {
|
static async delete(deletCommunicationType: DeleteCommunicationTypeCommand): Promise<void> {
|
||||||
return await dataSource
|
return await dataSource
|
||||||
.createQueryBuilder()
|
.createQueryBuilder()
|
||||||
.delete()
|
.delete()
|
||||||
.from(communicationType)
|
.from(communicationType)
|
||||||
.where("id = :id", { id: deleteCommunicationType.id })
|
.where("id = :id", { id: deletCommunicationType.id })
|
||||||
.execute()
|
.execute()
|
||||||
.then(() => {})
|
.then(() => {})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
throw new InternalException(
|
throw new InternalException("Failed deleting communicationType", err);
|
||||||
`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/settings/executivePosition";
|
import { executivePosition } from "../entity/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} createExecutivePosition
|
* @param CreateExecutivePositionCommand
|
||||||
* @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} updateExecutivePosition
|
* @param UpdateExecutivePositionCommand
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async update(updateExecutivePosition: UpdateExecutivePositionCommand): Promise<void> {
|
static async update(updateExecutivePosition: UpdateExecutivePositionCommand): Promise<void> {
|
||||||
|
@ -52,24 +52,19 @@ export default abstract class ExecutivePositionCommandHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description delete executivePosition
|
* @description delete executivePosition
|
||||||
* @param {DeleteExecutivePositionCommand} deleteExecutivePosition
|
* @param DeleteExecutivePositionCommand
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async delete(deleteExecutivePosition: DeleteExecutivePositionCommand): Promise<void> {
|
static async delete(deletExecutivePosition: DeleteExecutivePositionCommand): Promise<void> {
|
||||||
return await dataSource
|
return await dataSource
|
||||||
.createQueryBuilder()
|
.createQueryBuilder()
|
||||||
.delete()
|
.delete()
|
||||||
.from(executivePosition)
|
.from(executivePosition)
|
||||||
.where("id = :id", { id: deleteExecutivePosition.id })
|
.where("id = :id", { id: deletExecutivePosition.id })
|
||||||
.execute()
|
.execute()
|
||||||
.then(() => {})
|
.then(() => {})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
throw new InternalException(
|
throw new InternalException("Failed deleting executivePosition", err);
|
||||||
`Failed deleting executivePosition${
|
|
||||||
err.code.includes("ER_ROW_IS_REFERENCED") ? " due to referenced data" : ""
|
|
||||||
}`,
|
|
||||||
err
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
import { dataSource } from "../../../data-source";
|
import { dataSource } from "../data-source";
|
||||||
import { invite } from "../../../entity/user/invite";
|
import { invite } from "../entity/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 DeleteInviteCommand
|
* @param DeleteRefreshCommand
|
||||||
* @returns {Promise<any>}
|
* @returns {Promise<any>}
|
||||||
*/
|
*/
|
||||||
static async deleteByTokenAndMail(deleteInvite: DeleteInviteCommand): Promise<any> {
|
static async deleteByTokenAndMail(deleteInvite: DeleteInviteCommand): Promise<any> {
|
||||||
|
@ -53,22 +53,4 @@ export default abstract class InviteCommandHandler {
|
||||||
throw new InternalException("failed invite removal", err);
|
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);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -1,12 +1,14 @@
|
||||||
import { dataSource } from "../../../data-source";
|
import { dataSource } from "../data-source";
|
||||||
import { memberAwards } from "../../../entity/club/member/memberAwards";
|
import { award } from "../entity/award";
|
||||||
import InternalException from "../../../exceptions/internalException";
|
import { memberAwards } from "../entity/memberAwards";
|
||||||
|
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} createMemberAward
|
* @param CreateMemberAwardCommand
|
||||||
* @returns {Promise<number>}
|
* @returns {Promise<number>}
|
||||||
*/
|
*/
|
||||||
static async create(createMemberAward: CreateMemberAwardCommand): Promise<number> {
|
static async create(createMemberAward: CreateMemberAwardCommand): Promise<number> {
|
||||||
|
@ -18,8 +20,16 @@ export default abstract class MemberAwardCommandHandler {
|
||||||
given: createMemberAward.given,
|
given: createMemberAward.given,
|
||||||
note: createMemberAward.note,
|
note: createMemberAward.note,
|
||||||
date: createMemberAward.date,
|
date: createMemberAward.date,
|
||||||
memberId: createMemberAward.memberId,
|
member: await dataSource
|
||||||
awardId: createMemberAward.awardId,
|
.getRepository(user)
|
||||||
|
.createQueryBuilder("user")
|
||||||
|
.where("id = :id", { id: createMemberAward.memberId })
|
||||||
|
.getOneOrFail(),
|
||||||
|
award: await dataSource
|
||||||
|
.getRepository(award)
|
||||||
|
.createQueryBuilder("award")
|
||||||
|
.where("id = :id", { id: createMemberAward.awardId })
|
||||||
|
.getOneOrFail(),
|
||||||
})
|
})
|
||||||
.execute()
|
.execute()
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
|
@ -32,7 +42,7 @@ export default abstract class MemberAwardCommandHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description update memberAward
|
* @description update memberAward
|
||||||
* @param {UpdateMemberAwardCommand} updateMemberAward
|
* @param UpdateMemberAwardCommand
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async update(updateMemberAward: UpdateMemberAwardCommand): Promise<void> {
|
static async update(updateMemberAward: UpdateMemberAwardCommand): Promise<void> {
|
||||||
|
@ -43,7 +53,11 @@ export default abstract class MemberAwardCommandHandler {
|
||||||
given: updateMemberAward.given,
|
given: updateMemberAward.given,
|
||||||
note: updateMemberAward.note,
|
note: updateMemberAward.note,
|
||||||
date: updateMemberAward.date,
|
date: updateMemberAward.date,
|
||||||
award: updateMemberAward.awardId,
|
award: await dataSource
|
||||||
|
.getRepository(award)
|
||||||
|
.createQueryBuilder("award")
|
||||||
|
.where("id = :id", { id: updateMemberAward.awardId })
|
||||||
|
.getOneOrFail(),
|
||||||
})
|
})
|
||||||
.where("id = :id", { id: updateMemberAward.id })
|
.where("id = :id", { id: updateMemberAward.id })
|
||||||
.andWhere("memberId = :memberId", { memberId: updateMemberAward.memberId })
|
.andWhere("memberId = :memberId", { memberId: updateMemberAward.memberId })
|
||||||
|
@ -56,16 +70,16 @@ export default abstract class MemberAwardCommandHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description delete memberAward
|
* @description delete memberAward
|
||||||
* @param {DeleteMemberAwardCommand} deleteMemberAward
|
* @param DeleteMemberAwardCommand
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async delete(deleteMemberAward: DeleteMemberAwardCommand): Promise<void> {
|
static async delete(deletMemberAward: DeleteMemberAwardCommand): Promise<void> {
|
||||||
return await dataSource
|
return await dataSource
|
||||||
.createQueryBuilder()
|
.createQueryBuilder()
|
||||||
.delete()
|
.delete()
|
||||||
.from(memberAwards)
|
.from(memberAwards)
|
||||||
.where("id = :id", { id: deleteMemberAward.id })
|
.where("id = :id", { id: deletMemberAward.id })
|
||||||
.andWhere("memberId = :memberId", { memberId: deleteMemberAward.memberId })
|
.andWhere("memberId = :memberId", { memberId: deletMemberAward.memberId })
|
||||||
.execute()
|
.execute()
|
||||||
.then(() => {})
|
.then(() => {})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
|
@ -1,4 +1,4 @@
|
||||||
import { Salutation } from "../../../enums/salutation";
|
import { Salutation } from "../enums/salutation";
|
||||||
|
|
||||||
export interface CreateMemberCommand {
|
export interface CreateMemberCommand {
|
||||||
salutation: Salutation;
|
salutation: Salutation;
|
||||||
|
@ -6,7 +6,6 @@ export interface CreateMemberCommand {
|
||||||
lastname: string;
|
lastname: string;
|
||||||
nameaffix: string;
|
nameaffix: string;
|
||||||
birthdate: Date;
|
birthdate: Date;
|
||||||
internalId?: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UpdateMemberCommand {
|
export interface UpdateMemberCommand {
|
||||||
|
@ -16,7 +15,6 @@ export interface UpdateMemberCommand {
|
||||||
lastname: string;
|
lastname: string;
|
||||||
nameaffix: string;
|
nameaffix: string;
|
||||||
birthdate: Date;
|
birthdate: Date;
|
||||||
internalId?: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UpdateMemberNewsletterCommand {
|
export interface UpdateMemberNewsletterCommand {
|
|
@ -1,7 +1,8 @@
|
||||||
import { dataSource } from "../../../data-source";
|
import { dataSource } from "../data-source";
|
||||||
import { communication } from "../../../entity/club/member/communication";
|
import { communication } from "../entity/communication";
|
||||||
import { member } from "../../../entity/club/member/member";
|
import { member } from "../entity/member";
|
||||||
import InternalException from "../../../exceptions/internalException";
|
import InternalException from "../exceptions/internalException";
|
||||||
|
import CommunicationService from "../service/communicationService";
|
||||||
import {
|
import {
|
||||||
CreateMemberCommand,
|
CreateMemberCommand,
|
||||||
DeleteMemberCommand,
|
DeleteMemberCommand,
|
||||||
|
@ -12,7 +13,7 @@ import {
|
||||||
export default abstract class MemberCommandHandler {
|
export default abstract class MemberCommandHandler {
|
||||||
/**
|
/**
|
||||||
* @description create member
|
* @description create member
|
||||||
* @param {CreateMemberCommand} createMember
|
* @param CreateMemberCommand
|
||||||
* @returns {Promise<number>}
|
* @returns {Promise<number>}
|
||||||
*/
|
*/
|
||||||
static async create(createMember: CreateMemberCommand): Promise<number> {
|
static async create(createMember: CreateMemberCommand): Promise<number> {
|
||||||
|
@ -26,26 +27,23 @@ export default abstract class MemberCommandHandler {
|
||||||
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(
|
throw new InternalException("Failed creating member", err);
|
||||||
`Failed creating member${err.code.includes("ER_DUP_ENTRY") ? " due to duplicate entry for column" : ""}`,
|
|
||||||
err
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description update member
|
* @description update member
|
||||||
* @param {UpdateMemberCommand} updateMember
|
* @param UpdateMemberCommand
|
||||||
* @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)
|
||||||
|
@ -55,25 +53,22 @@ export default abstract class MemberCommandHandler {
|
||||||
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(
|
throw new InternalException("Failed updating member", err);
|
||||||
`Failed updating member${err.code.includes("ER_DUP_ENTRY") ? " due to duplicate entry for column" : ""}`,
|
|
||||||
err
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description update member newsletter
|
* @description update member newsletter
|
||||||
* @param {UpdateMemberCommand} updateMember
|
* @param UpdateMemberCommand
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async updateNewsletter(updateMember: UpdateMemberNewsletterCommand): Promise<void> {
|
static async updateNewsletter(updateMember: UpdateMemberNewsletterCommand): Promise<void> {
|
||||||
|
console.log(updateMember);
|
||||||
return await dataSource
|
return await dataSource
|
||||||
.createQueryBuilder()
|
.createQueryBuilder()
|
||||||
.update(member)
|
.update(member)
|
||||||
|
@ -88,26 +83,6 @@ export default abstract class MemberCommandHandler {
|
||||||
.where("id = :id", { id: updateMember.id })
|
.where("id = :id", { id: updateMember.id })
|
||||||
.execute()
|
.execute()
|
||||||
.then(() => {})
|
.then(() => {})
|
||||||
.catch((err) => {
|
|
||||||
throw new InternalException(`Failed updating member`, err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description update member newsletter to unset
|
|
||||||
* @param {number} memberId
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
static async unsetNewsletter(memberId: number): Promise<void> {
|
|
||||||
return await dataSource
|
|
||||||
.createQueryBuilder()
|
|
||||||
.update(member)
|
|
||||||
.set({
|
|
||||||
sendNewsletter: null,
|
|
||||||
})
|
|
||||||
.where("id = :id", { id: memberId })
|
|
||||||
.execute()
|
|
||||||
.then(() => {})
|
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
throw new InternalException("Failed updating member", err);
|
throw new InternalException("Failed updating member", err);
|
||||||
});
|
});
|
||||||
|
@ -115,7 +90,7 @@ export default abstract class MemberCommandHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description delete member
|
* @description delete member
|
||||||
* @param {DeleteMemberCommand} deleteMember
|
* @param DeleteMemberCommand
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async delete(deleteMember: DeleteMemberCommand): Promise<void> {
|
static async delete(deleteMember: DeleteMemberCommand): Promise<void> {
|
|
@ -1,6 +1,8 @@
|
||||||
import { dataSource } from "../../../data-source";
|
import { dataSource } from "../data-source";
|
||||||
import { memberExecutivePositions } from "../../../entity/club/member/memberExecutivePositions";
|
import { executivePosition } from "../entity/executivePosition";
|
||||||
import InternalException from "../../../exceptions/internalException";
|
import { memberExecutivePositions } from "../entity/memberExecutivePositions";
|
||||||
|
import { user } from "../entity/user";
|
||||||
|
import InternalException from "../exceptions/internalException";
|
||||||
import {
|
import {
|
||||||
CreateMemberExecutivePositionCommand,
|
CreateMemberExecutivePositionCommand,
|
||||||
DeleteMemberExecutivePositionCommand,
|
DeleteMemberExecutivePositionCommand,
|
||||||
|
@ -10,7 +12,7 @@ import {
|
||||||
export default abstract class MemberExecutivePositionCommandHandler {
|
export default abstract class MemberExecutivePositionCommandHandler {
|
||||||
/**
|
/**
|
||||||
* @description create memberExecutivePosition
|
* @description create memberExecutivePosition
|
||||||
* @param {CreateMemberExecutivePositionCommand} createMemberExecutivePosition
|
* @param CreateMemberExecutivePositionCommand
|
||||||
* @returns {Promise<number>}
|
* @returns {Promise<number>}
|
||||||
*/
|
*/
|
||||||
static async create(createMemberExecutivePosition: CreateMemberExecutivePositionCommand): Promise<number> {
|
static async create(createMemberExecutivePosition: CreateMemberExecutivePositionCommand): Promise<number> {
|
||||||
|
@ -22,8 +24,16 @@ export default abstract class MemberExecutivePositionCommandHandler {
|
||||||
note: createMemberExecutivePosition.note,
|
note: createMemberExecutivePosition.note,
|
||||||
start: createMemberExecutivePosition.start,
|
start: createMemberExecutivePosition.start,
|
||||||
end: createMemberExecutivePosition.end,
|
end: createMemberExecutivePosition.end,
|
||||||
memberId: createMemberExecutivePosition.memberId,
|
member: await dataSource
|
||||||
executivePositionId: createMemberExecutivePosition.executivePositionId,
|
.getRepository(user)
|
||||||
|
.createQueryBuilder("user")
|
||||||
|
.where("id = :id", { id: createMemberExecutivePosition.memberId })
|
||||||
|
.getOneOrFail(),
|
||||||
|
executivePosition: await dataSource
|
||||||
|
.getRepository(executivePosition)
|
||||||
|
.createQueryBuilder("executivePosition")
|
||||||
|
.where("id = :id", { id: createMemberExecutivePosition.executivePositionId })
|
||||||
|
.getOneOrFail(),
|
||||||
})
|
})
|
||||||
.execute()
|
.execute()
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
|
@ -36,7 +46,7 @@ export default abstract class MemberExecutivePositionCommandHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description update memberExecutivePosition
|
* @description update memberExecutivePosition
|
||||||
* @param {UpdateMemberExecutivePositionCommand} updateMemberExecutivePosition
|
* @param UpdateMemberExecutivePositionCommand
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async update(updateMemberExecutivePosition: UpdateMemberExecutivePositionCommand): Promise<void> {
|
static async update(updateMemberExecutivePosition: UpdateMemberExecutivePositionCommand): Promise<void> {
|
||||||
|
@ -47,7 +57,11 @@ export default abstract class MemberExecutivePositionCommandHandler {
|
||||||
note: updateMemberExecutivePosition.note,
|
note: updateMemberExecutivePosition.note,
|
||||||
start: updateMemberExecutivePosition.start,
|
start: updateMemberExecutivePosition.start,
|
||||||
end: updateMemberExecutivePosition.end,
|
end: updateMemberExecutivePosition.end,
|
||||||
executivePositionId: updateMemberExecutivePosition.executivePositionId,
|
executivePosition: await dataSource
|
||||||
|
.getRepository(executivePosition)
|
||||||
|
.createQueryBuilder("executivePosition")
|
||||||
|
.where("id = :id", { id: updateMemberExecutivePosition.executivePositionId })
|
||||||
|
.getOneOrFail(),
|
||||||
})
|
})
|
||||||
.where("id = :id", { id: updateMemberExecutivePosition.id })
|
.where("id = :id", { id: updateMemberExecutivePosition.id })
|
||||||
.andWhere("memberId = :memberId", { memberId: updateMemberExecutivePosition.memberId })
|
.andWhere("memberId = :memberId", { memberId: updateMemberExecutivePosition.memberId })
|
||||||
|
@ -60,16 +74,16 @@ export default abstract class MemberExecutivePositionCommandHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description delete memberExecutivePosition
|
* @description delete memberExecutivePosition
|
||||||
* @param {DeleteMemberExecutivePositionCommand} deleteMemberExecutivePosition
|
* @param DeleteMemberExecutivePositionCommand
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async delete(deleteMemberExecutivePosition: DeleteMemberExecutivePositionCommand): Promise<void> {
|
static async delete(deletMemberExecutivePosition: DeleteMemberExecutivePositionCommand): Promise<void> {
|
||||||
return await dataSource
|
return await dataSource
|
||||||
.createQueryBuilder()
|
.createQueryBuilder()
|
||||||
.delete()
|
.delete()
|
||||||
.from(memberExecutivePositions)
|
.from(memberExecutivePositions)
|
||||||
.where("id = :id", { id: deleteMemberExecutivePosition.id })
|
.where("id = :id", { id: deletMemberExecutivePosition.id })
|
||||||
.andWhere("memberId = :memberId", { memberId: deleteMemberExecutivePosition.memberId })
|
.andWhere("memberId = :memberId", { memberId: deletMemberExecutivePosition.memberId })
|
||||||
.execute()
|
.execute()
|
||||||
.then(() => {})
|
.then(() => {})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
|
@ -1,6 +1,8 @@
|
||||||
import { dataSource } from "../../../data-source";
|
import { dataSource } from "../data-source";
|
||||||
import { memberQualifications } from "../../../entity/club/member/memberQualifications";
|
import { qualification } from "../entity/qualification";
|
||||||
import InternalException from "../../../exceptions/internalException";
|
import { memberQualifications } from "../entity/memberQualifications";
|
||||||
|
import { user } from "../entity/user";
|
||||||
|
import InternalException from "../exceptions/internalException";
|
||||||
import {
|
import {
|
||||||
CreateMemberQualificationCommand,
|
CreateMemberQualificationCommand,
|
||||||
DeleteMemberQualificationCommand,
|
DeleteMemberQualificationCommand,
|
||||||
|
@ -10,7 +12,7 @@ import {
|
||||||
export default abstract class MemberQualificationCommandHandler {
|
export default abstract class MemberQualificationCommandHandler {
|
||||||
/**
|
/**
|
||||||
* @description create memberQualification
|
* @description create memberQualification
|
||||||
* @param {CreateMemberQualificationCommand} createMemberQualification
|
* @param CreateMemberQualificationCommand
|
||||||
* @returns {Promise<number>}
|
* @returns {Promise<number>}
|
||||||
*/
|
*/
|
||||||
static async create(createMemberQualification: CreateMemberQualificationCommand): Promise<number> {
|
static async create(createMemberQualification: CreateMemberQualificationCommand): Promise<number> {
|
||||||
|
@ -21,8 +23,16 @@ export default abstract class MemberQualificationCommandHandler {
|
||||||
.values({
|
.values({
|
||||||
note: createMemberQualification.note,
|
note: createMemberQualification.note,
|
||||||
start: createMemberQualification.start,
|
start: createMemberQualification.start,
|
||||||
memberId: createMemberQualification.memberId,
|
member: await dataSource
|
||||||
qualificationId: createMemberQualification.qualificationId,
|
.getRepository(user)
|
||||||
|
.createQueryBuilder("user")
|
||||||
|
.where("id = :id", { id: createMemberQualification.memberId })
|
||||||
|
.getOneOrFail(),
|
||||||
|
qualification: await dataSource
|
||||||
|
.getRepository(qualification)
|
||||||
|
.createQueryBuilder("qualification")
|
||||||
|
.where("id = :id", { id: createMemberQualification.qualificationId })
|
||||||
|
.getOneOrFail(),
|
||||||
})
|
})
|
||||||
.execute()
|
.execute()
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
|
@ -35,7 +45,7 @@ export default abstract class MemberQualificationCommandHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description update memberQualification
|
* @description update memberQualification
|
||||||
* @param {UpdateMemberQualificationCommand} updateMemberQualification
|
* @param UpdateMemberQualificationCommand
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async update(updateMemberQualification: UpdateMemberQualificationCommand): Promise<void> {
|
static async update(updateMemberQualification: UpdateMemberQualificationCommand): Promise<void> {
|
||||||
|
@ -47,7 +57,11 @@ export default abstract class MemberQualificationCommandHandler {
|
||||||
start: updateMemberQualification.start,
|
start: updateMemberQualification.start,
|
||||||
end: updateMemberQualification.end,
|
end: updateMemberQualification.end,
|
||||||
terminationReason: updateMemberQualification.terminationReason,
|
terminationReason: updateMemberQualification.terminationReason,
|
||||||
qualificationId: updateMemberQualification.qualificationId,
|
qualification: await dataSource
|
||||||
|
.getRepository(qualification)
|
||||||
|
.createQueryBuilder("qualification")
|
||||||
|
.where("id = :id", { id: updateMemberQualification.qualificationId })
|
||||||
|
.getOneOrFail(),
|
||||||
})
|
})
|
||||||
.where("id = :id", { id: updateMemberQualification.id })
|
.where("id = :id", { id: updateMemberQualification.id })
|
||||||
.andWhere("memberId = :memberId", { memberId: updateMemberQualification.memberId })
|
.andWhere("memberId = :memberId", { memberId: updateMemberQualification.memberId })
|
||||||
|
@ -60,16 +74,16 @@ export default abstract class MemberQualificationCommandHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description delete memberQualification
|
* @description delete memberQualification
|
||||||
* @param {DeleteMemberQualificationCommand} deleteMemberQualification
|
* @param DeleteMemberQualificationCommand
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async delete(deleteMemberQualification: DeleteMemberQualificationCommand): Promise<void> {
|
static async delete(deletMemberQualification: DeleteMemberQualificationCommand): Promise<void> {
|
||||||
return await dataSource
|
return await dataSource
|
||||||
.createQueryBuilder()
|
.createQueryBuilder()
|
||||||
.delete()
|
.delete()
|
||||||
.from(memberQualifications)
|
.from(memberQualifications)
|
||||||
.where("id = :id", { id: deleteMemberQualification.id })
|
.where("id = :id", { id: deletMemberQualification.id })
|
||||||
.andWhere("memberId = :memberId", { memberId: deleteMemberQualification.memberId })
|
.andWhere("memberId = :memberId", { memberId: deletMemberQualification.memberId })
|
||||||
.execute()
|
.execute()
|
||||||
.then(() => {})
|
.then(() => {})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
|
@ -1,4 +1,5 @@
|
||||||
export interface CreateMembershipCommand {
|
export interface CreateMembershipCommand {
|
||||||
|
internalId?: string;
|
||||||
start: Date;
|
start: Date;
|
||||||
memberId: number;
|
memberId: number;
|
||||||
statusId: number;
|
statusId: number;
|
||||||
|
@ -6,6 +7,7 @@ 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,16 +1,18 @@
|
||||||
import { dataSource } from "../../../data-source";
|
import { dataSource } from "../data-source";
|
||||||
import { membership } from "../../../entity/club/member/membership";
|
import { membership } from "../entity/membership";
|
||||||
import InternalException from "../../../exceptions/internalException";
|
import { membershipStatus } from "../entity/membershipStatus";
|
||||||
|
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} createMembership
|
* @param CreateMembershipCommand
|
||||||
* @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
|
||||||
|
@ -18,29 +20,37 @@ export default abstract class MembershipCommandHandler {
|
||||||
.insert()
|
.insert()
|
||||||
.into(membership)
|
.into(membership)
|
||||||
.values({
|
.values({
|
||||||
|
internalId: createMembership.internalId,
|
||||||
start: createMembership.start,
|
start: createMembership.start,
|
||||||
memberId: createMembership.memberId,
|
member: await dataSource
|
||||||
statusId: createMembership.statusId,
|
.getRepository(user)
|
||||||
|
.createQueryBuilder("user")
|
||||||
|
.where("id = :id", { id: createMembership.memberId })
|
||||||
|
.getOneOrFail(),
|
||||||
|
status: await dataSource
|
||||||
|
.getRepository(membershipStatus)
|
||||||
|
.createQueryBuilder("membershipStatus")
|
||||||
|
.where("id = :id", { id: createMembership.statusId })
|
||||||
|
.getOneOrFail(),
|
||||||
})
|
})
|
||||||
.execute()
|
.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: new Date(new Date(createMembership.start).setDate(new Date(createMembership.start).getDate() - 1)),
|
end: createMembership.start,
|
||||||
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);
|
||||||
|
@ -49,7 +59,7 @@ export default abstract class MembershipCommandHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description update membership
|
* @description update membership
|
||||||
* @param {UpdateMembershipCommand} updateMembership
|
* @param UpdateMembershipCommand
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async update(updateMembership: UpdateMembershipCommand): Promise<void> {
|
static async update(updateMembership: UpdateMembershipCommand): Promise<void> {
|
||||||
|
@ -57,10 +67,15 @@ 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,
|
||||||
statusId: updateMembership.statusId,
|
status: await dataSource
|
||||||
|
.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 })
|
||||||
|
@ -73,16 +88,16 @@ export default abstract class MembershipCommandHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description delete membership
|
* @description delete membership
|
||||||
* @param {DeleteMembershipCommand} deleteMembership
|
* @param DeleteMembershipCommand
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async delete(deleteMembership: DeleteMembershipCommand): Promise<void> {
|
static async delete(deletMembership: DeleteMembershipCommand): Promise<void> {
|
||||||
return await dataSource
|
return await dataSource
|
||||||
.createQueryBuilder()
|
.createQueryBuilder()
|
||||||
.delete()
|
.delete()
|
||||||
.from(membership)
|
.from(membership)
|
||||||
.where("id = :id", { id: deleteMembership.id })
|
.where("id = :id", { id: deletMembership.id })
|
||||||
.andWhere("memberId = :memberId", { memberId: deleteMembership.memberId })
|
.andWhere("memberId = :memberId", { memberId: deletMembership.memberId })
|
||||||
.execute()
|
.execute()
|
||||||
.then(() => {})
|
.then(() => {})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
|
@ -1,6 +1,6 @@
|
||||||
import { dataSource } from "../../../data-source";
|
import { dataSource } from "../data-source";
|
||||||
import { membershipStatus } from "../../../entity/settings/membershipStatus";
|
import { membershipStatus } from "../entity/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} createMembershipStatus
|
* @param CreateMembershipStatusCommand
|
||||||
* @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} updateMembershipStatus
|
* @param UpdateMembershipStatusCommand
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async update(updateMembershipStatus: UpdateMembershipStatusCommand): Promise<void> {
|
static async update(updateMembershipStatus: UpdateMembershipStatusCommand): Promise<void> {
|
||||||
|
@ -52,24 +52,19 @@ export default abstract class MembershipStatusCommandHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description delete membershipStatus
|
* @description delete membershipStatus
|
||||||
* @param {DeleteMembershipStatusCommand} deleteMembershipStatus
|
* @param DeleteMembershipStatusCommand
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async delete(deleteMembershipStatus: DeleteMembershipStatusCommand): Promise<void> {
|
static async delete(deletMembershipStatus: DeleteMembershipStatusCommand): Promise<void> {
|
||||||
return await dataSource
|
return await dataSource
|
||||||
.createQueryBuilder()
|
.createQueryBuilder()
|
||||||
.delete()
|
.delete()
|
||||||
.from(membershipStatus)
|
.from(membershipStatus)
|
||||||
.where("id = :id", { id: deleteMembershipStatus.id })
|
.where("id = :id", { id: deletMembershipStatus.id })
|
||||||
.execute()
|
.execute()
|
||||||
.then(() => {})
|
.then(() => {})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
throw new InternalException(
|
throw new InternalException("Failed deleting membershipStatus", err);
|
||||||
`Failed deleting membershipStatus${
|
|
||||||
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 { qualification } from "../../../entity/settings/qualification";
|
import { qualification } from "../entity/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} createQualification
|
* @param CreateQualificationCommand
|
||||||
* @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} updateQualification
|
* @param UpdateQualificationCommand
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async update(updateQualification: UpdateQualificationCommand): Promise<void> {
|
static async update(updateQualification: UpdateQualificationCommand): Promise<void> {
|
||||||
|
@ -54,22 +54,19 @@ export default abstract class QualificationCommandHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description delete qualification
|
* @description delete qualification
|
||||||
* @param {DeleteQualificationCommand} deleteQualification
|
* @param DeleteQualificationCommand
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async delete(deleteQualification: DeleteQualificationCommand): Promise<void> {
|
static async delete(deletQualification: DeleteQualificationCommand): Promise<void> {
|
||||||
return await dataSource
|
return await dataSource
|
||||||
.createQueryBuilder()
|
.createQueryBuilder()
|
||||||
.delete()
|
.delete()
|
||||||
.from(qualification)
|
.from(qualification)
|
||||||
.where("id = :id", { id: deleteQualification.id })
|
.where("id = :id", { id: deletQualification.id })
|
||||||
.execute()
|
.execute()
|
||||||
.then(() => {})
|
.then(() => {})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
throw new InternalException(
|
throw new InternalException("Failed deleting qualification", err);
|
||||||
`Failed deleting qualification${err.code.includes("ER_ROW_IS_REFERENCED") ? " due to referenced data" : ""}`,
|
|
||||||
err
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,6 +1,5 @@
|
||||||
export interface CreateRefreshCommand {
|
export interface CreateRefreshCommand {
|
||||||
userId: number;
|
userId: number;
|
||||||
isFromPwa?: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DeleteRefreshCommand {
|
export interface DeleteRefreshCommand {
|
||||||
|
|
|
@ -1,19 +1,25 @@
|
||||||
import { dataSource } from "../data-source";
|
import { dataSource } from "../data-source";
|
||||||
import { refresh } from "../entity/refresh";
|
import { refresh } from "../entity/refresh";
|
||||||
import { PWA_REFRESH_EXPIRATION, REFRESH_EXPIRATION } from "../env.defaults";
|
import { REFRESH_EXPIRATION } from "../env.defaults";
|
||||||
import InternalException from "../exceptions/internalException";
|
import InternalException from "../exceptions/internalException";
|
||||||
|
import { JWTHelper } from "../helpers/jwtHelper";
|
||||||
import { StringHelper } from "../helpers/stringHelper";
|
import { StringHelper } from "../helpers/stringHelper";
|
||||||
import UserService from "../service/user/userService";
|
import UserService from "../service/userService";
|
||||||
|
import { JWTRefresh } from "../type/jwtTypes";
|
||||||
import { CreateRefreshCommand, DeleteRefreshCommand } from "./refreshCommand";
|
import { 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} createRefresh
|
* @param CreateRefreshCommand
|
||||||
* @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
|
||||||
|
@ -23,9 +29,7 @@ export default abstract class RefreshCommandHandler {
|
||||||
.values({
|
.values({
|
||||||
token: refreshToken,
|
token: refreshToken,
|
||||||
user: await UserService.getById(createRefresh.userId),
|
user: await UserService.getById(createRefresh.userId),
|
||||||
expiry: createRefresh.isFromPwa
|
expiry: new Date(Date.now() + ms(REFRESH_EXPIRATION)),
|
||||||
? new Date(Date.now() + ms(PWA_REFRESH_EXPIRATION))
|
|
||||||
: new Date(Date.now() + ms(REFRESH_EXPIRATION)),
|
|
||||||
})
|
})
|
||||||
.execute()
|
.execute()
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
|
@ -38,7 +42,7 @@ export default abstract class RefreshCommandHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description delete refresh by user and token
|
* @description delete refresh by user and token
|
||||||
* @param {DeleteRefreshCommand} deleteRefresh
|
* @param DeleteRefreshCommand
|
||||||
* @returns {Promise<any>}
|
* @returns {Promise<any>}
|
||||||
*/
|
*/
|
||||||
static async deleteByToken(deleteRefresh: DeleteRefreshCommand): Promise<any> {
|
static async deleteByToken(deleteRefresh: DeleteRefreshCommand): Promise<any> {
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
export interface CreateResetCommand {
|
|
||||||
mail: string;
|
|
||||||
username: string;
|
|
||||||
secret: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface DeleteResetCommand {
|
|
||||||
token: string;
|
|
||||||
mail: string;
|
|
||||||
}
|
|
|
@ -1,54 +0,0 @@
|
||||||
import { dataSource } from "../data-source";
|
|
||||||
import { reset } from "../entity/reset";
|
|
||||||
import InternalException from "../exceptions/internalException";
|
|
||||||
import { StringHelper } from "../helpers/stringHelper";
|
|
||||||
import { CreateResetCommand, DeleteResetCommand } from "./resetCommand";
|
|
||||||
|
|
||||||
export default abstract class ResetCommandHandler {
|
|
||||||
/**
|
|
||||||
* @description create user
|
|
||||||
* @param {CreateResetCommand} createReset
|
|
||||||
* @returns {Promise<string>}
|
|
||||||
*/
|
|
||||||
static async create(createReset: CreateResetCommand): Promise<string> {
|
|
||||||
const token = StringHelper.random(32);
|
|
||||||
|
|
||||||
return await dataSource
|
|
||||||
.createQueryBuilder()
|
|
||||||
.insert()
|
|
||||||
.into(reset)
|
|
||||||
.values({
|
|
||||||
token: token,
|
|
||||||
mail: createReset.mail,
|
|
||||||
username: createReset.username,
|
|
||||||
secret: createReset.secret,
|
|
||||||
})
|
|
||||||
.orUpdate(["token", "secret"], ["mail"])
|
|
||||||
.execute()
|
|
||||||
.then((result) => {
|
|
||||||
return token;
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
throw new InternalException("Failed saving reset", err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description delete reset by mail and token
|
|
||||||
* @param {DeleteRefreshCommand} deleteReset
|
|
||||||
* @returns {Promise<any>}
|
|
||||||
*/
|
|
||||||
static async deleteByTokenAndMail(deleteReset: DeleteResetCommand): Promise<any> {
|
|
||||||
return await dataSource
|
|
||||||
.createQueryBuilder()
|
|
||||||
.delete()
|
|
||||||
.from(reset)
|
|
||||||
.where("reset.token = :token", { token: deleteReset.token })
|
|
||||||
.andWhere("reset.mail = :mail", { mail: deleteReset.mail })
|
|
||||||
.execute()
|
|
||||||
.then((res) => {})
|
|
||||||
.catch((err) => {
|
|
||||||
throw new InternalException("failed reset removal", err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,12 +1,12 @@
|
||||||
import { dataSource } from "../../../data-source";
|
import { dataSource } from "../data-source";
|
||||||
import { role } from "../../../entity/user/role";
|
import { role } from "../entity/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} createRole
|
* @param CreateRoleCommand
|
||||||
* @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} updateRole
|
* @param UpdateRoleCommand
|
||||||
* @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} deleteRole
|
* @param DeleteRoleCommand
|
||||||
* @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,21 +1,22 @@
|
||||||
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/user/role_permission";
|
import { rolePermission } from "../entity/role_permission";
|
||||||
import InternalException from "../../../exceptions/internalException";
|
import InternalException from "../exceptions/internalException";
|
||||||
import RoleService from "../../../service/user/roleService";
|
import RoleService from "../service/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/user/rolePermissionService";
|
import RolePermissionService from "../service/rolePermissionService";
|
||||||
import { PermissionString } from "../../../type/permissionTypes";
|
import { role } from "../entity/role";
|
||||||
|
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} updateRolePermissions
|
* @param UpdateRolePermissionsCommand
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async updatePermissions(updateRolePermissions: UpdateRolePermissionsCommand): Promise<void> {
|
static async updatePermissions(updateRolePermissions: UpdateRolePermissionsCommand): Promise<void> {
|
||||||
|
@ -74,7 +75,7 @@ export default abstract class RolePermissionCommandHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description grant permission to user
|
* @description grant permission to user
|
||||||
* @param {CreateRolePermissionCommand} createPermission
|
* @param CreateRolePermissionCommand
|
||||||
* @returns {Promise<number>}
|
* @returns {Promise<number>}
|
||||||
*/
|
*/
|
||||||
static async create(createPermission: CreateRolePermissionCommand): Promise<number> {
|
static async create(createPermission: CreateRolePermissionCommand): Promise<number> {
|
||||||
|
@ -97,7 +98,7 @@ export default abstract class RolePermissionCommandHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description remove permission from role
|
* @description remove permission from role
|
||||||
* @param {DeleteRolePermissionCommand} deletePermission
|
* @param DeleteRolePermissionCommand
|
||||||
* @returns {Promise<any>}
|
* @returns {Promise<any>}
|
||||||
*/
|
*/
|
||||||
static async delete(deletePermission: DeleteRolePermissionCommand): Promise<any> {
|
static async delete(deletePermission: DeleteRolePermissionCommand): Promise<any> {
|
||||||
|
@ -108,7 +109,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(() => {})
|
.then((res) => {})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
throw new InternalException("failed role permission removal", err);
|
throw new InternalException("failed role permission removal", err);
|
||||||
});
|
});
|
|
@ -1,18 +0,0 @@
|
||||||
export interface CreateCalendarTypeCommand {
|
|
||||||
type: string;
|
|
||||||
nscdr: boolean;
|
|
||||||
color: string;
|
|
||||||
passphrase?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface UpdateCalendarTypeCommand {
|
|
||||||
id: number;
|
|
||||||
type: string;
|
|
||||||
nscdr: boolean;
|
|
||||||
color: string;
|
|
||||||
passphrase?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface DeleteCalendarTypeCommand {
|
|
||||||
id: number;
|
|
||||||
}
|
|
|
@ -1,75 +0,0 @@
|
||||||
import { dataSource } from "../../../data-source";
|
|
||||||
import { calendarType } from "../../../entity/settings/calendarType";
|
|
||||||
import InternalException from "../../../exceptions/internalException";
|
|
||||||
import { CreateCalendarTypeCommand, DeleteCalendarTypeCommand, UpdateCalendarTypeCommand } from "./calendarTypeCommand";
|
|
||||||
|
|
||||||
export default abstract class CalendarTypeCommandHandler {
|
|
||||||
/**
|
|
||||||
* @description create calendarType
|
|
||||||
* @param {CreateCalendarTypeCommand} createCalendarType
|
|
||||||
* @returns {Promise<number>}
|
|
||||||
*/
|
|
||||||
static async create(createCalendarType: CreateCalendarTypeCommand): Promise<number> {
|
|
||||||
return await dataSource
|
|
||||||
.createQueryBuilder()
|
|
||||||
.insert()
|
|
||||||
.into(calendarType)
|
|
||||||
.values({
|
|
||||||
type: createCalendarType.type,
|
|
||||||
nscdr: createCalendarType.nscdr,
|
|
||||||
color: createCalendarType.color,
|
|
||||||
passphrase: createCalendarType.nscdr ? null : createCalendarType.passphrase,
|
|
||||||
})
|
|
||||||
.execute()
|
|
||||||
.then((result) => {
|
|
||||||
return result.identifiers[0].id;
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
throw new InternalException("Failed creating calendarType", err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description update calendarType
|
|
||||||
* @param {UpdateCalendarTypeCommand} updateCalendarType
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
static async update(updateCalendarType: UpdateCalendarTypeCommand): Promise<void> {
|
|
||||||
return await dataSource
|
|
||||||
.createQueryBuilder()
|
|
||||||
.update(calendarType)
|
|
||||||
.set({
|
|
||||||
type: updateCalendarType.type,
|
|
||||||
nscdr: updateCalendarType.nscdr,
|
|
||||||
color: updateCalendarType.color,
|
|
||||||
passphrase: updateCalendarType.nscdr ? null : updateCalendarType.passphrase,
|
|
||||||
})
|
|
||||||
.where("id = :id", { id: updateCalendarType.id })
|
|
||||||
.execute()
|
|
||||||
.then(() => {})
|
|
||||||
.catch((err) => {
|
|
||||||
throw new InternalException("Failed updating award", err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description delete calendarType
|
|
||||||
* @param {DeleteCalendarTypeCommand} deleteCalendarType
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
static async delete(deleteCalendarType: DeleteCalendarTypeCommand): Promise<void> {
|
|
||||||
return await dataSource
|
|
||||||
.createQueryBuilder()
|
|
||||||
.delete()
|
|
||||||
.from(calendarType)
|
|
||||||
.where("id = :id", { id: deleteCalendarType.id })
|
|
||||||
.execute()
|
|
||||||
.then(() => {})
|
|
||||||
.catch((err) => {
|
|
||||||
throw new InternalException(
|
|
||||||
`Failed deleting calendarType${err.code.includes("ER_ROW_IS_REFERENCED") ? " due to referenced data" : ""}`,
|
|
||||||
err
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,6 +0,0 @@
|
||||||
import { NewsletterConfigType } from "../../../enums/newsletterConfigType";
|
|
||||||
|
|
||||||
export interface SetNewsletterConfigCommand {
|
|
||||||
comTypeId: number;
|
|
||||||
config: NewsletterConfigType;
|
|
||||||
}
|
|
|
@ -1,30 +0,0 @@
|
||||||
import { dataSource } from "../../../data-source";
|
|
||||||
import { newsletterConfig } from "../../../entity/settings/newsletterConfig";
|
|
||||||
import InternalException from "../../../exceptions/internalException";
|
|
||||||
import { SetNewsletterConfigCommand } from "./newsletterConfigCommand";
|
|
||||||
|
|
||||||
export default abstract class NewsletterConfigCommandHandler {
|
|
||||||
/**
|
|
||||||
* @description set newsletterConfig
|
|
||||||
* @param {SetNewsletterConfigCommand} setNewsletterConfig
|
|
||||||
* @returns {Promise<number>}
|
|
||||||
*/
|
|
||||||
static async set(setNewsletterConfig: SetNewsletterConfigCommand): Promise<number> {
|
|
||||||
return await dataSource
|
|
||||||
.createQueryBuilder()
|
|
||||||
.insert()
|
|
||||||
.into(newsletterConfig)
|
|
||||||
.values({
|
|
||||||
comTypeId: setNewsletterConfig.comTypeId,
|
|
||||||
config: setNewsletterConfig.config,
|
|
||||||
})
|
|
||||||
.orUpdate(["config"], "comTypeId")
|
|
||||||
.execute()
|
|
||||||
.then((result) => {
|
|
||||||
return result.identifiers[0].id;
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
throw new InternalException("Failed setting newsletterConfig", err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,15 +0,0 @@
|
||||||
import { DynamicQueryStructure } from "../../../type/dynamicQueries";
|
|
||||||
|
|
||||||
export interface CreateQueryStoreCommand {
|
|
||||||
title: string;
|
|
||||||
query: string | DynamicQueryStructure;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface UpdateQueryStoreCommand {
|
|
||||||
id: number;
|
|
||||||
query: string | DynamicQueryStructure;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface DeleteQueryStoreCommand {
|
|
||||||
id: number;
|
|
||||||
}
|
|
|
@ -1,72 +0,0 @@
|
||||||
import { dataSource } from "../../../data-source";
|
|
||||||
import { query } from "../../../entity/settings/query";
|
|
||||||
import InternalException from "../../../exceptions/internalException";
|
|
||||||
import { CreateQueryStoreCommand, DeleteQueryStoreCommand, UpdateQueryStoreCommand } from "./queryStoreCommand";
|
|
||||||
|
|
||||||
export default abstract class QueryStoreCommandHandler {
|
|
||||||
/**
|
|
||||||
* @description create queryStore
|
|
||||||
* @param {CreateQueryStoreCommand} createQueryStore
|
|
||||||
* @returns {Promise<number>}
|
|
||||||
*/
|
|
||||||
static async create(createQueryStore: CreateQueryStoreCommand): Promise<number> {
|
|
||||||
return await dataSource
|
|
||||||
.createQueryBuilder()
|
|
||||||
.insert()
|
|
||||||
.into(query)
|
|
||||||
.values({
|
|
||||||
title: createQueryStore.title,
|
|
||||||
query:
|
|
||||||
typeof createQueryStore.query == "string" ? createQueryStore.query : JSON.stringify(createQueryStore.query),
|
|
||||||
})
|
|
||||||
.execute()
|
|
||||||
.then((result) => {
|
|
||||||
return result.identifiers[0].id;
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
throw new InternalException("Failed creating queryStore", err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description update queryStore
|
|
||||||
* @param {UpdateQueryStoreCommand} updateQueryStore
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
static async update(updateQueryStore: UpdateQueryStoreCommand): Promise<void> {
|
|
||||||
return await dataSource
|
|
||||||
.createQueryBuilder()
|
|
||||||
.update(query)
|
|
||||||
.set({
|
|
||||||
query:
|
|
||||||
typeof updateQueryStore.query == "string" ? updateQueryStore.query : JSON.stringify(updateQueryStore.query),
|
|
||||||
})
|
|
||||||
.where("id = :id", { id: updateQueryStore.id })
|
|
||||||
.execute()
|
|
||||||
.then(() => {})
|
|
||||||
.catch((err) => {
|
|
||||||
throw new InternalException("Failed updating queryStore", err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description delete queryStore
|
|
||||||
* @param {DeleteQueryStoreCommand} deleteQueryStore
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
static async delete(deleteQueryStore: DeleteQueryStoreCommand): Promise<void> {
|
|
||||||
return await dataSource
|
|
||||||
.createQueryBuilder()
|
|
||||||
.delete()
|
|
||||||
.from(query)
|
|
||||||
.where("id = :id", { id: deleteQueryStore.id })
|
|
||||||
.execute()
|
|
||||||
.then(() => {})
|
|
||||||
.catch((err) => {
|
|
||||||
throw new InternalException(
|
|
||||||
`Failed deleting queryStore${err.code.includes("ER_ROW_IS_REFERENCED") ? " due to referenced data" : ""}`,
|
|
||||||
err
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,16 +0,0 @@
|
||||||
export interface CreateTemplateCommand {
|
|
||||||
template: string;
|
|
||||||
description: string | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface UpdateTemplateCommand {
|
|
||||||
id: number;
|
|
||||||
template: string;
|
|
||||||
description: string | null;
|
|
||||||
design: object;
|
|
||||||
html: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface DeleteTemplateCommand {
|
|
||||||
id: number;
|
|
||||||
}
|
|
|
@ -1,73 +0,0 @@
|
||||||
import { dataSource } from "../../../data-source";
|
|
||||||
import { template } from "../../../entity/settings/template";
|
|
||||||
import InternalException from "../../../exceptions/internalException";
|
|
||||||
import { CreateTemplateCommand, DeleteTemplateCommand, UpdateTemplateCommand } from "./templateCommand";
|
|
||||||
|
|
||||||
export default abstract class TemplateCommandHandler {
|
|
||||||
/**
|
|
||||||
* @description create template
|
|
||||||
* @param {CreateTemplateCommand} createTemplate
|
|
||||||
* @returns {Promise<number>}
|
|
||||||
*/
|
|
||||||
static async create(createTemplate: CreateTemplateCommand): Promise<number> {
|
|
||||||
return await dataSource
|
|
||||||
.createQueryBuilder()
|
|
||||||
.insert()
|
|
||||||
.into(template)
|
|
||||||
.values({
|
|
||||||
template: createTemplate.template,
|
|
||||||
description: createTemplate.description,
|
|
||||||
})
|
|
||||||
.execute()
|
|
||||||
.then((result) => {
|
|
||||||
return result.identifiers[0].id;
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
throw new InternalException("Failed creating template", err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description update template
|
|
||||||
* @param {UpdateTemplateCommand} updateTemplate
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
static async update(updateTemplate: UpdateTemplateCommand): Promise<void> {
|
|
||||||
return await dataSource
|
|
||||||
.createQueryBuilder()
|
|
||||||
.update(template)
|
|
||||||
.set({
|
|
||||||
template: updateTemplate.template,
|
|
||||||
description: updateTemplate.description,
|
|
||||||
design: updateTemplate.design,
|
|
||||||
html: updateTemplate.html,
|
|
||||||
})
|
|
||||||
.where("id = :id", { id: updateTemplate.id })
|
|
||||||
.execute()
|
|
||||||
.then(() => {})
|
|
||||||
.catch((err) => {
|
|
||||||
throw new InternalException("Failed updating template", err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description delete template
|
|
||||||
* @param {DeleteTemplateCommand} deleteTemplate
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
static async delete(deleteTemplate: DeleteTemplateCommand): Promise<void> {
|
|
||||||
return await dataSource
|
|
||||||
.createQueryBuilder()
|
|
||||||
.delete()
|
|
||||||
.from(template)
|
|
||||||
.where("id = :id", { id: deleteTemplate.id })
|
|
||||||
.execute()
|
|
||||||
.then(() => {})
|
|
||||||
.catch((err) => {
|
|
||||||
throw new InternalException(
|
|
||||||
`Failed deleting template${err.code.includes("ER_ROW_IS_REFERENCED") ? " due to referenced data" : ""}`,
|
|
||||||
err
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,8 +0,0 @@
|
||||||
export interface UpdateTemplateUsageCommand {
|
|
||||||
scope: string;
|
|
||||||
headerId: number | null;
|
|
||||||
bodyId: number | null;
|
|
||||||
footerId: number | null;
|
|
||||||
headerHeight: number | null;
|
|
||||||
footerHeight: number | null;
|
|
||||||
}
|
|
|
@ -1,30 +0,0 @@
|
||||||
import { dataSource } from "../../../data-source";
|
|
||||||
import { templateUsage } from "../../../entity/settings/templateUsage";
|
|
||||||
import InternalException from "../../../exceptions/internalException";
|
|
||||||
import { UpdateTemplateUsageCommand } from "./templateUsageCommand";
|
|
||||||
|
|
||||||
export default abstract class TemplateUsageCommandHandler {
|
|
||||||
/**
|
|
||||||
* @description update templateUsage
|
|
||||||
* @param {UpdateTemplateUsageCommand} updateTemplateUsage
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
static async update(updateTemplateUsage: UpdateTemplateUsageCommand): Promise<void> {
|
|
||||||
return await dataSource
|
|
||||||
.createQueryBuilder()
|
|
||||||
.update(templateUsage)
|
|
||||||
.set({
|
|
||||||
headerId: updateTemplateUsage.headerId,
|
|
||||||
bodyId: updateTemplateUsage.bodyId,
|
|
||||||
footerId: updateTemplateUsage.footerId,
|
|
||||||
headerHeight: updateTemplateUsage.headerHeight,
|
|
||||||
footerHeight: updateTemplateUsage.footerHeight,
|
|
||||||
})
|
|
||||||
.where("scope = :scope", { scope: updateTemplateUsage.scope })
|
|
||||||
.execute()
|
|
||||||
.then(() => {})
|
|
||||||
.catch((err) => {
|
|
||||||
throw new InternalException("Failed updating templateUsage", err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,19 +0,0 @@
|
||||||
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;
|
|
||||||
}
|
|
|
@ -1,100 +0,0 @@
|
||||||
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);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,16 +0,0 @@
|
||||||
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>;
|
|
||||||
}
|
|
|
@ -1,119 +0,0 @@
|
||||||
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);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -4,7 +4,6 @@ export interface CreateUserCommand {
|
||||||
firstname: string;
|
firstname: string;
|
||||||
lastname: string;
|
lastname: string;
|
||||||
secret: string;
|
secret: string;
|
||||||
isOwner: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UpdateUserCommand {
|
export interface UpdateUserCommand {
|
||||||
|
@ -15,16 +14,6 @@ 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,21 +1,14 @@
|
||||||
import { EntityManager } from "typeorm";
|
import { EntityManager } from "typeorm";
|
||||||
import { dataSource } from "../../../data-source";
|
import { dataSource } from "../data-source";
|
||||||
import { user } from "../../../entity/user/user";
|
import { user } from "../entity/user";
|
||||||
import InternalException from "../../../exceptions/internalException";
|
import InternalException from "../exceptions/internalException";
|
||||||
import {
|
import { CreateUserCommand, DeleteUserCommand, UpdateUserCommand, UpdateUserRolesCommand } from "./userCommand";
|
||||||
CreateUserCommand,
|
import UserService from "../service/userService";
|
||||||
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} createUser
|
* @param CreateUserCommand
|
||||||
* @returns {Promise<number>}
|
* @returns {Promise<number>}
|
||||||
*/
|
*/
|
||||||
static async create(createUser: CreateUserCommand): Promise<number> {
|
static async create(createUser: CreateUserCommand): Promise<number> {
|
||||||
|
@ -29,7 +22,6 @@ 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) => {
|
||||||
|
@ -42,7 +34,7 @@ export default abstract class UserCommandHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description update user
|
* @description update user
|
||||||
* @param {UpdateUserCommand} updateUser
|
* @param UpdateUserCommand
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async update(updateUser: UpdateUserCommand): Promise<void> {
|
static async update(updateUser: UpdateUserCommand): Promise<void> {
|
||||||
|
@ -63,29 +55,9 @@ export default abstract class UserCommandHandler {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @description update user
|
|
||||||
* @param {UpdateUserSecretCommand} updateUser
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
static async updateSecret(updateUser: UpdateUserSecretCommand): Promise<void> {
|
|
||||||
return await dataSource
|
|
||||||
.createQueryBuilder()
|
|
||||||
.update(user)
|
|
||||||
.set({
|
|
||||||
secret: updateUser.secret,
|
|
||||||
})
|
|
||||||
.where("id = :id", { id: updateUser.id })
|
|
||||||
.execute()
|
|
||||||
.then(() => {})
|
|
||||||
.catch((err) => {
|
|
||||||
throw new InternalException("Failed updating user secret", err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description update user roles
|
* @description update user roles
|
||||||
* @param {UpdateUserRolesCommand} updateUserRoles
|
* @param UpdateUserRolesCommand
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async updateRoles(updateUserRoles: UpdateUserRolesCommand): Promise<void> {
|
static async updateRoles(updateUserRoles: UpdateUserRolesCommand): Promise<void> {
|
||||||
|
@ -117,38 +89,6 @@ export default abstract class UserCommandHandler {
|
||||||
return await manager.createQueryBuilder().relation(user, "roles").of(userId).remove(roleId);
|
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/user";
|
import { user } from "../entity/user";
|
||||||
import { userPermission } from "../../../entity/user/user_permission";
|
import { userPermission } from "../entity/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/user/userPermissionService";
|
import UserPermissionService from "../service/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} updateUserPermissions
|
* @param UpdateUserPermissionsCommand
|
||||||
* @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} createPermission
|
* @param CreateUserPermissionCommand
|
||||||
* @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} deletePermission
|
* @param DeleteUserPermissionCommand
|
||||||
* @returns {Promise<any>}
|
* @returns {Promise<any>}
|
||||||
*/
|
*/
|
||||||
static async delete(deletePermission: DeleteUserPermissionCommand): Promise<any> {
|
static async delete(deletePermission: DeleteUserPermissionCommand): Promise<any> {
|
|
@ -1,8 +1,8 @@
|
||||||
import { Request, Response } from "express";
|
import { Request, Response } from "express";
|
||||||
import AwardService from "../../../service/settings/awardService";
|
import AwardService from "../../service/awardService";
|
||||||
import AwardFactory from "../../../factory/admin/settings/award";
|
import AwardFactory from "../../factory/admin/award";
|
||||||
import { CreateAwardCommand, DeleteAwardCommand, UpdateAwardCommand } from "../../../command/settings/award/awardCommand";
|
import { CreateAwardCommand, DeleteAwardCommand, UpdateAwardCommand } from "../../command/awardCommand";
|
||||||
import AwardCommandHandler from "../../../command/settings/award/awardCommandHandler";
|
import AwardCommandHandler from "../../command/awardCommandHandler";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description get all awards
|
* @description get all awards
|
|
@ -1,205 +0,0 @@
|
||||||
import { Request, Response } from "express";
|
|
||||||
import CalendarService from "../../../service/club/calendarService";
|
|
||||||
import CalendarFactory from "../../../factory/admin/club/calendar";
|
|
||||||
import CalendarTypeService from "../../../service/settings/calendarTypeService";
|
|
||||||
import CalendarTypeFactory from "../../../factory/admin/settings/calendarType";
|
|
||||||
import { CreateCalendarCommand, DeleteCalendarCommand, UpdateCalendarCommand } from "../../../command/club/calendar/calendarCommand";
|
|
||||||
import CalendarCommandHandler from "../../../command/club/calendar/calendarCommandHandler";
|
|
||||||
import {
|
|
||||||
CreateCalendarTypeCommand,
|
|
||||||
DeleteCalendarTypeCommand,
|
|
||||||
UpdateCalendarTypeCommand,
|
|
||||||
} from "../../../command/settings/calendarType/calendarTypeCommand";
|
|
||||||
import CalendarTypeCommandHandler from "../../../command/settings/calendarType/calendarTypeCommandHandler";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description get all calendar items
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function getAllCalendarItems(req: Request, res: Response): Promise<any> {
|
|
||||||
let items = await CalendarService.getAll();
|
|
||||||
|
|
||||||
res.json(CalendarFactory.mapToBase(items));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description get calendar item by id
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function getCalendarItemById(req: Request, res: Response): Promise<any> {
|
|
||||||
const id = req.params.id;
|
|
||||||
let item = await CalendarService.getById(id);
|
|
||||||
|
|
||||||
res.json(CalendarFactory.mapToSingle(item));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description get all calendar types
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function getAllCalendarTypes(req: Request, res: Response): Promise<any> {
|
|
||||||
let types = await CalendarTypeService.getAll();
|
|
||||||
|
|
||||||
res.json(CalendarTypeFactory.mapToBase(types));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description get calendar type by id
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function getCalendarTypeById(req: Request, res: Response): Promise<any> {
|
|
||||||
const id = parseInt(req.params.id);
|
|
||||||
let type = await CalendarTypeService.getById(id);
|
|
||||||
|
|
||||||
res.json(CalendarTypeFactory.mapToSingle(type));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description create calendar item
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function createCalendarItem(req: Request, res: Response): Promise<any> {
|
|
||||||
const starttime = req.body.starttime;
|
|
||||||
const endtime = req.body.endtime;
|
|
||||||
const title = req.body.title;
|
|
||||||
const content = req.body.content;
|
|
||||||
const location = req.body.location;
|
|
||||||
const allDay = req.body.allDay;
|
|
||||||
const typeId = req.body.typeId;
|
|
||||||
|
|
||||||
let createItem: CreateCalendarCommand = {
|
|
||||||
starttime,
|
|
||||||
endtime,
|
|
||||||
title,
|
|
||||||
content,
|
|
||||||
location,
|
|
||||||
allDay,
|
|
||||||
typeId,
|
|
||||||
};
|
|
||||||
let id = await CalendarCommandHandler.create(createItem);
|
|
||||||
|
|
||||||
res.send(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description create calendar type
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function createCalendarType(req: Request, res: Response): Promise<any> {
|
|
||||||
const type = req.body.type;
|
|
||||||
const nscdr = req.body.nscdr;
|
|
||||||
const color = req.body.color;
|
|
||||||
const passphrase = req.body.passphrase;
|
|
||||||
|
|
||||||
let createType: CreateCalendarTypeCommand = {
|
|
||||||
type,
|
|
||||||
nscdr,
|
|
||||||
color,
|
|
||||||
passphrase,
|
|
||||||
};
|
|
||||||
let id = await CalendarTypeCommandHandler.create(createType);
|
|
||||||
|
|
||||||
res.send(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description update calendar item
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function updateCalendarItem(req: Request, res: Response): Promise<any> {
|
|
||||||
const id = req.params.id;
|
|
||||||
const starttime = req.body.starttime;
|
|
||||||
const endtime = req.body.endtime;
|
|
||||||
const title = req.body.title;
|
|
||||||
const content = req.body.content;
|
|
||||||
const location = req.body.location;
|
|
||||||
const allDay = req.body.allDay;
|
|
||||||
const typeId = req.body.typeId;
|
|
||||||
|
|
||||||
let updateItem: UpdateCalendarCommand = {
|
|
||||||
id,
|
|
||||||
starttime,
|
|
||||||
endtime,
|
|
||||||
title,
|
|
||||||
content,
|
|
||||||
location,
|
|
||||||
allDay,
|
|
||||||
typeId,
|
|
||||||
};
|
|
||||||
await CalendarCommandHandler.update(updateItem);
|
|
||||||
|
|
||||||
res.sendStatus(204);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description update calendar type
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function updateCalendarType(req: Request, res: Response): Promise<any> {
|
|
||||||
const id = parseInt(req.params.id);
|
|
||||||
const type = req.body.type;
|
|
||||||
const nscdr = req.body.nscdr;
|
|
||||||
const color = req.body.color;
|
|
||||||
const passphrase = req.body.passphrase;
|
|
||||||
|
|
||||||
let updateType: UpdateCalendarTypeCommand = {
|
|
||||||
id,
|
|
||||||
type,
|
|
||||||
nscdr,
|
|
||||||
color,
|
|
||||||
passphrase,
|
|
||||||
};
|
|
||||||
await CalendarTypeCommandHandler.update(updateType);
|
|
||||||
|
|
||||||
res.sendStatus(204);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description delete calendar item
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function deleteCalendarItem(req: Request, res: Response): Promise<any> {
|
|
||||||
const id = req.params.id;
|
|
||||||
|
|
||||||
let deleteItem: DeleteCalendarCommand = {
|
|
||||||
id,
|
|
||||||
};
|
|
||||||
await CalendarCommandHandler.delete(deleteItem);
|
|
||||||
|
|
||||||
res.sendStatus(204);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description delete calendar type
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function deleteCalendarType(req: Request, res: Response): Promise<any> {
|
|
||||||
const id = parseInt(req.params.id);
|
|
||||||
|
|
||||||
let deleteType: DeleteCalendarTypeCommand = {
|
|
||||||
id,
|
|
||||||
};
|
|
||||||
await CalendarTypeCommandHandler.delete(deleteType);
|
|
||||||
|
|
||||||
res.sendStatus(204);
|
|
||||||
}
|
|
|
@ -1,388 +0,0 @@
|
||||||
import { Request, Response } from "express";
|
|
||||||
import NewsletterService from "../../../service/club/newsletter/newsletterService";
|
|
||||||
import NewsletterFactory from "../../../factory/admin/club/newsletter/newsletter";
|
|
||||||
import NewsletterDatesService from "../../../service/club/newsletter/newsletterDatesService";
|
|
||||||
import NewsletterDatesFactory from "../../../factory/admin/club/newsletter/newsletterDates";
|
|
||||||
import NewsletterRecipientsService from "../../../service/club/newsletter/newsletterRecipientsService";
|
|
||||||
import NewsletterRecipientsFactory from "../../../factory/admin/club/newsletter/newsletterRecipients";
|
|
||||||
import { FileSystemHelper } from "../../../helpers/fileSystemHelper";
|
|
||||||
import {
|
|
||||||
CreateNewsletterCommand,
|
|
||||||
SynchronizeNewsletterCommand,
|
|
||||||
} from "../../../command/club/newsletter/newsletterCommand";
|
|
||||||
import NewsletterCommandHandler from "../../../command/club/newsletter/newsletterCommandHandler";
|
|
||||||
import { SynchronizeNewsletterDatesCommand } from "../../../command/club/newsletter/newsletterDatesCommand";
|
|
||||||
import NewsletterDatesCommandHandler from "../../../command/club/newsletter/newsletterDatesCommandHandler";
|
|
||||||
import { SynchronizeNewsletterRecipientsCommand } from "../../../command/club/newsletter/newsletterRecipientsCommand";
|
|
||||||
import NewsletterRecipientsCommandHandler from "../../../command/club/newsletter/newsletterRecipientsCommandHandler";
|
|
||||||
import { NewsletterDatesViewModel } from "../../../viewmodel/admin/club/newsletter/newsletterDates.models";
|
|
||||||
import { PdfExport } from "../../../helpers/pdfExport";
|
|
||||||
import UserService from "../../../service/user/userService";
|
|
||||||
import { TemplateHelper } from "../../../helpers/templateHelper";
|
|
||||||
import MailHelper from "../../../helpers/mailHelper";
|
|
||||||
import { NewsletterEventType, NewsletterHelper } from "../../../helpers/newsletterHelper";
|
|
||||||
import { Salutation } from "../../../enums/salutation";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description get all newsletters
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function getAllNewsletters(req: Request, res: Response): Promise<any> {
|
|
||||||
let offset = parseInt((req.query.offset as string) ?? "0");
|
|
||||||
let count = parseInt((req.query.count as string) ?? "25");
|
|
||||||
let [newsletters, total] = await NewsletterService.getAll(offset, count);
|
|
||||||
|
|
||||||
res.json({
|
|
||||||
newsletters: NewsletterFactory.mapToBase(newsletters),
|
|
||||||
total: total,
|
|
||||||
offset: offset,
|
|
||||||
count: count,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description get newsletter by id
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function getNewsletterById(req: Request, res: Response): Promise<any> {
|
|
||||||
let id = parseInt(req.params.id);
|
|
||||||
let newsletter = await NewsletterService.getById(id);
|
|
||||||
|
|
||||||
res.json(NewsletterFactory.mapToSingle(newsletter));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description get newsletter dates by id
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function getNewsletterDatesById(req: Request, res: Response): Promise<any> {
|
|
||||||
let newsletterId = parseInt(req.params.newsletterId);
|
|
||||||
|
|
||||||
let dates = await NewsletterDatesService.getAll(newsletterId);
|
|
||||||
|
|
||||||
res.json(NewsletterDatesFactory.mapToBase(dates));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description get newsletter recipients by id
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function getNewsletterRecipientsById(req: Request, res: Response): Promise<any> {
|
|
||||||
let newsletterId = parseInt(req.params.newsletterId);
|
|
||||||
|
|
||||||
let recipients = await NewsletterRecipientsService.getAll(newsletterId);
|
|
||||||
|
|
||||||
res.json(NewsletterRecipientsFactory.mapToBase(recipients));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description get newsletter printouts by id
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function getNewsletterPrintoutsById(req: Request, res: Response): Promise<any> {
|
|
||||||
let newsletterId = parseInt(req.params.newsletterId);
|
|
||||||
|
|
||||||
let newsletter = await NewsletterService.getById(newsletterId);
|
|
||||||
|
|
||||||
let filesInFolder = FileSystemHelper.getFilesInDirectory(
|
|
||||||
`newsletter/${newsletter.id}_${newsletter.title.replace(" ", "")}`
|
|
||||||
);
|
|
||||||
|
|
||||||
res.json(filesInFolder);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description get newsletter printout by id and print
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function getNewsletterPrintoutByIdAndPrint(req: Request, res: Response): Promise<any> {
|
|
||||||
let newsletterId = parseInt(req.params.newsletterId);
|
|
||||||
let filename = req.params.filename;
|
|
||||||
|
|
||||||
let newsletter = await NewsletterService.getById(newsletterId);
|
|
||||||
|
|
||||||
let filepath = FileSystemHelper.formatPath(
|
|
||||||
"newsletter",
|
|
||||||
`${newsletter.id}_${newsletter.title.replace(" ", "")}`,
|
|
||||||
filename
|
|
||||||
);
|
|
||||||
|
|
||||||
res.sendFile(filepath, {
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/pdf",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description create newsletter printout preview by id
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function createNewsletterPrintoutPreviewById(req: Request, res: Response): Promise<any> {
|
|
||||||
let newsletterId = parseInt(req.params.newsletterId);
|
|
||||||
let newsletter = await NewsletterService.getById(newsletterId);
|
|
||||||
let dates = await NewsletterDatesService.getAll(newsletterId);
|
|
||||||
let recipient = await UserService.getById(parseInt(req.userId));
|
|
||||||
|
|
||||||
let data = NewsletterHelper.buildData(newsletter, dates);
|
|
||||||
data.recipient = {
|
|
||||||
firstname: recipient.firstname,
|
|
||||||
lastname: recipient.lastname,
|
|
||||||
salutation: Salutation.none,
|
|
||||||
nameaffix: "",
|
|
||||||
street: "Straße",
|
|
||||||
streetNumber: "Hausnummer",
|
|
||||||
streetNumberAdd: "Adresszusatz",
|
|
||||||
};
|
|
||||||
|
|
||||||
let pdf = await PdfExport.renderFile({
|
|
||||||
title: "Probedruck Newsletter",
|
|
||||||
template: "newsletter",
|
|
||||||
saveToDisk: false,
|
|
||||||
data: data,
|
|
||||||
});
|
|
||||||
|
|
||||||
let pdfbuffer = Buffer.from(pdf);
|
|
||||||
|
|
||||||
res.setHeader("Content-Type", "application/pdf");
|
|
||||||
res.setHeader("Content-Length", pdfbuffer.byteLength);
|
|
||||||
res.setHeader("Content-Disposition", "inline; filename=preview.pdf");
|
|
||||||
|
|
||||||
res.send(pdfbuffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description create newsletter
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function createNewsletter(req: Request, res: Response): Promise<any> {
|
|
||||||
let title = req.body.title;
|
|
||||||
|
|
||||||
let createNewsletter: CreateNewsletterCommand = {
|
|
||||||
title,
|
|
||||||
};
|
|
||||||
let id = await NewsletterCommandHandler.create(createNewsletter);
|
|
||||||
|
|
||||||
res.send(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description get newsletter printout progress by id
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function getNewsletterPrintoutProgressById(req: Request, res: Response): Promise<any> {
|
|
||||||
let newsletterId = parseInt(req.params.newsletterId);
|
|
||||||
|
|
||||||
res.writeHead(200, {
|
|
||||||
"Content-Type": "text/plain",
|
|
||||||
"Transfer-Encoding": "chunked",
|
|
||||||
});
|
|
||||||
|
|
||||||
const progressHandler = (data: NewsletterEventType) => {
|
|
||||||
if (data.newsletterId == newsletterId && data.kind == "pdf") {
|
|
||||||
res.write(JSON.stringify(data) + "//");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const completeHandler = (data: NewsletterEventType) => {
|
|
||||||
if (data.newsletterId == newsletterId && data.kind == "pdf") {
|
|
||||||
res.write(JSON.stringify(data));
|
|
||||||
res.end();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
NewsletterHelper.jobStatus.on("progress", progressHandler);
|
|
||||||
NewsletterHelper.jobStatus.on("complete", completeHandler);
|
|
||||||
|
|
||||||
req.on("close", () => {
|
|
||||||
NewsletterHelper.jobStatus.off("progress", progressHandler);
|
|
||||||
NewsletterHelper.jobStatus.off("complete", completeHandler);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description create newsletter printouts for each member by id
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function createNewsletterPrintoutById(req: Request, res: Response): Promise<any> {
|
|
||||||
let newsletterId = parseInt(req.params.newsletterId);
|
|
||||||
|
|
||||||
await NewsletterHelper.printPdfs(newsletterId);
|
|
||||||
|
|
||||||
res.sendStatus(204);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description create newsletter mail preview by id
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function createNewsletterMailPreviewById(req: Request, res: Response): Promise<any> {
|
|
||||||
let newsletterId = parseInt(req.params.newsletterId);
|
|
||||||
let newsletter = await NewsletterService.getById(newsletterId);
|
|
||||||
let dates = await NewsletterDatesService.getAll(newsletterId);
|
|
||||||
let recipient = await UserService.getById(parseInt(req.userId));
|
|
||||||
|
|
||||||
let data = NewsletterHelper.buildData(newsletter, dates);
|
|
||||||
data.recipient = {
|
|
||||||
firstname: recipient.firstname,
|
|
||||||
lastname: recipient.lastname,
|
|
||||||
salutation: Salutation.none,
|
|
||||||
nameaffix: "",
|
|
||||||
street: "Straße",
|
|
||||||
streetNumber: "Hausnummer",
|
|
||||||
streetNumberAdd: "Adresszusatz",
|
|
||||||
};
|
|
||||||
|
|
||||||
const { body } = await TemplateHelper.renderFileForModule({
|
|
||||||
module: "newsletter",
|
|
||||||
bodyData: data,
|
|
||||||
title: "Probeversand Newsletter",
|
|
||||||
});
|
|
||||||
|
|
||||||
await MailHelper.sendMail(recipient.mail, "Probeversand Newsletter", body);
|
|
||||||
|
|
||||||
res.sendStatus(204);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description send newsletter mail and create printouts by id
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function sendNewsletterById(req: Request, res: Response): Promise<any> {
|
|
||||||
let newsletterId = parseInt(req.params.newsletterId);
|
|
||||||
|
|
||||||
await NewsletterHelper.sendMails(newsletterId);
|
|
||||||
|
|
||||||
res.sendStatus(204);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description get newsletter sending progress by id
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function getNewsletterSendingProgressById(req: Request, res: Response): Promise<any> {
|
|
||||||
let newsletterId = parseInt(req.params.newsletterId);
|
|
||||||
|
|
||||||
res.writeHead(200, {
|
|
||||||
"Content-Type": "text/plain",
|
|
||||||
"Transfer-Encoding": "chunked",
|
|
||||||
});
|
|
||||||
|
|
||||||
const progressHandler = (data: NewsletterEventType) => {
|
|
||||||
if (data.newsletterId == newsletterId && data.kind == "mail") {
|
|
||||||
res.write(JSON.stringify(data) + "//");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const completeHandler = (data: NewsletterEventType) => {
|
|
||||||
if (data.newsletterId == newsletterId && data.kind == "mail") {
|
|
||||||
res.write(JSON.stringify(data));
|
|
||||||
res.end();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
NewsletterHelper.jobStatus.on("progress", progressHandler);
|
|
||||||
NewsletterHelper.jobStatus.on("complete", completeHandler);
|
|
||||||
|
|
||||||
req.on("close", () => {
|
|
||||||
NewsletterHelper.jobStatus.off("progress", progressHandler);
|
|
||||||
NewsletterHelper.jobStatus.off("complete", completeHandler);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description synchronize newsletter by id
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function synchronizeNewsletterById(req: Request, res: Response): Promise<any> {
|
|
||||||
let id = parseInt(req.params.id);
|
|
||||||
let title = req.body.title;
|
|
||||||
let description = req.body.description;
|
|
||||||
let newsletterTitle = req.body.newsletterTitle;
|
|
||||||
let newsletterText = req.body.newsletterText;
|
|
||||||
let newsletterSignatur = req.body.newsletterSignatur;
|
|
||||||
let recipientsByQueryId = req.body.recipientsByQueryId ?? null;
|
|
||||||
|
|
||||||
let syncNewsletter: SynchronizeNewsletterCommand = {
|
|
||||||
id,
|
|
||||||
title,
|
|
||||||
description,
|
|
||||||
newsletterTitle,
|
|
||||||
newsletterText,
|
|
||||||
newsletterSignatur,
|
|
||||||
recipientsByQueryId,
|
|
||||||
};
|
|
||||||
await NewsletterCommandHandler.sync(syncNewsletter);
|
|
||||||
|
|
||||||
res.sendStatus(204);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description synchronize newsletter dates by id
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function synchronizeNewsletterDatesById(req: Request, res: Response): Promise<any> {
|
|
||||||
let newsletterId = parseInt(req.params.newsletterId);
|
|
||||||
let dates = req.body.dates as Array<NewsletterDatesViewModel>;
|
|
||||||
|
|
||||||
let syncDates: SynchronizeNewsletterDatesCommand = {
|
|
||||||
newsletterId,
|
|
||||||
dates: dates.map((d) => ({
|
|
||||||
calendarId: d.calendarId,
|
|
||||||
diffTitle: d.diffTitle,
|
|
||||||
diffDescription: d.diffDescription,
|
|
||||||
})),
|
|
||||||
};
|
|
||||||
await NewsletterDatesCommandHandler.sync(syncDates);
|
|
||||||
|
|
||||||
res.sendStatus(204);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description synchronize newsletter recipients by id
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function synchronizeNewsletterRecipientsById(req: Request, res: Response): Promise<any> {
|
|
||||||
let newsletterId = parseInt(req.params.newsletterId);
|
|
||||||
let recipients = req.body.recipients as Array<number>;
|
|
||||||
|
|
||||||
let syncRecipients: SynchronizeNewsletterRecipientsCommand = {
|
|
||||||
newsletterId,
|
|
||||||
recipients: recipients,
|
|
||||||
};
|
|
||||||
await NewsletterRecipientsCommandHandler.sync(syncRecipients);
|
|
||||||
|
|
||||||
res.sendStatus(204);
|
|
||||||
}
|
|
|
@ -1,401 +0,0 @@
|
||||||
import { Request, Response } from "express";
|
|
||||||
import ProtocolService from "../../../service/club/protocol/protocolService";
|
|
||||||
import ProtocolFactory from "../../../factory/admin/club/protocol/protocol";
|
|
||||||
import ProtocolAgendaService from "../../../service/club/protocol/protocolAgendaService";
|
|
||||||
import ProtocolAgendaFactory from "../../../factory/admin/club/protocol/protocolAgenda";
|
|
||||||
import ProtocolDecisionService from "../../../service/club/protocol/protocolDecisionService";
|
|
||||||
import ProtocolDecisionFactory from "../../../factory/admin/club/protocol/protocolDecision";
|
|
||||||
import ProtocolPresenceService from "../../../service/club/protocol/protocolPrecenseService";
|
|
||||||
import ProtocolPresenceFactory from "../../../factory/admin/club/protocol/protocolPresence";
|
|
||||||
import ProtocolVotingService from "../../../service/club/protocol/protocolVotingService";
|
|
||||||
import ProtocolVotingFactory from "../../../factory/admin/club/protocol/protocolVoting";
|
|
||||||
import { CreateProtocolCommand, SynchronizeProtocolCommand } from "../../../command/club/protocol/protocolCommand";
|
|
||||||
import ProtocolCommandHandler from "../../../command/club/protocol/protocolCommandHandler";
|
|
||||||
import { SynchronizeProtocolAgendaCommand } from "../../../command/club/protocol/protocolAgendaCommand";
|
|
||||||
import ProtocolAgendaCommandHandler from "../../../command/club/protocol/protocolAgendaCommandHandler";
|
|
||||||
import { ProtocolAgendaViewModel } from "../../../viewmodel/admin/club/protocol/protocolAgenda.models";
|
|
||||||
import ProtocolDecisionCommandHandler from "../../../command/club/protocol/protocolDecisionCommandHandler";
|
|
||||||
import { ProtocolDecisionViewModel } from "../../../viewmodel/admin/club/protocol/protocolDecision.models";
|
|
||||||
import ProtocolPresenceCommandHandler from "../../../command/club/protocol/protocolPresenceCommandHandler";
|
|
||||||
import { SynchronizeProtocolPresenceCommand } from "../../../command/club/protocol/protocolPresenceCommand";
|
|
||||||
import { SynchronizeProtocolDecisionCommand } from "../../../command/club/protocol/protocolDecisionCommand";
|
|
||||||
import { SynchronizeProtocolVotingCommand } from "../../../command/club/protocol/protocolVotingCommand";
|
|
||||||
import { ProtocolVotingViewModel } from "../../../viewmodel/admin/club/protocol/protocolVoting.models";
|
|
||||||
import ProtocolVotingCommandHandler from "../../../command/club/protocol/protocolVotingCommandHandler";
|
|
||||||
import { PdfExport } from "../../../helpers/pdfExport";
|
|
||||||
import ProtocolPrintoutService from "../../../service/club/protocol/protocolPrintoutService";
|
|
||||||
import ProtocolPrintoutFactory from "../../../factory/admin/club/protocol/protocolPrintout";
|
|
||||||
import { CreateProtocolPrintoutCommand } from "../../../command/club/protocol/protocolPrintoutCommand";
|
|
||||||
import ProtocolPrintoutCommandHandler from "../../../command/club/protocol/protocolPrintoutCommandHandler";
|
|
||||||
import { FileSystemHelper } from "../../../helpers/fileSystemHelper";
|
|
||||||
import { ProtocolPresenceViewModel } from "../../../viewmodel/admin/club/protocol/protocolPresence.models";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description get all protocols
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function getAllProtocols(req: Request, res: Response): Promise<any> {
|
|
||||||
let offset = parseInt((req.query.offset as string) ?? "0");
|
|
||||||
let count = parseInt((req.query.count as string) ?? "25");
|
|
||||||
let [protocols, total] = await ProtocolService.getAll(offset, count);
|
|
||||||
|
|
||||||
res.json({
|
|
||||||
protocols: ProtocolFactory.mapToBase(protocols),
|
|
||||||
total: total,
|
|
||||||
offset: offset,
|
|
||||||
count: count,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description get protocol by id
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function getProtocolById(req: Request, res: Response): Promise<any> {
|
|
||||||
let id = parseInt(req.params.id);
|
|
||||||
let protocol = await ProtocolService.getById(id);
|
|
||||||
|
|
||||||
res.json(ProtocolFactory.mapToSingle(protocol));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description get protocol agenda by id
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function getProtocolAgendaById(req: Request, res: Response): Promise<any> {
|
|
||||||
let protocolId = parseInt(req.params.protocolId);
|
|
||||||
|
|
||||||
let agenda = await ProtocolAgendaService.getAll(protocolId);
|
|
||||||
|
|
||||||
res.json(ProtocolAgendaFactory.mapToBase(agenda));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description get protocol decisions by id
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function getProtocolDecisonsById(req: Request, res: Response): Promise<any> {
|
|
||||||
let protocolId = parseInt(req.params.protocolId);
|
|
||||||
|
|
||||||
let decisions = await ProtocolDecisionService.getAll(protocolId);
|
|
||||||
|
|
||||||
res.json(ProtocolDecisionFactory.mapToBase(decisions));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description get protocol precense by id
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function getProtocolPrecenseById(req: Request, res: Response): Promise<any> {
|
|
||||||
let protocolId = parseInt(req.params.protocolId);
|
|
||||||
|
|
||||||
let presence = await ProtocolPresenceService.getAll(protocolId);
|
|
||||||
|
|
||||||
res.json(ProtocolPresenceFactory.mapToBase(presence));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description get protocol votings by id
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function getProtocolVotingsById(req: Request, res: Response): Promise<any> {
|
|
||||||
let protocolId = parseInt(req.params.protocolId);
|
|
||||||
|
|
||||||
let votings = await ProtocolVotingService.getAll(protocolId);
|
|
||||||
|
|
||||||
res.json(ProtocolVotingFactory.mapToBase(votings));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description get protocol printouts by id
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function getProtocolPrintoutsById(req: Request, res: Response): Promise<any> {
|
|
||||||
let protocolId = parseInt(req.params.protocolId);
|
|
||||||
|
|
||||||
let printouts = await ProtocolPrintoutService.getAll(protocolId);
|
|
||||||
|
|
||||||
res.json(ProtocolPrintoutFactory.mapToBase(printouts));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description get protocol printout by id and print
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function getProtocolPrintoutByIdAndPrint(req: Request, res: Response): Promise<any> {
|
|
||||||
let protocolId = parseInt(req.params.protocolId);
|
|
||||||
let printoutId = parseInt(req.params.printoutId);
|
|
||||||
|
|
||||||
let printout = await ProtocolPrintoutService.getById(printoutId, protocolId);
|
|
||||||
|
|
||||||
let filepath = FileSystemHelper.formatPath("protocol", printout.filename);
|
|
||||||
|
|
||||||
res.sendFile(filepath, {
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/pdf",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description create protocol
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function createProtocol(req: Request, res: Response): Promise<any> {
|
|
||||||
let title = req.body.title;
|
|
||||||
let date = req.body.date;
|
|
||||||
|
|
||||||
let createProtocol: CreateProtocolCommand = {
|
|
||||||
title,
|
|
||||||
date,
|
|
||||||
};
|
|
||||||
let id = await ProtocolCommandHandler.create(createProtocol);
|
|
||||||
|
|
||||||
res.send(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description create protocol agenda by id
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function createProtocolAgendaById(req: Request, res: Response): Promise<any> {
|
|
||||||
let protocolId = parseInt(req.params.protocolId);
|
|
||||||
|
|
||||||
let agenda = await ProtocolAgendaCommandHandler.create(protocolId);
|
|
||||||
|
|
||||||
res.send(agenda);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description create protocol decisions by id
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function createProtocolDecisonsById(req: Request, res: Response): Promise<any> {
|
|
||||||
let protocolId = parseInt(req.params.protocolId);
|
|
||||||
|
|
||||||
let decision = await ProtocolDecisionCommandHandler.create(protocolId);
|
|
||||||
|
|
||||||
res.send(decision);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description create protocol votings by id
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function createProtocolVotingsById(req: Request, res: Response): Promise<any> {
|
|
||||||
let protocolId = parseInt(req.params.protocolId);
|
|
||||||
|
|
||||||
let voting = await ProtocolVotingCommandHandler.create(protocolId);
|
|
||||||
|
|
||||||
res.send(voting);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description create protocol printout by id
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function createProtocolPrintoutById(req: Request, res: Response): Promise<any> {
|
|
||||||
let protocolId = parseInt(req.params.protocolId);
|
|
||||||
let protocol = await ProtocolService.getById(protocolId);
|
|
||||||
let agenda = await ProtocolAgendaService.getAll(protocolId);
|
|
||||||
let decisions = await ProtocolDecisionService.getAll(protocolId);
|
|
||||||
let presence = await ProtocolPresenceService.getAll(protocolId);
|
|
||||||
let votings = await ProtocolVotingService.getAll(protocolId);
|
|
||||||
let iteration = await ProtocolPrintoutService.getCount(protocolId);
|
|
||||||
|
|
||||||
let title = `${protocol.title} - ${new Date(protocol.date).toLocaleDateString("de-DE", {
|
|
||||||
day: "2-digit",
|
|
||||||
month: "long",
|
|
||||||
year: "numeric",
|
|
||||||
})}`;
|
|
||||||
|
|
||||||
let filename = `${new Date().toISOString().split("T")[0]}_${iteration + 1}_Protokoll_${protocol.title.replace(
|
|
||||||
/[^a-zA-Z0-9]/g,
|
|
||||||
""
|
|
||||||
)}`;
|
|
||||||
|
|
||||||
await PdfExport.renderFile({
|
|
||||||
template: "protocol",
|
|
||||||
title,
|
|
||||||
filename,
|
|
||||||
folder: "protocol",
|
|
||||||
data: {
|
|
||||||
title: protocol.title,
|
|
||||||
summary: protocol.summary,
|
|
||||||
iteration: iteration + 1,
|
|
||||||
date: new Date(protocol.date).toLocaleDateString("de-DE", {
|
|
||||||
weekday: "long",
|
|
||||||
day: "2-digit",
|
|
||||||
month: "2-digit",
|
|
||||||
year: "numeric",
|
|
||||||
}),
|
|
||||||
start: protocol.starttime,
|
|
||||||
end: protocol.endtime,
|
|
||||||
agenda,
|
|
||||||
decisions,
|
|
||||||
presence: presence.filter((p) => !p.absent).map((p) => p.member),
|
|
||||||
absent: presence.filter((p) => p.absent).map((p) => ({ ...p.member, excused: p.excused })),
|
|
||||||
excused_absent: presence.filter((p) => p.absent && p.excused).map((p) => p.member),
|
|
||||||
unexcused_absent: presence.filter((p) => p.absent && !p.excused).map((p) => p.member),
|
|
||||||
votings,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
let printout: CreateProtocolPrintoutCommand = {
|
|
||||||
title,
|
|
||||||
iteration: iteration + 1,
|
|
||||||
filename: `${filename}.pdf`,
|
|
||||||
protocolId,
|
|
||||||
};
|
|
||||||
await ProtocolPrintoutCommandHandler.create(printout);
|
|
||||||
|
|
||||||
res.sendStatus(204);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description synchronize protocol by id
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function synchronizeProtocolById(req: Request, res: Response): Promise<any> {
|
|
||||||
let id = parseInt(req.params.id);
|
|
||||||
let title = req.body.title;
|
|
||||||
let date = req.body.date;
|
|
||||||
let starttime = req.body.starttime;
|
|
||||||
let endtime = req.body.endtime;
|
|
||||||
let summary = req.body.summary;
|
|
||||||
|
|
||||||
let syncProtocol: SynchronizeProtocolCommand = {
|
|
||||||
id,
|
|
||||||
title,
|
|
||||||
date,
|
|
||||||
starttime,
|
|
||||||
endtime,
|
|
||||||
summary,
|
|
||||||
};
|
|
||||||
await ProtocolCommandHandler.sync(syncProtocol);
|
|
||||||
|
|
||||||
res.sendStatus(204);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description synchronize protocol agenda by id
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function synchronizeProtocolAgendaById(req: Request, res: Response): Promise<any> {
|
|
||||||
let protocolId = parseInt(req.params.protocolId);
|
|
||||||
let agenda = req.body.agenda as Array<ProtocolAgendaViewModel>;
|
|
||||||
|
|
||||||
let syncAgenda: Array<SynchronizeProtocolAgendaCommand> = agenda.map(
|
|
||||||
(a: ProtocolAgendaViewModel): SynchronizeProtocolAgendaCommand => ({
|
|
||||||
id: a.id ?? null,
|
|
||||||
topic: a.topic,
|
|
||||||
context: a.context,
|
|
||||||
protocolId,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
await ProtocolAgendaCommandHandler.sync(syncAgenda);
|
|
||||||
|
|
||||||
res.sendStatus(204);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description synchronize protocol decisions by id
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function synchronizeProtocolDecisonsById(req: Request, res: Response): Promise<any> {
|
|
||||||
let protocolId = parseInt(req.params.protocolId);
|
|
||||||
let decisions = req.body.decisions as Array<ProtocolDecisionViewModel>;
|
|
||||||
|
|
||||||
let syncDecision: Array<SynchronizeProtocolDecisionCommand> = decisions.map(
|
|
||||||
(d: ProtocolDecisionViewModel): SynchronizeProtocolDecisionCommand => ({
|
|
||||||
id: d.id ?? null,
|
|
||||||
topic: d.topic,
|
|
||||||
context: d.context,
|
|
||||||
protocolId,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
await ProtocolDecisionCommandHandler.sync(syncDecision);
|
|
||||||
|
|
||||||
res.sendStatus(204);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description synchronize protocol votings by id
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function synchronizeProtocolVotingsById(req: Request, res: Response): Promise<any> {
|
|
||||||
let protocolId = parseInt(req.params.protocolId);
|
|
||||||
let votings = req.body.votings as Array<ProtocolVotingViewModel>;
|
|
||||||
|
|
||||||
let syncVoting: Array<SynchronizeProtocolVotingCommand> = votings.map(
|
|
||||||
(d: ProtocolVotingViewModel): SynchronizeProtocolVotingCommand => ({
|
|
||||||
id: d.id ?? null,
|
|
||||||
topic: d.topic,
|
|
||||||
context: d.context,
|
|
||||||
favour: d.favour,
|
|
||||||
abstain: d.abstain,
|
|
||||||
against: d.abstain,
|
|
||||||
protocolId,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
await ProtocolVotingCommandHandler.sync(syncVoting);
|
|
||||||
|
|
||||||
res.sendStatus(204);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description synchronize protocol precense by id
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function synchronizeProtocolPrecenseById(req: Request, res: Response): Promise<any> {
|
|
||||||
let protocolId = parseInt(req.params.protocolId);
|
|
||||||
let presence = req.body.presence as Array<ProtocolPresenceViewModel>;
|
|
||||||
|
|
||||||
let syncPresence: SynchronizeProtocolPresenceCommand = {
|
|
||||||
members: presence.map((p) => ({
|
|
||||||
memberId: p.memberId,
|
|
||||||
absent: p.absent,
|
|
||||||
excused: p.excused,
|
|
||||||
})),
|
|
||||||
protocolId,
|
|
||||||
};
|
|
||||||
await ProtocolPresenceCommandHandler.sync(syncPresence);
|
|
||||||
|
|
||||||
res.sendStatus(204);
|
|
||||||
}
|
|
|
@ -1,44 +0,0 @@
|
||||||
import { Request, Response } from "express";
|
|
||||||
import DynamicQueryBuilder from "../../../helpers/dynamicQueryBuilder";
|
|
||||||
import { dataSource } from "../../../data-source";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description get all table metas
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function getAllTableMeta(req: Request, res: Response): Promise<any> {
|
|
||||||
let tableMetas = DynamicQueryBuilder.getAllTableMeta();
|
|
||||||
|
|
||||||
res.json(tableMetas);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description get meta by tablename
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function getTableMetaByTablename(req: Request, res: Response): Promise<any> {
|
|
||||||
const tablename = req.params.tablename;
|
|
||||||
let tableMeta = DynamicQueryBuilder.getTableMeta(tablename);
|
|
||||||
|
|
||||||
res.json(tableMeta);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description execute Query
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function executeQuery(req: Request, res: Response): Promise<any> {
|
|
||||||
let offset = parseInt((req.query.offset as string) ?? "0");
|
|
||||||
let count = parseInt((req.query.count as string) ?? "25");
|
|
||||||
const query = req.body.query;
|
|
||||||
|
|
||||||
let result = await DynamicQueryBuilder.executeQuery(query, offset, count);
|
|
||||||
|
|
||||||
res.json(result);
|
|
||||||
}
|
|
|
@ -1,13 +1,13 @@
|
||||||
import { Request, Response } from "express";
|
import { Request, Response } from "express";
|
||||||
import CommunicationTypeService from "../../../service/settings/communicationTypeService";
|
import CommunicationTypeService from "../../service/communicationTypeService";
|
||||||
import CommunicationTypeFactory from "../../../factory/admin/settings/communicationType";
|
import CommunicationTypeFactory from "../../factory/admin/communicationType";
|
||||||
import CommunicationService from "../../../service/club/member/communicationService";
|
import CommunicationService from "../../service/communicationService";
|
||||||
import {
|
import {
|
||||||
CreateCommunicationTypeCommand,
|
CreateCommunicationTypeCommand,
|
||||||
DeleteCommunicationTypeCommand,
|
DeleteCommunicationTypeCommand,
|
||||||
UpdateCommunicationTypeCommand,
|
UpdateCommunicationTypeCommand,
|
||||||
} from "../../../command/settings/communicationType/communicationTypeCommand";
|
} from "../../command/communicationTypeCommand";
|
||||||
import CommunicationTypeCommandHandler from "../../../command/settings/communicationType/communicationTypeCommandHandler";
|
import CommunicationTypeCommandHandler from "../../command/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/settings/executivePositionService";
|
import ExecutivePositionService from "../../service/executivePositionService";
|
||||||
import ExecutivePositionFactory from "../../../factory/admin/settings/executivePosition";
|
import ExecutivePositionFactory from "../../factory/admin/executivePosition";
|
||||||
import {
|
import {
|
||||||
CreateExecutivePositionCommand,
|
CreateExecutivePositionCommand,
|
||||||
DeleteExecutivePositionCommand,
|
DeleteExecutivePositionCommand,
|
||||||
UpdateExecutivePositionCommand,
|
UpdateExecutivePositionCommand,
|
||||||
} from "../../../command/settings/executivePosition/executivePositionCommand";
|
} from "../../command/executivePositionCommand";
|
||||||
import ExecutivePositionCommandHandler from "../../../command/settings/executivePosition/executivePositionCommandHandler";
|
import ExecutivePositionCommandHandler from "../../command/executivePositionCommandHandler";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description get all executivePositions
|
* @description get all executivePositions
|
161
src/controller/admin/exportController.ts
Normal file
161
src/controller/admin/exportController.ts
Normal file
|
@ -0,0 +1,161 @@
|
||||||
|
import { Request, Response } from "express";
|
||||||
|
import MemberService from "../../service/memberService";
|
||||||
|
import AwardService from "../../service/awardService";
|
||||||
|
import CommunicationTypeService from "../../service/communicationTypeService";
|
||||||
|
import ExecutivePositionService from "../../service/executivePositionService";
|
||||||
|
import crypto from "crypto";
|
||||||
|
import { type BinaryLike } from "node:crypto";
|
||||||
|
import { CreateAwardCommand } from "../../command/awardCommand";
|
||||||
|
import AwardCommandHandler from "../../command/awardCommandHandler";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description get all data stored in the database as a single json object
|
||||||
|
* @param req {Request} Express req object
|
||||||
|
* @param res {Response} Express res object
|
||||||
|
* @returns {Promise<*>}
|
||||||
|
*/
|
||||||
|
export async function getDatabaseExport(req: Request, res: Response): Promise<any> {
|
||||||
|
const noEncryption = req.headers["x-encrypt-no"];
|
||||||
|
|
||||||
|
const secret = req.headers["x-encrypt-with"];
|
||||||
|
try {
|
||||||
|
if (!secret && !noEncryption) {
|
||||||
|
res.status(400).send("Empty encryption key");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let data: any = {};
|
||||||
|
|
||||||
|
console.log("Exporting awards...");
|
||||||
|
data.awards = await AwardService.getAll();
|
||||||
|
console.log(`Exported ${data.awards.length} awards`);
|
||||||
|
console.log("Exporting communication types...");
|
||||||
|
data.communicationTypes = await CommunicationTypeService.getAll();
|
||||||
|
console.log(`Exported ${data.communicationTypes.length} communicationTypes`);
|
||||||
|
console.log("Exporting executivePositions...");
|
||||||
|
data.executivePositions = await ExecutivePositionService.getAll();
|
||||||
|
console.log(`Exported ${data.executivePositions.length} executivePositions`);
|
||||||
|
console.log("Exporting members...");
|
||||||
|
data.members = await MemberService.getAll();
|
||||||
|
console.log(`Exported ${data.members.length} members`);
|
||||||
|
|
||||||
|
if (noEncryption) {
|
||||||
|
console.log(`Sending data unencrypted with length ${data.length}`);
|
||||||
|
res.json({
|
||||||
|
encrypted: !noEncryption,
|
||||||
|
data: data,
|
||||||
|
});
|
||||||
|
console.log("finished encrypted data");
|
||||||
|
} else {
|
||||||
|
const dataStr: string = JSON.stringify(data);
|
||||||
|
console.log(`Encrypting data...`);
|
||||||
|
const iv = await new Promise((resolve, reject) => {
|
||||||
|
// create initialization vector
|
||||||
|
crypto.randomBytes(16, (err, iv) => {
|
||||||
|
if (err) {
|
||||||
|
reject(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
resolve(iv);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
// encrypt data
|
||||||
|
let base64Key = crypto.createHash("sha256").update(String(secret)).digest("base64");
|
||||||
|
const key = Buffer.from(base64Key, "base64");
|
||||||
|
|
||||||
|
// create initialization vector
|
||||||
|
const randomIV: Buffer = await new Promise((resolve, reject) => {
|
||||||
|
crypto.randomBytes(16, (err, iv) => {
|
||||||
|
if (err) {
|
||||||
|
reject(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
resolve(iv);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
// console.log(`iv: ${randomIV.toString('hex')}`);
|
||||||
|
// console.log(`key: ${key.toString('hex')}`);
|
||||||
|
|
||||||
|
let cipher = crypto.createCipheriv("aes-256-gcm", key, randomIV);
|
||||||
|
const encryptedData: string = cipher.update(dataStr, "utf8", "hex") + cipher.final("hex");
|
||||||
|
const authTag = cipher.getAuthTag().toString("hex");
|
||||||
|
|
||||||
|
// console.log(`authTag: ${authTag}`);
|
||||||
|
console.log(`Sending encrypted data with length ${encryptedData.length}`);
|
||||||
|
res.json({
|
||||||
|
encrypted: !noEncryption,
|
||||||
|
iv: randomIV.toString("base64"),
|
||||||
|
data: encryptedData,
|
||||||
|
authTag: authTag,
|
||||||
|
});
|
||||||
|
console.log("finished encrypted data");
|
||||||
|
}
|
||||||
|
} catch (ex) {
|
||||||
|
console.log(ex);
|
||||||
|
res.status(500).send(ex.message ? ex.message : "Exception!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description decrypt the import data and use it to re-fill the database
|
||||||
|
* @param req {Request} Express req object
|
||||||
|
* @param res {Response} Express res object
|
||||||
|
* @returns {Promise<*>}
|
||||||
|
*/
|
||||||
|
export async function importDatabaseExport(req: Request, res: Response): Promise<any> {
|
||||||
|
const { data: receivedData } = req.body;
|
||||||
|
if (!receivedData) {
|
||||||
|
res.status(400).send("Empty database import data");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const noEncryption = req.headers["x-encrypt-no"];
|
||||||
|
try {
|
||||||
|
let data;
|
||||||
|
if (noEncryption) {
|
||||||
|
data = receivedData;
|
||||||
|
} else {
|
||||||
|
const secret = req.headers["x-decrypt-with"];
|
||||||
|
const { iv, authTag } = req.body;
|
||||||
|
if (!secret) {
|
||||||
|
res.status(400).send("Empty decryption key");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!iv) {
|
||||||
|
res.status(400).send("Empty database import iv");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!authTag) {
|
||||||
|
res.status(400).send("Empty database import authTag");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// prepare the secret to be in a buffer
|
||||||
|
const base64Key = crypto.createHash("sha256").update(String(secret)).digest("base64");
|
||||||
|
const key = Buffer.from(base64Key, "base64");
|
||||||
|
|
||||||
|
// decrypt data
|
||||||
|
const ivString = Buffer.from(iv, "base64");
|
||||||
|
// console.log(`iv: ${ivString.toString('hex')}`);
|
||||||
|
// console.log(`key: ${key.toString('hex')}`);
|
||||||
|
// console.log(`authTag: ${authTag}`);
|
||||||
|
const decipher = crypto.createDecipheriv("aes-256-gcm", key, ivString);
|
||||||
|
decipher.setAuthTag(Buffer.from(authTag, "hex"));
|
||||||
|
const decrypted = decipher.update(receivedData, "hex", "utf-8") + decipher.final("utf-8");
|
||||||
|
data = JSON.parse(decrypted.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const award of data.awards) {
|
||||||
|
let createAward: CreateAwardCommand = {
|
||||||
|
award: award,
|
||||||
|
};
|
||||||
|
const awardId: any = await AwardCommandHandler.create(createAward);
|
||||||
|
console.log(`Award with id ${awardId} created`);
|
||||||
|
}
|
||||||
|
|
||||||
|
res.send(200);
|
||||||
|
} catch (ex) {
|
||||||
|
console.log(ex);
|
||||||
|
res.status(500).send(ex.message ? ex.message : "Exception!");
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,55 +1,53 @@
|
||||||
import { Request, Response } from "express";
|
import { Request, Response } from "express";
|
||||||
import MemberService from "../../../service/club/member/memberService";
|
import MemberService from "../../service/memberService";
|
||||||
import MemberFactory from "../../../factory/admin/club/member/member";
|
import MemberFactory from "../../factory/admin/member";
|
||||||
import MembershipService from "../../../service/club/member/membershipService";
|
import MembershipService from "../../service/membershipService";
|
||||||
import MembershipFactory from "../../../factory/admin/club/member/membership";
|
import MembershipFactory from "../../factory/admin/membership";
|
||||||
import MemberAwardService from "../../../service/club/member/memberAwardService";
|
import MemberAwardService from "../../service/memberAwardService";
|
||||||
import MemberAwardFactory from "../../../factory/admin/club/member/memberAward";
|
import MemberAwardFactory from "../../factory/admin/memberAward";
|
||||||
import MemberQualificationService from "../../../service/club/member/memberQualificationService";
|
import MemberQualificationService from "../../service/memberQualificationService";
|
||||||
import MemberQualificationFactory from "../../../factory/admin/club/member/memberQualification";
|
import MemberQualificationFactory from "../../factory/admin/memberQualification";
|
||||||
import MemberExecutivePositionService from "../../../service/club/member/memberExecutivePositionService";
|
import MemberExecutivePositionService from "../../service/memberExecutivePositionService";
|
||||||
import MemberExecutivePositionFactory from "../../../factory/admin/club/member/memberExecutivePosition";
|
import MemberExecutivePositionFactory from "../../factory/admin/memberExecutivePosition";
|
||||||
import CommunicationService from "../../../service/club/member/communicationService";
|
import CommunicationService from "../../service/communicationService";
|
||||||
import CommunicationFactory from "../../../factory/admin/club/member/communication";
|
import CommunicationFactory from "../../factory/admin/communication";
|
||||||
import {
|
import {
|
||||||
CreateMemberCommand,
|
CreateMemberCommand,
|
||||||
DeleteMemberCommand,
|
DeleteMemberCommand,
|
||||||
UpdateMemberCommand,
|
UpdateMemberCommand,
|
||||||
UpdateMemberNewsletterCommand,
|
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/club/member/membershipCommand";
|
} from "../../command/membershipCommand";
|
||||||
import MembershipCommandHandler from "../../../command/club/member/membershipCommandHandler";
|
import MembershipCommandHandler from "../../command/membershipCommandHandler";
|
||||||
import {
|
import {
|
||||||
CreateMemberAwardCommand,
|
CreateMemberAwardCommand,
|
||||||
DeleteMemberAwardCommand,
|
DeleteMemberAwardCommand,
|
||||||
UpdateMemberAwardCommand,
|
UpdateMemberAwardCommand,
|
||||||
} from "../../../command/club/member/memberAwardCommand";
|
} from "../../command/memberAwardCommand";
|
||||||
import MemberAwardCommandHandler from "../../../command/club/member/memberAwardCommandHandler";
|
import MemberAwardCommandHandler from "../../command/memberAwardCommandHandler";
|
||||||
import {
|
import {
|
||||||
CreateMemberExecutivePositionCommand,
|
CreateMemberExecutivePositionCommand,
|
||||||
DeleteMemberExecutivePositionCommand,
|
DeleteMemberExecutivePositionCommand,
|
||||||
UpdateMemberExecutivePositionCommand,
|
UpdateMemberExecutivePositionCommand,
|
||||||
} from "../../../command/club/member/memberExecutivePositionCommand";
|
} from "../../command/memberExecutivePositionCommand";
|
||||||
import MemberExecutivePositionCommandHandler from "../../../command/club/member/memberExecutivePositionCommandHandler";
|
import MemberExecutivePositionCommandHandler from "../../command/memberExecutivePositionCommandHandler";
|
||||||
import {
|
import {
|
||||||
CreateMemberQualificationCommand,
|
CreateMemberQualificationCommand,
|
||||||
DeleteMemberQualificationCommand,
|
DeleteMemberQualificationCommand,
|
||||||
UpdateMemberQualificationCommand,
|
UpdateMemberQualificationCommand,
|
||||||
} from "../../../command/club/member/memberQualificationCommand";
|
} from "../../command/memberQualificationCommand";
|
||||||
import MemberQualificationCommandHandler from "../../../command/club/member/memberQualificationCommandHandler";
|
import MemberQualificationCommandHandler from "../../command/memberQualificationCommandHandler";
|
||||||
import {
|
import {
|
||||||
CreateCommunicationCommand,
|
CreateCommunicationCommand,
|
||||||
DeleteCommunicationCommand,
|
DeleteCommunicationCommand,
|
||||||
UpdateCommunicationCommand,
|
UpdateCommunicationCommand,
|
||||||
} from "../../../command/club/member/communicationCommand";
|
} from "../../command/communicationCommand";
|
||||||
import CommunicationCommandHandler from "../../../command/club/member/communicationCommandHandler";
|
import CommunicationCommandHandler from "../../command/communicationCommandHandler";
|
||||||
import { PdfExport } from "../../../helpers/pdfExport";
|
|
||||||
import { PermissionModule } from "../../../type/permissionTypes";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description get all members
|
* @description get all members
|
||||||
|
@ -60,14 +58,7 @@ import { PermissionModule } from "../../../type/permissionTypes";
|
||||||
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 search = (req.query.search as string) ?? "";
|
let [members, total] = await MemberService.getAll(offset, count);
|
||||||
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),
|
||||||
|
@ -90,19 +81,6 @@ 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
|
||||||
|
@ -116,19 +94,6 @@ 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
|
||||||
|
@ -251,33 +216,6 @@ 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
|
||||||
|
@ -290,7 +228,6 @@ export async function createMember(req: Request, res: Response): Promise<any> {
|
||||||
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,
|
salutation,
|
||||||
|
@ -298,7 +235,6 @@ export async function createMember(req: Request, res: Response): Promise<any> {
|
||||||
lastname,
|
lastname,
|
||||||
nameaffix,
|
nameaffix,
|
||||||
birthdate,
|
birthdate,
|
||||||
internalId,
|
|
||||||
};
|
};
|
||||||
let memberId = await MemberCommandHandler.create(createMember);
|
let memberId = await MemberCommandHandler.create(createMember);
|
||||||
|
|
||||||
|
@ -313,10 +249,12 @@ 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,
|
||||||
|
@ -408,10 +346,8 @@ 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 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;
|
||||||
|
@ -421,10 +357,8 @@ export async function addCommunicationToMember(req: Request, res: Response): Pro
|
||||||
|
|
||||||
let createCommunication: CreateCommunicationCommand = {
|
let createCommunication: CreateCommunicationCommand = {
|
||||||
preferred,
|
preferred,
|
||||||
isSMSAlarming,
|
|
||||||
mobile,
|
mobile,
|
||||||
email,
|
email,
|
||||||
postalCode,
|
|
||||||
city,
|
city,
|
||||||
street,
|
street,
|
||||||
streetNumber,
|
streetNumber,
|
||||||
|
@ -458,7 +392,6 @@ export async function updateMemberById(req: Request, res: Response): Promise<any
|
||||||
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,
|
||||||
|
@ -467,7 +400,6 @@ export async function updateMemberById(req: Request, res: Response): Promise<any
|
||||||
lastname,
|
lastname,
|
||||||
nameaffix,
|
nameaffix,
|
||||||
birthdate,
|
birthdate,
|
||||||
internalId,
|
|
||||||
};
|
};
|
||||||
await MemberCommandHandler.update(updateMember);
|
await MemberCommandHandler.update(updateMember);
|
||||||
|
|
||||||
|
@ -483,6 +415,7 @@ 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;
|
||||||
|
@ -490,6 +423,7 @@ 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,
|
||||||
|
@ -594,23 +528,20 @@ 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 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;
|
const isNewsletterMain = req.body.isNewsletterMain;
|
||||||
|
|
||||||
let updateCommunication: UpdateCommunicationCommand = {
|
let updateCommunication: UpdateCommunicationCommand = {
|
||||||
id: recordId,
|
id: recordId,
|
||||||
preferred,
|
preferred,
|
||||||
isSMSAlarming,
|
|
||||||
mobile,
|
mobile,
|
||||||
email,
|
email,
|
||||||
postalCode,
|
|
||||||
city,
|
city,
|
||||||
street,
|
street,
|
||||||
streetNumber,
|
streetNumber,
|
||||||
|
@ -619,16 +550,12 @@ export async function updateCommunicationOfMember(req: Request, res: Response):
|
||||||
};
|
};
|
||||||
await CommunicationCommandHandler.update(updateCommunication);
|
await CommunicationCommandHandler.update(updateCommunication);
|
||||||
|
|
||||||
let currentUserNewsletterMain = await MemberService.getNewsletterById(memberId);
|
|
||||||
|
|
||||||
if (isNewsletterMain) {
|
if (isNewsletterMain) {
|
||||||
let updateNewsletter: UpdateMemberNewsletterCommand = {
|
let updateNewsletter: UpdateMemberNewsletterCommand = {
|
||||||
id: memberId,
|
id: memberId,
|
||||||
communicationId: recordId,
|
communicationId: recordId,
|
||||||
};
|
};
|
||||||
await MemberCommandHandler.updateNewsletter(updateNewsletter);
|
await MemberCommandHandler.updateNewsletter(updateNewsletter);
|
||||||
} else if (currentUserNewsletterMain.sendNewsletter?.id == recordId) {
|
|
||||||
await MemberCommandHandler.unsetNewsletter(memberId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
res.sendStatus(204);
|
res.sendStatus(204);
|
|
@ -1,12 +1,12 @@
|
||||||
import { Request, Response } from "express";
|
import { Request, Response } from "express";
|
||||||
import MembershipStatusService from "../../../service/settings/membershipStatusService";
|
import MembershipStatusService from "../../service/membershipStatusService";
|
||||||
import MembershipStatusFactory from "../../../factory/admin/settings/membershipStatus";
|
import MembershipStatusFactory from "../../factory/admin/membershipStatus";
|
||||||
import {
|
import {
|
||||||
CreateMembershipStatusCommand,
|
CreateMembershipStatusCommand,
|
||||||
DeleteMembershipStatusCommand,
|
DeleteMembershipStatusCommand,
|
||||||
UpdateMembershipStatusCommand,
|
UpdateMembershipStatusCommand,
|
||||||
} from "../../../command/settings/membershipStatus/membershipStatusCommand";
|
} from "../../command/membershipStatusCommand";
|
||||||
import MembershipStatusCommandHandler from "../../../command/settings/membershipStatus/membershipStatusCommandHandler";
|
import MembershipStatusCommandHandler from "../../command/membershipStatusCommandHandler";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description get all membershipStatus
|
* @description get all membershipStatus
|
|
@ -1,12 +1,12 @@
|
||||||
import { Request, Response } from "express";
|
import { Request, Response } from "express";
|
||||||
import QualificationService from "../../../service/settings/qualification";
|
import QualificationService from "../../service/qualification";
|
||||||
import QualificationFactory from "../../../factory/admin/settings/qualification";
|
import QualificationFactory from "../../factory/admin/qualification";
|
||||||
import {
|
import {
|
||||||
CreateQualificationCommand,
|
CreateQualificationCommand,
|
||||||
DeleteQualificationCommand,
|
DeleteQualificationCommand,
|
||||||
UpdateQualificationCommand,
|
UpdateQualificationCommand,
|
||||||
} from "../../../command/settings/qualification/qualificationCommand";
|
} from "../../command/qualificationCommand";
|
||||||
import QualificationCommandHandler from "../../../command/settings/qualification/qualificationCommandHandler";
|
import QualificationCommandHandler from "../../command/qualificationCommandHandler";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description get all qualifications
|
* @description get all qualifications
|
|
@ -1,12 +1,12 @@
|
||||||
import { Request, Response } from "express";
|
import { Request, Response } from "express";
|
||||||
import RoleService from "../../../service/user/roleService";
|
import RoleService from "../../service/roleService";
|
||||||
import RoleFactory from "../../../factory/admin/user/role";
|
import RoleFactory from "../../factory/admin/role";
|
||||||
import RolePermissionService from "../../../service/user/rolePermissionService";
|
import RolePermissionService from "../../service/rolePermissionService";
|
||||||
import PermissionHelper from "../../../helpers/permissionHelper";
|
import PermissionHelper from "../../helpers/permissionHelper";
|
||||||
import { CreateRoleCommand, DeleteRoleCommand, UpdateRoleCommand } from "../../../command/user/role/roleCommand";
|
import { CreateRoleCommand, DeleteRoleCommand, UpdateRoleCommand } from "../../command/roleCommand";
|
||||||
import RoleCommandHandler from "../../../command/user/role/roleCommandHandler";
|
import RoleCommandHandler from "../../command/roleCommandHandler";
|
||||||
import { UpdateRolePermissionsCommand } from "../../../command/user/role/rolePermissionCommand";
|
import { UpdateRolePermissionsCommand } from "../../command/rolePermissionCommand";
|
||||||
import RolePermissionCommandHandler from "../../../command/user/role/rolePermissionCommandHandler";
|
import RolePermissionCommandHandler from "../../command/rolePermissionCommandHandler";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description get All roles
|
* @description get All roles
|
|
@ -1,49 +0,0 @@
|
||||||
import { Request, Response } from "express";
|
|
||||||
import NewsletterConfigService from "../../../service/settings/newsletterConfigService";
|
|
||||||
import NewsletterConfigFactory from "../../../factory/admin/settings/newsletterConfig";
|
|
||||||
import NewsletterConfigCommandHandler from "../../../command/settings/newsletterConfig/newsletterConfigCommandHandler";
|
|
||||||
import { SetNewsletterConfigCommand } from "../../../command/settings/newsletterConfig/newsletterConfigCommand";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description get all newsletterConfigs
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function getAllNewsletterConfigs(req: Request, res: Response): Promise<any> {
|
|
||||||
let newsletterConfigs = await NewsletterConfigService.getAll();
|
|
||||||
|
|
||||||
res.json(NewsletterConfigFactory.mapToBase(newsletterConfigs));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description get newsletterConfig by id
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function getNewsletterConfigById(req: Request, res: Response): Promise<any> {
|
|
||||||
let comId = parseInt(req.params.comId);
|
|
||||||
let newsletterConfig = await NewsletterConfigService.getByComId(comId);
|
|
||||||
|
|
||||||
res.json(NewsletterConfigFactory.mapToSingle(newsletterConfig));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description set newsletterConfig
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function setNewsletterConfig(req: Request, res: Response): Promise<any> {
|
|
||||||
let comTypeId = req.body.comTypeId;
|
|
||||||
let config = req.body.config;
|
|
||||||
|
|
||||||
let createNewsletterConfig: SetNewsletterConfigCommand = {
|
|
||||||
comTypeId,
|
|
||||||
config,
|
|
||||||
};
|
|
||||||
let id = await NewsletterConfigCommandHandler.set(createNewsletterConfig);
|
|
||||||
|
|
||||||
res.send(id);
|
|
||||||
}
|
|
|
@ -1,93 +0,0 @@
|
||||||
import { Request, Response } from "express";
|
|
||||||
import QueryStoreFactory from "../../../factory/admin/settings/queryStore";
|
|
||||||
import QueryStoreService from "../../../service/settings/queryStoreService";
|
|
||||||
import {
|
|
||||||
CreateQueryStoreCommand,
|
|
||||||
DeleteQueryStoreCommand,
|
|
||||||
UpdateQueryStoreCommand,
|
|
||||||
} from "../../../command/settings/queryStore/queryStoreCommand";
|
|
||||||
import QueryStoreCommandHandler from "../../../command/settings/queryStore/queryStoreCommandHandler";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description get all queryStores
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function getAllQueryStores(req: Request, res: Response): Promise<any> {
|
|
||||||
let queryStores = await QueryStoreService.getAll();
|
|
||||||
|
|
||||||
res.json(QueryStoreFactory.mapToBase(queryStores));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description get queryStore by id
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function getQueryStoreById(req: Request, res: Response): Promise<any> {
|
|
||||||
const id = parseInt(req.params.id);
|
|
||||||
|
|
||||||
let queryStore = await QueryStoreService.getById(id);
|
|
||||||
|
|
||||||
res.json(QueryStoreFactory.mapToSingle(queryStore));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description create new queryStore
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function createQueryStore(req: Request, res: Response): Promise<any> {
|
|
||||||
const query = req.body.query;
|
|
||||||
const title = req.body.title;
|
|
||||||
|
|
||||||
let createQueryStore: CreateQueryStoreCommand = {
|
|
||||||
title: title,
|
|
||||||
query: query,
|
|
||||||
};
|
|
||||||
|
|
||||||
let id = await QueryStoreCommandHandler.create(createQueryStore);
|
|
||||||
|
|
||||||
res.status(200).send(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description update queryStore
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function updateQueryStore(req: Request, res: Response): Promise<any> {
|
|
||||||
const id = parseInt(req.params.id);
|
|
||||||
const query = req.body.query;
|
|
||||||
|
|
||||||
let updateQueryStore: UpdateQueryStoreCommand = {
|
|
||||||
id: id,
|
|
||||||
query: query,
|
|
||||||
};
|
|
||||||
|
|
||||||
await QueryStoreCommandHandler.update(updateQueryStore);
|
|
||||||
|
|
||||||
res.sendStatus(204);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description delete queryStore
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function deleteQueryStore(req: Request, res: Response): Promise<any> {
|
|
||||||
const id = parseInt(req.params.id);
|
|
||||||
|
|
||||||
let deleteQueryStore: DeleteQueryStoreCommand = {
|
|
||||||
id: id,
|
|
||||||
};
|
|
||||||
|
|
||||||
await QueryStoreCommandHandler.delete(deleteQueryStore);
|
|
||||||
|
|
||||||
res.sendStatus(204);
|
|
||||||
}
|
|
|
@ -1,120 +0,0 @@
|
||||||
import { Request, Response } from "express";
|
|
||||||
import TemplateService from "../../../service/settings/templateService";
|
|
||||||
import TemplateFactory from "../../../factory/admin/settings/template";
|
|
||||||
import { CreateTemplateCommand, DeleteTemplateCommand, UpdateTemplateCommand } from "../../../command/settings/template/templateCommand";
|
|
||||||
import TemplateCommandHandler from "../../../command/settings/template/templateCommandHandler";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description get all templates
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function getAllTemplates(req: Request, res: Response): Promise<any> {
|
|
||||||
let templates = await TemplateService.getAll();
|
|
||||||
|
|
||||||
res.json(TemplateFactory.mapToBase(templates));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description get template by id
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function getTemplateById(req: Request, res: Response): Promise<any> {
|
|
||||||
const id = parseInt(req.params.id);
|
|
||||||
let template = await TemplateService.getById(id);
|
|
||||||
|
|
||||||
res.json(TemplateFactory.mapToSingle(template));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description create new template
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function createTemplate(req: Request, res: Response): Promise<any> {
|
|
||||||
const template = req.body.template;
|
|
||||||
const description = req.body.description;
|
|
||||||
|
|
||||||
let createTemplate: CreateTemplateCommand = {
|
|
||||||
template: template,
|
|
||||||
description: description,
|
|
||||||
};
|
|
||||||
let id = await TemplateCommandHandler.create(createTemplate);
|
|
||||||
|
|
||||||
res.status(200).send(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description clone template
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function cloneTemplate(req: Request, res: Response): Promise<any> {
|
|
||||||
const cloneId = req.body.cloneId;
|
|
||||||
|
|
||||||
const { template, description, design, html } = await TemplateService.getById(cloneId);
|
|
||||||
|
|
||||||
let createTemplate: CreateTemplateCommand = {
|
|
||||||
template: "",
|
|
||||||
description: "",
|
|
||||||
};
|
|
||||||
let id = await TemplateCommandHandler.create(createTemplate);
|
|
||||||
|
|
||||||
let updateTemplate: UpdateTemplateCommand = {
|
|
||||||
id: id,
|
|
||||||
template: template + " - Kopie",
|
|
||||||
description: description,
|
|
||||||
design: design,
|
|
||||||
html: html,
|
|
||||||
};
|
|
||||||
await TemplateCommandHandler.update(updateTemplate);
|
|
||||||
|
|
||||||
res.status(200).send(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description update template
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function updateTemplate(req: Request, res: Response): Promise<any> {
|
|
||||||
const id = parseInt(req.params.id);
|
|
||||||
const template = req.body.template;
|
|
||||||
const description = req.body.description;
|
|
||||||
const design = req.body.design;
|
|
||||||
const html = req.body.html;
|
|
||||||
|
|
||||||
let updateTemplate: UpdateTemplateCommand = {
|
|
||||||
id: id,
|
|
||||||
template: template,
|
|
||||||
description: description,
|
|
||||||
design: design,
|
|
||||||
html: html,
|
|
||||||
};
|
|
||||||
await TemplateCommandHandler.update(updateTemplate);
|
|
||||||
|
|
||||||
res.sendStatus(204);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description delete template
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function deleteTemplate(req: Request, res: Response): Promise<any> {
|
|
||||||
const id = parseInt(req.params.id);
|
|
||||||
|
|
||||||
let deleteTemplate: DeleteTemplateCommand = {
|
|
||||||
id: id,
|
|
||||||
};
|
|
||||||
await TemplateCommandHandler.delete(deleteTemplate);
|
|
||||||
|
|
||||||
res.sendStatus(204);
|
|
||||||
}
|
|
|
@ -1,95 +0,0 @@
|
||||||
import { Request, Response } from "express";
|
|
||||||
import TemplateUsageService from "../../../service/settings/templateUsageService";
|
|
||||||
import TemplateUsageFactory from "../../../factory/admin/settings/templateUsage";
|
|
||||||
import { UpdateTemplateUsageCommand } from "../../../command/settings/templateUsage/templateUsageCommand";
|
|
||||||
import TemplateUsageCommandHandler from "../../../command/settings/templateUsage/templateUsageCommandHandler";
|
|
||||||
import PermissionHelper from "../../../helpers/permissionHelper";
|
|
||||||
import ForbiddenRequestException from "../../../exceptions/forbiddenRequestException";
|
|
||||||
import { PermissionModule } from "../../../type/permissionTypes";
|
|
||||||
import { PdfExport } from "../../../helpers/pdfExport";
|
|
||||||
import { DemoDataHelper } from "../../../helpers/demoDataHelper";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description get all templateUsages
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function getAllTemplateUsages(req: Request, res: Response): Promise<any> {
|
|
||||||
let templateUsages = await TemplateUsageService.getAll();
|
|
||||||
|
|
||||||
if (!req.isOwner) {
|
|
||||||
templateUsages = templateUsages.filter((tu) => {
|
|
||||||
return (
|
|
||||||
PermissionHelper.can(req.permissions, "update", "settings", tu.scope.split(".")[0] as PermissionModule) ||
|
|
||||||
PermissionHelper.can(req.permissions, "update", "club", tu.scope.split(".")[0] as PermissionModule)
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
res.json(TemplateUsageFactory.mapToBase(templateUsages));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description print demo of templateUsage
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function printTemplateUsageDemo(req: Request, res: Response): Promise<any> {
|
|
||||||
const scope = req.params.scope as PermissionModule;
|
|
||||||
|
|
||||||
let demoData = DemoDataHelper.getData(scope);
|
|
||||||
let pdf = await PdfExport.renderFile({
|
|
||||||
template: scope,
|
|
||||||
saveToDisk: false,
|
|
||||||
data: demoData,
|
|
||||||
});
|
|
||||||
|
|
||||||
let pdfbuffer = Buffer.from(pdf);
|
|
||||||
|
|
||||||
res.setHeader("Content-Type", "application/pdf");
|
|
||||||
res.setHeader("Content-Length", pdfbuffer.byteLength);
|
|
||||||
res.setHeader("Content-Disposition", "inline; filename=preview.pdf");
|
|
||||||
|
|
||||||
res.send(pdfbuffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description update templateUsage
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function updateTemplateUsage(req: Request, res: Response): Promise<any> {
|
|
||||||
const scope = req.params.scope;
|
|
||||||
let allowedSettings = PermissionHelper.can(
|
|
||||||
req.permissions,
|
|
||||||
"update",
|
|
||||||
"settings",
|
|
||||||
req.params.scope as PermissionModule
|
|
||||||
);
|
|
||||||
let allowedClub = PermissionHelper.can(req.permissions, "update", "club", req.params.scope as PermissionModule);
|
|
||||||
|
|
||||||
if (!(req.isOwner || allowedSettings || allowedClub)) {
|
|
||||||
throw new ForbiddenRequestException(`missing permission for editing scope ${req.params.scope}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const headerId = req.body.headerId ?? null;
|
|
||||||
const bodyId = req.body.bodyId ?? null;
|
|
||||||
const footerId = req.body.footerId ?? null;
|
|
||||||
const headerHeight = req.body.headerHeight ?? null;
|
|
||||||
const footerHeight = req.body.footerHeight ?? null;
|
|
||||||
|
|
||||||
let updateTemplateUsage: UpdateTemplateUsageCommand = {
|
|
||||||
scope: scope,
|
|
||||||
headerId: headerId,
|
|
||||||
bodyId: bodyId,
|
|
||||||
footerId: footerId,
|
|
||||||
headerHeight: headerHeight,
|
|
||||||
footerHeight: footerHeight,
|
|
||||||
};
|
|
||||||
await TemplateUsageCommandHandler.update(updateTemplateUsage);
|
|
||||||
|
|
||||||
res.sendStatus(204);
|
|
||||||
}
|
|
|
@ -1,155 +0,0 @@
|
||||||
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);
|
|
||||||
}
|
|
|
@ -1,15 +1,15 @@
|
||||||
import { Request, Response } from "express";
|
import { Request, Response } from "express";
|
||||||
import UserService from "../../../service/user/userService";
|
import UserService from "../../service/userService";
|
||||||
import UserFactory from "../../../factory/admin/user/user";
|
import UserFactory from "../../factory/admin/user";
|
||||||
import UserPermissionService from "../../../service/user/userPermissionService";
|
import UserPermissionService from "../../service/userPermissionService";
|
||||||
import PermissionHelper from "../../../helpers/permissionHelper";
|
import PermissionHelper from "../../helpers/permissionHelper";
|
||||||
import RoleFactory from "../../../factory/admin/user/role";
|
import RoleFactory from "../../factory/admin/role";
|
||||||
import { DeleteUserCommand, UpdateUserCommand, UpdateUserRolesCommand } from "../../../command/user/user/userCommand";
|
import { DeleteUserCommand, UpdateUserCommand, UpdateUserRolesCommand } from "../../command/userCommand";
|
||||||
import UserCommandHandler from "../../../command/user/user/userCommandHandler";
|
import UserCommandHandler from "../../command/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/user/user/userPermissionCommand";
|
import { UpdateUserPermissionsCommand } from "../../command/userPermissionCommand";
|
||||||
import UserPermissionCommandHandler from "../../../command/user/user/userPermissionCommandHandler";
|
import UserPermissionCommandHandler from "../../command/userPermissionCommandHandler";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description get All users
|
* @description get All users
|
||||||
|
@ -146,7 +146,8 @@ export async function deleteUser(req: Request, res: Response): Promise<any> {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// sendmail
|
// sendmail
|
||||||
await MailHelper.sendMail(
|
let mailhelper = new MailHelper();
|
||||||
|
await mailhelper.sendMail(
|
||||||
user.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.`
|
|
@ -4,10 +4,13 @@ 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/user/userService";
|
import UserService from "../service/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
|
||||||
|
@ -19,7 +22,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 } = await UserService.getByUsername(username);
|
let { id, secret, mail, firstname, lastname } = await UserService.getByUsername(username);
|
||||||
|
|
||||||
let valid = speakeasy.totp.verify({
|
let valid = speakeasy.totp.verify({
|
||||||
secret: secret,
|
secret: secret,
|
||||||
|
@ -32,13 +35,38 @@ 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 accessToken = await JWTHelper.buildToken(id);
|
let userPermissions = await UserPermissionService.getByUser(id);
|
||||||
|
let userPermissionStrings = userPermissions.map((e) => e.permission);
|
||||||
|
let userRoles = await UserService.getAssignedRolesByUserId(id);
|
||||||
|
let rolePermissions = userRoles.length != 0 ? await RolePermissionService.getByRoles(userRoles.map((e) => e.id)) : [];
|
||||||
|
let rolePermissionStrings = rolePermissions.map((e) => e.permission);
|
||||||
|
let permissionObject = PermissionHelper.convertToObject([...userPermissionStrings, ...rolePermissionStrings]);
|
||||||
|
|
||||||
|
let jwtData: JWTToken = {
|
||||||
|
userId: id,
|
||||||
|
mail: mail,
|
||||||
|
username: username,
|
||||||
|
firstname: firstname,
|
||||||
|
lastname: lastname,
|
||||||
|
permissions: permissionObject,
|
||||||
|
};
|
||||||
|
|
||||||
|
let accessToken: string;
|
||||||
|
let refreshToken: string;
|
||||||
|
|
||||||
|
JWTHelper.create(jwtData)
|
||||||
|
.then((result) => {
|
||||||
|
accessToken = result;
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(err);
|
||||||
|
throw new InternalException("Failed accessToken creation", err);
|
||||||
|
});
|
||||||
|
|
||||||
let refreshCommand: CreateRefreshCommand = {
|
let refreshCommand: CreateRefreshCommand = {
|
||||||
userId: id,
|
userId: id,
|
||||||
isFromPwa: req.isPWA,
|
|
||||||
};
|
};
|
||||||
let refreshToken = await RefreshCommandHandler.create(refreshCommand);
|
refreshToken = await RefreshCommandHandler.create(refreshCommand);
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
accessToken,
|
accessToken,
|
||||||
|
@ -77,16 +105,39 @@ export async function refresh(req: Request, res: Response): Promise<any> {
|
||||||
throw new UnauthorizedRequestException("user not identified with token and refresh");
|
throw new UnauthorizedRequestException("user not identified with token and refresh");
|
||||||
}
|
}
|
||||||
|
|
||||||
let accessToken = await JWTHelper.buildToken(tokenUserId);
|
let { id, username, mail, firstname, lastname } = await UserService.getById(tokenUserId);
|
||||||
|
|
||||||
|
let permissions = await UserPermissionService.getByUser(id);
|
||||||
|
let permissionStrings = permissions.map((e) => e.permission);
|
||||||
|
let permissionObject = PermissionHelper.convertToObject(permissionStrings);
|
||||||
|
|
||||||
|
let jwtData: JWTToken = {
|
||||||
|
userId: id,
|
||||||
|
mail: mail,
|
||||||
|
username: username,
|
||||||
|
firstname: firstname,
|
||||||
|
lastname: lastname,
|
||||||
|
permissions: permissionObject,
|
||||||
|
};
|
||||||
|
|
||||||
|
let accessToken: string;
|
||||||
|
let refreshToken: string;
|
||||||
|
|
||||||
|
JWTHelper.create(jwtData)
|
||||||
|
.then((result) => {
|
||||||
|
accessToken = result;
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
throw new InternalException("Failed accessToken creation", err);
|
||||||
|
});
|
||||||
|
|
||||||
let refreshCommand: CreateRefreshCommand = {
|
let refreshCommand: CreateRefreshCommand = {
|
||||||
userId: tokenUserId,
|
userId: id,
|
||||||
isFromPwa: req.isPWA,
|
|
||||||
};
|
};
|
||||||
let refreshToken = await RefreshCommandHandler.create(refreshCommand);
|
refreshToken = await RefreshCommandHandler.create(refreshCommand);
|
||||||
|
|
||||||
let removeToken: DeleteRefreshCommand = {
|
let removeToken: DeleteRefreshCommand = {
|
||||||
userId: tokenUserId,
|
userId: id,
|
||||||
token: refresh,
|
token: refresh,
|
||||||
};
|
};
|
||||||
await RefreshCommandHandler.deleteByToken(removeToken);
|
await RefreshCommandHandler.deleteByToken(removeToken);
|
||||||
|
|
|
@ -7,30 +7,17 @@ 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/user/user/userCommand";
|
import { CreateUserCommand } from "../command/userCommand";
|
||||||
import UserCommandHandler from "../command/user/user/userCommandHandler";
|
import UserCommandHandler from "../command/userCommandHandler";
|
||||||
import { CreateInviteCommand, DeleteInviteCommand } from "../command/user/user/inviteCommand";
|
import { CreateInviteCommand, DeleteInviteCommand } from "../command/inviteCommand";
|
||||||
import InviteCommandHandler from "../command/user/user/inviteCommandHandler";
|
import InviteCommandHandler from "../command/inviteCommandHandler";
|
||||||
import MailHelper from "../helpers/mailHelper";
|
import MailHelper from "../helpers/mailHelper";
|
||||||
import InviteService from "../service/user/inviteService";
|
import InviteService from "../service/inviteService";
|
||||||
import UserService from "../service/user/userService";
|
import UserService from "../service/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/user/user/userPermissionCommand";
|
import { CreateUserPermissionCommand } from "../command/userPermissionCommand";
|
||||||
import UserPermissionCommandHandler from "../command/user/user/userPermissionCommandHandler";
|
import UserPermissionCommandHandler from "../command/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
|
||||||
|
@ -71,7 +58,8 @@ export async function inviteUser(req: Request, res: Response, isInvite: boolean
|
||||||
let token = await InviteCommandHandler.create(createInvite);
|
let token = await InviteCommandHandler.create(createInvite);
|
||||||
|
|
||||||
// sendmail
|
// sendmail
|
||||||
await MailHelper.sendMail(
|
let mailhelper = new MailHelper();
|
||||||
|
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}`
|
||||||
|
@ -90,7 +78,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, username } = await InviteService.getByMailAndToken(mail, token);
|
let { secret } = await InviteService.getByMailAndToken(mail, token);
|
||||||
|
|
||||||
const url = `otpauth://totp/Mitgliederverwaltung ${CLUB_NAME}?secret=${secret}`;
|
const url = `otpauth://totp/Mitgliederverwaltung ${CLUB_NAME}?secret=${secret}`;
|
||||||
|
|
||||||
|
@ -99,7 +87,6 @@ export async function verifyInvite(req: Request, res: Response): Promise<any> {
|
||||||
res.json({
|
res.json({
|
||||||
dataUrl: result,
|
dataUrl: result,
|
||||||
otp: secret,
|
otp: secret,
|
||||||
username,
|
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
|
@ -137,16 +124,43 @@ 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);
|
||||||
|
|
||||||
let accessToken = await JWTHelper.buildToken(id);
|
if (grantAdmin) {
|
||||||
|
let createPermission: CreateUserPermissionCommand = {
|
||||||
|
permission: "*",
|
||||||
|
userId: id,
|
||||||
|
};
|
||||||
|
await UserPermissionCommandHandler.create(createPermission);
|
||||||
|
}
|
||||||
|
|
||||||
|
let jwtData: JWTToken = {
|
||||||
|
userId: id,
|
||||||
|
mail: mail,
|
||||||
|
username: username,
|
||||||
|
firstname: firstname,
|
||||||
|
lastname: lastname,
|
||||||
|
permissions: {
|
||||||
|
...(grantAdmin ? { admin: true } : {}),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
let accessToken: string;
|
||||||
|
let refreshToken: string;
|
||||||
|
|
||||||
|
JWTHelper.create(jwtData)
|
||||||
|
.then((result) => {
|
||||||
|
accessToken = result;
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
throw new InternalException("Failed accessToken creation", err);
|
||||||
|
});
|
||||||
|
|
||||||
let refreshCommand: CreateRefreshCommand = {
|
let refreshCommand: CreateRefreshCommand = {
|
||||||
userId: id,
|
userId: id,
|
||||||
};
|
};
|
||||||
let refreshToken = await RefreshCommandHandler.create(refreshCommand);
|
refreshToken = await RefreshCommandHandler.create(refreshCommand);
|
||||||
|
|
||||||
let deleteInvite: DeleteInviteCommand = {
|
let deleteInvite: DeleteInviteCommand = {
|
||||||
mail: mail,
|
mail: mail,
|
||||||
|
@ -159,17 +173,3 @@ 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);
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,53 +0,0 @@
|
||||||
import { Request, Response } from "express";
|
|
||||||
import CalendarService from "../service/club/calendarService";
|
|
||||||
import CalendarTypeService from "../service/settings/calendarTypeService";
|
|
||||||
import { calendar } from "../entity/club/calendar";
|
|
||||||
import { createEvents } from "ics";
|
|
||||||
import moment from "moment";
|
|
||||||
import InternalException from "../exceptions/internalException";
|
|
||||||
import CalendarFactory from "../factory/admin/club/calendar";
|
|
||||||
import { CalendarHelper } from "../helpers/calendarHelper";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description get all calendar items by types or nscdr
|
|
||||||
* @summary passphrase is passed as value pair like `type:passphrase`
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function getCalendarItemsByTypes(req: Request, res: Response): Promise<any> {
|
|
||||||
let types = Array.isArray(req.query.types) ? req.query.types : [req.query.types];
|
|
||||||
let nscdr = req.query.nscdr == "true";
|
|
||||||
let output = (req.query.output as "ics" | "json") ?? "ics";
|
|
||||||
|
|
||||||
if (output != "ics" && output != "json") {
|
|
||||||
throw new InternalException("set output query value to `ics` or `json` (defaults to `ics`)");
|
|
||||||
}
|
|
||||||
|
|
||||||
types = types.filter((t) => t);
|
|
||||||
|
|
||||||
let items: Array<calendar> = [];
|
|
||||||
if (types.length != 0) {
|
|
||||||
let typeIds = await CalendarTypeService.getByTypes((types as Array<string>).map((t) => t.split(":")[0]));
|
|
||||||
typeIds = typeIds.filter(
|
|
||||||
(ti) =>
|
|
||||||
ti.passphrase == null ||
|
|
||||||
ti.passphrase == "" ||
|
|
||||||
ti.passphrase == (types as Array<string>).find((t) => t.includes(ti.type)).split(":")[1]
|
|
||||||
);
|
|
||||||
items = await CalendarService.getByTypes(
|
|
||||||
typeIds.map((t) => t.id),
|
|
||||||
nscdr
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
items = await CalendarService.getByTypeNSCDR();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (output == "json") {
|
|
||||||
res.json(CalendarFactory.mapToBase(items));
|
|
||||||
} else {
|
|
||||||
let { error, value } = CalendarHelper.buildICS(items);
|
|
||||||
|
|
||||||
res.type("ics").send(value);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,128 +0,0 @@
|
||||||
import { Request, Response } from "express";
|
|
||||||
import { JWTHelper } from "../helpers/jwtHelper";
|
|
||||||
import { JWTToken } from "../type/jwtTypes";
|
|
||||||
import InternalException from "../exceptions/internalException";
|
|
||||||
import RefreshCommandHandler from "../command/refreshCommandHandler";
|
|
||||||
import { CreateRefreshCommand } from "../command/refreshCommand";
|
|
||||||
import speakeasy from "speakeasy";
|
|
||||||
import UnauthorizedRequestException from "../exceptions/unauthorizedRequestException";
|
|
||||||
import QRCode from "qrcode";
|
|
||||||
import { CreateResetCommand, DeleteResetCommand } from "../command/resetCommand";
|
|
||||||
import ResetCommandHandler from "../command/resetCommandHandler";
|
|
||||||
import MailHelper from "../helpers/mailHelper";
|
|
||||||
import ResetService from "../service/resetService";
|
|
||||||
import UserService from "../service/user/userService";
|
|
||||||
import { CLUB_NAME } from "../env.defaults";
|
|
||||||
import PermissionHelper from "../helpers/permissionHelper";
|
|
||||||
import RolePermissionService from "../service/user/rolePermissionService";
|
|
||||||
import UserPermissionService from "../service/user/userPermissionService";
|
|
||||||
import { UpdateUserSecretCommand } from "../command/user/user/userCommand";
|
|
||||||
import UserCommandHandler from "../command/user/user/userCommandHandler";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description request totp reset
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function startReset(req: Request, res: Response): Promise<any> {
|
|
||||||
let origin = req.headers.origin;
|
|
||||||
let username = req.body.username;
|
|
||||||
|
|
||||||
let { mail } = await UserService.getByUsername(username);
|
|
||||||
|
|
||||||
var secret = speakeasy.generateSecret({ length: 20, name: `Mitgliederverwaltung ${CLUB_NAME}` });
|
|
||||||
|
|
||||||
let createReset: CreateResetCommand = {
|
|
||||||
username: username,
|
|
||||||
mail: mail,
|
|
||||||
secret: secret.base32,
|
|
||||||
};
|
|
||||||
let token = await ResetCommandHandler.create(createReset);
|
|
||||||
|
|
||||||
// sendmail
|
|
||||||
await MailHelper.sendMail(
|
|
||||||
mail,
|
|
||||||
`Email Bestätigung für Mitglieder Admin-Portal von ${CLUB_NAME}`,
|
|
||||||
`Öffne folgenden Link: ${origin}/reset/reset?mail=${mail}&token=${token}`
|
|
||||||
);
|
|
||||||
|
|
||||||
res.sendStatus(204);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description verify reset link
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function verifyReset(req: Request, res: Response): Promise<any> {
|
|
||||||
let mail = req.body.mail;
|
|
||||||
let token = req.body.token;
|
|
||||||
|
|
||||||
let { secret } = await ResetService.getByMailAndToken(mail, token);
|
|
||||||
|
|
||||||
const url = `otpauth://totp/Mitgliederverwaltung ${CLUB_NAME}?secret=${secret}`;
|
|
||||||
|
|
||||||
QRCode.toDataURL(url)
|
|
||||||
.then((result) => {
|
|
||||||
res.json({
|
|
||||||
dataUrl: result,
|
|
||||||
otp: secret,
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
throw new InternalException("QRCode not created", err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description finishReset
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function finishReset(req: Request, res: Response): Promise<any> {
|
|
||||||
let mail = req.body.mail;
|
|
||||||
let token = req.body.token;
|
|
||||||
let totp = req.body.totp;
|
|
||||||
|
|
||||||
let { secret, username } = await ResetService.getByMailAndToken(mail, token);
|
|
||||||
|
|
||||||
let valid = speakeasy.totp.verify({
|
|
||||||
secret: secret,
|
|
||||||
encoding: "base32",
|
|
||||||
token: totp,
|
|
||||||
window: 2,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!valid) {
|
|
||||||
throw new UnauthorizedRequestException("Token not valid or expired");
|
|
||||||
}
|
|
||||||
|
|
||||||
let { id } = await UserService.getByUsername(username);
|
|
||||||
|
|
||||||
let updateUserSecret: UpdateUserSecretCommand = {
|
|
||||||
id,
|
|
||||||
secret,
|
|
||||||
};
|
|
||||||
await UserCommandHandler.updateSecret(updateUserSecret);
|
|
||||||
|
|
||||||
let accessToken = await JWTHelper.buildToken(id);
|
|
||||||
|
|
||||||
let refreshCommand: CreateRefreshCommand = {
|
|
||||||
userId: id,
|
|
||||||
};
|
|
||||||
let refreshToken = await RefreshCommandHandler.create(refreshCommand);
|
|
||||||
|
|
||||||
let deleteReset: DeleteResetCommand = {
|
|
||||||
mail: mail,
|
|
||||||
token: token,
|
|
||||||
};
|
|
||||||
await ResetCommandHandler.deleteByTokenAndMail(deleteReset);
|
|
||||||
|
|
||||||
res.json({
|
|
||||||
accessToken,
|
|
||||||
refreshToken,
|
|
||||||
});
|
|
||||||
}
|
|
|
@ -1,121 +0,0 @@
|
||||||
import { Request, Response } from "express";
|
|
||||||
import speakeasy from "speakeasy";
|
|
||||||
import QRCode from "qrcode";
|
|
||||||
import InternalException from "../exceptions/internalException";
|
|
||||||
import { CLUB_NAME } from "../env.defaults";
|
|
||||||
import UserService from "../service/user/userService";
|
|
||||||
import UserFactory from "../factory/admin/user/user";
|
|
||||||
import { TransferUserOwnerCommand, UpdateUserCommand } from "../command/user/user/userCommand";
|
|
||||||
import UserCommandHandler from "../command/user/user/userCommandHandler";
|
|
||||||
import ForbiddenRequestException from "../exceptions/forbiddenRequestException";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description get my by id
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function getMeById(req: Request, res: Response): Promise<any> {
|
|
||||||
const id = parseInt(req.userId);
|
|
||||||
let user = await UserService.getById(id);
|
|
||||||
|
|
||||||
res.json(UserFactory.mapToSingle(user));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description get my totp
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function getMyTotp(req: Request, res: Response): Promise<any> {
|
|
||||||
const userId = parseInt(req.userId);
|
|
||||||
|
|
||||||
let { secret } = await UserService.getById(userId);
|
|
||||||
|
|
||||||
const url = `otpauth://totp/Mitgliederverwaltung ${CLUB_NAME}?secret=${secret}`;
|
|
||||||
|
|
||||||
QRCode.toDataURL(url)
|
|
||||||
.then((result) => {
|
|
||||||
res.json({
|
|
||||||
dataUrl: result,
|
|
||||||
otp: secret,
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
throw new InternalException("QRCode not created", err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description verify my totp
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function verifyMyTotp(req: Request, res: Response): Promise<any> {
|
|
||||||
const userId = parseInt(req.userId);
|
|
||||||
let totp = req.body.totp;
|
|
||||||
|
|
||||||
let { secret } = await UserService.getById(userId);
|
|
||||||
let valid = speakeasy.totp.verify({
|
|
||||||
secret: secret,
|
|
||||||
encoding: "base32",
|
|
||||||
token: totp,
|
|
||||||
window: 2,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!valid) {
|
|
||||||
throw new InternalException("Token not valid or expired");
|
|
||||||
}
|
|
||||||
res.sendStatus(204);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description transferOwnership
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function transferOwnership(req: Request, res: Response): Promise<any> {
|
|
||||||
const userId = parseInt(req.userId);
|
|
||||||
let toId = req.body.toId;
|
|
||||||
|
|
||||||
let { isOwner } = await UserService.getById(userId);
|
|
||||||
if (!isOwner) {
|
|
||||||
throw new ForbiddenRequestException("Action only allowed to owner.");
|
|
||||||
}
|
|
||||||
|
|
||||||
let transfer: TransferUserOwnerCommand = {
|
|
||||||
toId: toId,
|
|
||||||
fromId: userId,
|
|
||||||
};
|
|
||||||
await UserCommandHandler.transferOwnership(transfer);
|
|
||||||
|
|
||||||
res.sendStatus(204);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description update my data
|
|
||||||
* @param req {Request} Express req object
|
|
||||||
* @param res {Response} Express res object
|
|
||||||
* @returns {Promise<*>}
|
|
||||||
*/
|
|
||||||
export async function updateMe(req: Request, res: Response): Promise<any> {
|
|
||||||
const id = parseInt(req.userId);
|
|
||||||
let mail = req.body.mail;
|
|
||||||
let firstname = req.body.firstname;
|
|
||||||
let lastname = req.body.lastname;
|
|
||||||
let username = req.body.username;
|
|
||||||
|
|
||||||
let updateUser: UpdateUserCommand = {
|
|
||||||
id: id,
|
|
||||||
mail: mail,
|
|
||||||
firstname: firstname,
|
|
||||||
lastname: lastname,
|
|
||||||
username: username,
|
|
||||||
};
|
|
||||||
await UserCommandHandler.update(updateUser);
|
|
||||||
|
|
||||||
res.sendStatus(204);
|
|
||||||
}
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue