Intermediate: Merge pull request 'postal Code & commandHandler update' (#28) from #25-cleanup-&-enhancements into main

Reviewed-on: Ehrenamt/member-administration-server#28
This commit is contained in:
Julian Krauser 2025-01-03 18:27:46 +00:00
commit b92cca773e
13 changed files with 70 additions and 76 deletions

View file

@ -3,6 +3,7 @@ export interface CreateCommunicationCommand {
isSMSAlarming: boolean;
mobile: string;
email: string;
postalCode: string;
city: string;
street: string;
streetNumber: number;
@ -17,6 +18,7 @@ export interface UpdateCommunicationCommand {
isSMSAlarming: boolean;
mobile: string;
email: string;
postalCode: string;
city: string;
street: string;
streetNumber: number;

View file

@ -25,20 +25,13 @@ export default abstract class CommunicationCommandHandler {
isSMSAlarming: createCommunication.isSMSAlarming,
mobile: createCommunication.mobile,
email: createCommunication.email,
postalCode: createCommunication.postalCode,
city: createCommunication.city,
street: createCommunication.street,
streetNumber: createCommunication.streetNumber,
streetNumberAddition: createCommunication.streetNumberAddition,
member: await dataSource
.getRepository(user)
.createQueryBuilder("user")
.where("id = :id", { id: createCommunication.memberId })
.getOneOrFail(),
type: await dataSource
.getRepository(communicationType)
.createQueryBuilder("communication")
.where("id = :id", { id: createCommunication.typeId })
.getOneOrFail(),
memberId: createCommunication.memberId,
typeId: createCommunication.typeId,
})
.execute()
.then((result) => {
@ -63,6 +56,7 @@ export default abstract class CommunicationCommandHandler {
isSMSAlarming: updateCommunication.isSMSAlarming,
mobile: updateCommunication.mobile,
email: updateCommunication.email,
postalCode: updateCommunication.postalCode,
city: updateCommunication.city,
street: updateCommunication.street,
streetNumber: updateCommunication.streetNumber,
@ -82,13 +76,13 @@ export default abstract class CommunicationCommandHandler {
* @param DeleteCommunicationCommand
* @returns {Promise<void>}
*/
static async delete(deletCommunication: DeleteCommunicationCommand): Promise<void> {
static async delete(deleteCommunication: DeleteCommunicationCommand): Promise<void> {
return await dataSource
.createQueryBuilder()
.delete()
.from(communication)
.where("id = :id", { id: deletCommunication.id })
.andWhere("memberId = :memberId", { memberId: deletCommunication.memberId })
.where("id = :id", { id: deleteCommunication.id })
.andWhere("memberId = :memberId", { memberId: deleteCommunication.memberId })
.execute()
.then(() => {})
.catch((err) => {

View file

@ -20,16 +20,8 @@ export default abstract class MemberAwardCommandHandler {
given: createMemberAward.given,
note: createMemberAward.note,
date: createMemberAward.date,
member: await dataSource
.getRepository(member)
.createQueryBuilder("member")
.where("id = :id", { id: createMemberAward.memberId })
.getOneOrFail(),
award: await dataSource
.getRepository(award)
.createQueryBuilder("award")
.where("id = :id", { id: createMemberAward.awardId })
.getOneOrFail(),
memberId: createMemberAward.memberId,
awardId: createMemberAward.awardId,
})
.execute()
.then((result) => {
@ -53,11 +45,7 @@ export default abstract class MemberAwardCommandHandler {
given: updateMemberAward.given,
note: updateMemberAward.note,
date: updateMemberAward.date,
award: await dataSource
.getRepository(award)
.createQueryBuilder("award")
.where("id = :id", { id: updateMemberAward.awardId })
.getOneOrFail(),
award: updateMemberAward.awardId,
})
.where("id = :id", { id: updateMemberAward.id })
.andWhere("memberId = :memberId", { memberId: updateMemberAward.memberId })

View file

@ -24,16 +24,8 @@ export default abstract class MemberExecutivePositionCommandHandler {
note: createMemberExecutivePosition.note,
start: createMemberExecutivePosition.start,
end: createMemberExecutivePosition.end,
member: await dataSource
.getRepository(member)
.createQueryBuilder("member")
.where("id = :id", { id: createMemberExecutivePosition.memberId })
.getOneOrFail(),
executivePosition: await dataSource
.getRepository(executivePosition)
.createQueryBuilder("executivePosition")
.where("id = :id", { id: createMemberExecutivePosition.executivePositionId })
.getOneOrFail(),
memberId: createMemberExecutivePosition.memberId,
executivePositionId: createMemberExecutivePosition.executivePositionId,
})
.execute()
.then((result) => {
@ -57,11 +49,7 @@ export default abstract class MemberExecutivePositionCommandHandler {
note: updateMemberExecutivePosition.note,
start: updateMemberExecutivePosition.start,
end: updateMemberExecutivePosition.end,
executivePosition: await dataSource
.getRepository(executivePosition)
.createQueryBuilder("executivePosition")
.where("id = :id", { id: updateMemberExecutivePosition.executivePositionId })
.getOneOrFail(),
executivePositionId: updateMemberExecutivePosition.executivePositionId,
})
.where("id = :id", { id: updateMemberExecutivePosition.id })
.andWhere("memberId = :memberId", { memberId: updateMemberExecutivePosition.memberId })

View file

@ -23,16 +23,8 @@ export default abstract class MemberQualificationCommandHandler {
.values({
note: createMemberQualification.note,
start: createMemberQualification.start,
member: await dataSource
.getRepository(member)
.createQueryBuilder("member")
.where("id = :id", { id: createMemberQualification.memberId })
.getOneOrFail(),
qualification: await dataSource
.getRepository(qualification)
.createQueryBuilder("qualification")
.where("id = :id", { id: createMemberQualification.qualificationId })
.getOneOrFail(),
memberId: createMemberQualification.memberId,
qualificationId: createMemberQualification.qualificationId,
})
.execute()
.then((result) => {
@ -57,11 +49,7 @@ export default abstract class MemberQualificationCommandHandler {
start: updateMemberQualification.start,
end: updateMemberQualification.end,
terminationReason: updateMemberQualification.terminationReason,
qualification: await dataSource
.getRepository(qualification)
.createQueryBuilder("qualification")
.where("id = :id", { id: updateMemberQualification.qualificationId })
.getOneOrFail(),
qualificationId: updateMemberQualification.qualificationId,
})
.where("id = :id", { id: updateMemberQualification.id })
.andWhere("memberId = :memberId", { memberId: updateMemberQualification.memberId })

View file

@ -21,16 +21,8 @@ export default abstract class MembershipCommandHandler {
.into(membership)
.values({
start: createMembership.start,
member: await dataSource
.getRepository(member)
.createQueryBuilder("member")
.where("id = :id", { id: createMembership.memberId })
.getOneOrFail(),
status: await dataSource
.getRepository(membershipStatus)
.createQueryBuilder("membershipStatus")
.where("id = :id", { id: createMembership.statusId })
.getOneOrFail(),
memberId: createMembership.memberId,
statusId: createMembership.statusId,
})
.execute()
.then((result) => {
@ -70,11 +62,7 @@ export default abstract class MembershipCommandHandler {
start: updateMembership.start,
end: updateMembership.end,
terminationReason: updateMembership.terminationReason,
status: await dataSource
.getRepository(membershipStatus)
.createQueryBuilder("membershipStatus")
.where("id = :id", { id: updateMembership.statusId })
.getOneOrFail(),
statusId: updateMembership.statusId,
})
.where("id = :id", { id: updateMembership.id })
.andWhere("memberId = :memberId", { memberId: updateMembership.memberId })

View file

@ -351,6 +351,7 @@ export async function addCommunicationToMember(req: Request, res: Response): Pro
const isSMSAlarming = req.body.isSMSAlarming;
const mobile = req.body.mobile;
const email = req.body.email;
const postalCode = req.body.postalCode;
const city = req.body.city;
const street = req.body.street;
const streetNumber = req.body.streetNumber;
@ -363,6 +364,7 @@ export async function addCommunicationToMember(req: Request, res: Response): Pro
isSMSAlarming,
mobile,
email,
postalCode,
city,
street,
streetNumber,
@ -535,11 +537,11 @@ export async function updateCommunicationOfMember(req: Request, res: Response):
const isSMSAlarming = req.body.isSMSAlarming;
const mobile = req.body.mobile;
const email = req.body.email;
const postalCode = req.body.postalCode;
const city = req.body.city;
const street = req.body.street;
const streetNumber = req.body.streetNumber;
const streetNumberAddition = req.body.streetNumberAddition;
const typeId = req.body.typeId;
const isNewsletterMain = req.body.isNewsletterMain;
let updateCommunication: UpdateCommunicationCommand = {
@ -548,6 +550,7 @@ export async function updateCommunicationOfMember(req: Request, res: Response):
isSMSAlarming,
mobile,
email,
postalCode,
city,
street,
streetNumber,

View file

@ -63,6 +63,7 @@ import { newsletterConfig } from "./entity/newsletterConfig";
import { NewsletterConfig1735207446910 } from "./migrations/1735207446910-newsletterConfig";
import { TemplateMargins1735733514043 } from "./migrations/1735733514043-templateMargins";
import { InternalId1735822722235 } from "./migrations/1735822722235-internalId";
import { PostalCode1735927918979 } from "./migrations/1735927918979-postalCode";
const dataSource = new DataSource({
type: DB_TYPE as any,
@ -136,6 +137,7 @@ const dataSource = new DataSource({
NewsletterConfig1735207446910,
TemplateMargins1735733514043,
InternalId1735822722235,
PostalCode1735927918979,
],
migrationsRun: true,
migrationsTransactionMode: "each",

View file

@ -1,4 +1,4 @@
import { Column, Entity, JoinColumn, ManyToOne, PrimaryColumn } from "typeorm";
import { Column, Entity, ManyToOne, PrimaryColumn } from "typeorm";
import { member } from "./member";
import { communicationType } from "./communicationType";
@ -19,6 +19,9 @@ export class communication {
@Column({ type: "varchar", length: 255, nullable: true })
email: string;
@Column({ type: "varchar", length: 255, nullable: true })
postalCode: string;
@Column({ type: "varchar", length: 255, nullable: true })
city: string;
@ -31,6 +34,12 @@ export class communication {
@Column({ type: "varchar", length: 255, nullable: true })
streetNumberAddition: string;
@Column()
memberId: number;
@Column()
typeId: number;
@ManyToOne(() => communicationType, (communicationType) => communicationType.communications, {
nullable: false,
onDelete: "RESTRICT",

View file

@ -14,6 +14,7 @@ export default abstract class CommunicationFactory {
preferred: record.preferred,
mobile: record.mobile,
email: record.email,
postalCode: record.postalCode,
city: record.city,
street: record.street,
streetNumber: record.streetNumber,

View file

@ -0,0 +1,22 @@
import { MigrationInterface, QueryRunner, TableColumn } from "typeorm";
export class PostalCode1735927918979 implements MigrationInterface {
name = "PostalCode1735927918979";
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.addColumn(
"communication",
new TableColumn({
name: "postalCode",
type: "varchar",
length: "255",
default: null,
isNullable: true,
})
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.dropColumn("communication", "postalCode");
}
}

View file

@ -1,8 +1,16 @@
export type CommunicationFieldType = "mobile" | "email" | "city" | "street" | "streetNumber" | "streetNumberAddition";
export type CommunicationFieldType =
| "mobile"
| "email"
| "postalCode"
| "city"
| "street"
| "streetNumber"
| "streetNumberAddition";
export const communicationFieldTypes: Array<CommunicationFieldType> = [
"mobile",
"email",
"postalCode",
"city",
"street",
"streetNumber",

View file

@ -5,6 +5,7 @@ export interface CommunicationViewModel {
preferred: boolean;
mobile: string;
email: string;
postalCode: string;
city: string;
street: string;
streetNumber: number;