viewmodels and factories

This commit is contained in:
Julian Krauser 2024-09-16 15:55:41 +02:00
parent 93e27ab440
commit 7cd4e5505b
25 changed files with 501 additions and 69 deletions

View file

@ -21,8 +21,8 @@ export async function getAllMembers(req: Request, res: Response): Promise<any> {
* @returns {Promise<*>} * @returns {Promise<*>}
*/ */
export async function getMemberById(req: Request, res: Response): Promise<any> { export async function getMemberById(req: Request, res: Response): Promise<any> {
const memberid = parseInt(req.params.id); const memberId = parseInt(req.params.id);
let member = await MemberService.getById(memberid); let member = await MemberService.getById(memberId);
res.json(MemberFactory.mapToSingle(member)); res.json(MemberFactory.mapToSingle(member));
} }
@ -34,7 +34,7 @@ export async function getMemberById(req: Request, res: Response): Promise<any> {
* @returns {Promise<*>} * @returns {Promise<*>}
*/ */
export async function getMembershipsByMember(req: Request, res: Response): Promise<any> { export async function getMembershipsByMember(req: Request, res: Response): Promise<any> {
const memberid = parseInt(req.params.memberId); const memberId = parseInt(req.params.memberId);
res.json([]); res.json([]);
} }
@ -46,7 +46,7 @@ export async function getMembershipsByMember(req: Request, res: Response): Promi
* @returns {Promise<*>} * @returns {Promise<*>}
*/ */
export async function getAwardsByMember(req: Request, res: Response): Promise<any> { export async function getAwardsByMember(req: Request, res: Response): Promise<any> {
const memberid = parseInt(req.params.memberId); const memberId = parseInt(req.params.memberId);
res.json([]); res.json([]);
} }
@ -58,7 +58,7 @@ export async function getAwardsByMember(req: Request, res: Response): Promise<an
* @returns {Promise<*>} * @returns {Promise<*>}
*/ */
export async function getQualificationsByMember(req: Request, res: Response): Promise<any> { export async function getQualificationsByMember(req: Request, res: Response): Promise<any> {
const memberid = parseInt(req.params.memberId); const memberId = parseInt(req.params.memberId);
res.json([]); res.json([]);
} }
@ -70,7 +70,7 @@ export async function getQualificationsByMember(req: Request, res: Response): Pr
* @returns {Promise<*>} * @returns {Promise<*>}
*/ */
export async function getExecutivePositionsByMember(req: Request, res: Response): Promise<any> { export async function getExecutivePositionsByMember(req: Request, res: Response): Promise<any> {
const memberid = parseInt(req.params.memberId); const memberId = parseInt(req.params.memberId);
res.json([]); res.json([]);
} }
@ -82,7 +82,7 @@ export async function getExecutivePositionsByMember(req: Request, res: Response)
* @returns {Promise<*>} * @returns {Promise<*>}
*/ */
export async function getCommunicationsByMember(req: Request, res: Response): Promise<any> { export async function getCommunicationsByMember(req: Request, res: Response): Promise<any> {
const memberid = parseInt(req.params.memberId); const memberId = parseInt(req.params.memberId);
res.json([]); res.json([]);
} }
@ -104,7 +104,7 @@ export async function createMember(req: Request, res: Response): Promise<any> {
* @returns {Promise<*>} * @returns {Promise<*>}
*/ */
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);
res.sendStatus(204); res.sendStatus(204);
} }
@ -116,7 +116,7 @@ export async function addMembershipToMember(req: Request, res: Response): Promis
* @returns {Promise<*>} * @returns {Promise<*>}
*/ */
export async function addAwardToMember(req: Request, res: Response): Promise<any> { export async function addAwardToMember(req: Request, res: Response): Promise<any> {
const memberid = parseInt(req.params.memberId); const memberId = parseInt(req.params.memberId);
res.sendStatus(204); res.sendStatus(204);
} }
@ -128,7 +128,7 @@ export async function addAwardToMember(req: Request, res: Response): Promise<any
* @returns {Promise<*>} * @returns {Promise<*>}
*/ */
export async function addQualificationToMember(req: Request, res: Response): Promise<any> { export async function addQualificationToMember(req: Request, res: Response): Promise<any> {
const memberid = parseInt(req.params.memberId); const memberId = parseInt(req.params.memberId);
res.sendStatus(204); res.sendStatus(204);
} }
@ -140,7 +140,7 @@ export async function addQualificationToMember(req: Request, res: Response): Pro
* @returns {Promise<*>} * @returns {Promise<*>}
*/ */
export async function addExecutivePositionToMember(req: Request, res: Response): Promise<any> { export async function addExecutivePositionToMember(req: Request, res: Response): Promise<any> {
const memberid = parseInt(req.params.memberId); const memberId = parseInt(req.params.memberId);
res.sendStatus(204); res.sendStatus(204);
} }
@ -152,7 +152,7 @@ export async function addExecutivePositionToMember(req: Request, res: Response):
* @returns {Promise<*>} * @returns {Promise<*>}
*/ */
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);
res.sendStatus(204); res.sendStatus(204);
} }
@ -164,7 +164,7 @@ export async function addCommunicationToMember(req: Request, res: Response): Pro
* @returns {Promise<*>} * @returns {Promise<*>}
*/ */
export async function updateMemberById(req: Request, res: Response): Promise<any> { export async function updateMemberById(req: Request, res: Response): Promise<any> {
const memberid = parseInt(req.params.id); const memberId = parseInt(req.params.id);
res.sendStatus(204); res.sendStatus(204);
} }
@ -176,8 +176,8 @@ export async function updateMemberById(req: Request, res: Response): Promise<any
* @returns {Promise<*>} * @returns {Promise<*>}
*/ */
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 membershipId = parseInt(req.params.membershipId); const recordId = parseInt(req.params.recordId);
res.sendStatus(204); res.sendStatus(204);
} }
@ -189,8 +189,8 @@ export async function updateMembershipOfMember(req: Request, res: Response): Pro
* @returns {Promise<*>} * @returns {Promise<*>}
*/ */
export async function updateAwardOfMember(req: Request, res: Response): Promise<any> { export async function updateAwardOfMember(req: Request, res: Response): Promise<any> {
const memberid = parseInt(req.params.memberId); const memberId = parseInt(req.params.memberId);
const awardId = parseInt(req.params.awardId); const recordId = parseInt(req.params.recordId);
res.sendStatus(204); res.sendStatus(204);
} }
@ -202,8 +202,8 @@ export async function updateAwardOfMember(req: Request, res: Response): Promise<
* @returns {Promise<*>} * @returns {Promise<*>}
*/ */
export async function updateQualificationOfMember(req: Request, res: Response): Promise<any> { export async function updateQualificationOfMember(req: Request, res: Response): Promise<any> {
const memberid = parseInt(req.params.memberId); const memberId = parseInt(req.params.memberId);
const qualificationId = parseInt(req.params.qualificationId); const recordId = parseInt(req.params.recordId);
res.sendStatus(204); res.sendStatus(204);
} }
@ -215,8 +215,8 @@ export async function updateQualificationOfMember(req: Request, res: Response):
* @returns {Promise<*>} * @returns {Promise<*>}
*/ */
export async function updateExecutivePositionOfMember(req: Request, res: Response): Promise<any> { export async function updateExecutivePositionOfMember(req: Request, res: Response): Promise<any> {
const memberid = parseInt(req.params.memberId); const memberId = parseInt(req.params.memberId);
const positionId = parseInt(req.params.positionId); const recordId = parseInt(req.params.recordId);
res.sendStatus(204); res.sendStatus(204);
} }
@ -228,8 +228,8 @@ export async function updateExecutivePositionOfMember(req: Request, res: Respons
* @returns {Promise<*>} * @returns {Promise<*>}
*/ */
export async function updateCommunicationOfMember(req: Request, res: Response): Promise<any> { export async function updateCommunicationOfMember(req: Request, res: Response): Promise<any> {
const memberid = parseInt(req.params.memberId); const memberId = parseInt(req.params.memberId);
const communicationId = parseInt(req.params.communicationId); const recordId = parseInt(req.params.recordId);
res.sendStatus(204); res.sendStatus(204);
} }
@ -241,7 +241,7 @@ export async function updateCommunicationOfMember(req: Request, res: Response):
* @returns {Promise<*>} * @returns {Promise<*>}
*/ */
export async function deleteMemberById(req: Request, res: Response): Promise<any> { export async function deleteMemberById(req: Request, res: Response): Promise<any> {
const memberid = parseInt(req.params.id); const memberId = parseInt(req.params.id);
res.sendStatus(204); res.sendStatus(204);
} }
@ -253,8 +253,8 @@ export async function deleteMemberById(req: Request, res: Response): Promise<any
* @returns {Promise<*>} * @returns {Promise<*>}
*/ */
export async function deleteMembershipOfMember(req: Request, res: Response): Promise<any> { export async function deleteMembershipOfMember(req: Request, res: Response): Promise<any> {
const memberid = parseInt(req.params.memberId); const memberId = parseInt(req.params.memberId);
const membershipId = parseInt(req.params.membershipId); const recordId = parseInt(req.params.recordId);
res.sendStatus(204); res.sendStatus(204);
} }
@ -266,8 +266,8 @@ export async function deleteMembershipOfMember(req: Request, res: Response): Pro
* @returns {Promise<*>} * @returns {Promise<*>}
*/ */
export async function deleteAwardOfMember(req: Request, res: Response): Promise<any> { export async function deleteAwardOfMember(req: Request, res: Response): Promise<any> {
const memberid = parseInt(req.params.memberId); const memberId = parseInt(req.params.memberId);
const awardId = parseInt(req.params.awardId); const recordId = parseInt(req.params.recordId);
res.sendStatus(204); res.sendStatus(204);
} }
@ -279,8 +279,8 @@ export async function deleteAwardOfMember(req: Request, res: Response): Promise<
* @returns {Promise<*>} * @returns {Promise<*>}
*/ */
export async function deleteQualificationOfMember(req: Request, res: Response): Promise<any> { export async function deleteQualificationOfMember(req: Request, res: Response): Promise<any> {
const memberid = parseInt(req.params.memberId); const memberId = parseInt(req.params.memberId);
const qualificationId = parseInt(req.params.qualificationId); const recordId = parseInt(req.params.recordId);
res.sendStatus(204); res.sendStatus(204);
} }
@ -292,8 +292,8 @@ export async function deleteQualificationOfMember(req: Request, res: Response):
* @returns {Promise<*>} * @returns {Promise<*>}
*/ */
export async function deleteExecutivePositionOfMember(req: Request, res: Response): Promise<any> { export async function deleteExecutivePositionOfMember(req: Request, res: Response): Promise<any> {
const memberid = parseInt(req.params.memberId); const memberId = parseInt(req.params.memberId);
const positionId = parseInt(req.params.positionId); const recordId = parseInt(req.params.recordId);
res.sendStatus(204); res.sendStatus(204);
} }
@ -305,8 +305,8 @@ export async function deleteExecutivePositionOfMember(req: Request, res: Respons
* @returns {Promise<*>} * @returns {Promise<*>}
*/ */
export async function deleteCommunicationOfMember(req: Request, res: Response): Promise<any> { export async function deleteCommunicationOfMember(req: Request, res: Response): Promise<any> {
const memberid = parseInt(req.params.memberId); const memberId = parseInt(req.params.memberId);
const communicationId = parseInt(req.params.communicationId); const recordId = parseInt(req.params.recordId);
res.sendStatus(204); res.sendStatus(204);
} }

View file

@ -60,4 +60,7 @@ export class member {
@OneToMany(() => memberQualifications, (qualifications) => qualifications.member) @OneToMany(() => memberQualifications, (qualifications) => qualifications.member)
qualifications: memberQualifications[]; qualifications: memberQualifications[];
firstMembershipEntry?: membership;
lastMembershipEntry?: membership;
} }

View file

@ -0,0 +1,34 @@
import { communication } from "../../entity/communication";
import { CommunicationViewModel } from "../../viewmodel/admin/communication.models";
import CommunicationTypeFactory from "./communicationType";
export default abstract class CommunicationFactory {
/**
* @description map record to communication
* @param {communication} record
* @returns {CommunicationViewModel}
*/
public static mapToSingle(record: communication): CommunicationViewModel {
return {
id: record.id,
preferred: record.preferred,
mobile: record.mobile,
email: record.email,
city: record.city,
street: record.street,
streetNumber: record.streetNumber,
streetNumberAddition: record.streetNumberAddition,
type: CommunicationTypeFactory.mapToSingle(record.type),
isNewsletterMain: record.member.sendNewsletter?.id == record.id,
};
}
/**
* @description map records to communication
* @param {Array<communication>} records
* @returns {Array<CommunicationViewModel>}
*/
public static mapToBase(records: Array<communication>): Array<CommunicationViewModel> {
return records.map((r) => this.mapToSingle(r));
}
}

View file

@ -1,5 +1,6 @@
import { member } from "../../entity/member"; import { member } from "../../entity/member";
import { MemberViewModel } from "../../viewmodel/admin/member.models"; import { MemberViewModel } from "../../viewmodel/admin/member.models";
import MembershipFactory from "./membership";
export default abstract class MemberFactory { export default abstract class MemberFactory {
/** /**
@ -15,6 +16,8 @@ export default abstract class MemberFactory {
lastname: record.lastname, lastname: record.lastname,
nameaffix: record.nameaffix, nameaffix: record.nameaffix,
birthdate: record.birthdate, birthdate: record.birthdate,
firstMembershipEntry: MembershipFactory.mapToSingle(record.firstMembershipEntry),
lastMembershipEntry: MembershipFactory.mapToSingle(record.lastMembershipEntry),
}; };
} }

View file

@ -0,0 +1,28 @@
import { memberAwards } from "../../entity/memberAwards";
import { MemberAwardViewModel } from "../../viewmodel/admin/memberAward.models";
export default abstract class MemberAwardFactory {
/**
* @description map record to memberAward
* @param {memberAward} record
* @returns {MemberAwardViewModel}
*/
public static mapToSingle(record: memberAwards): MemberAwardViewModel {
return {
id: record.id,
given: record.given,
note: record.note,
date: record.date,
award: record.award.award,
};
}
/**
* @description map records to memberAward
* @param {Array<memberAward>} records
* @returns {Array<MemberAwardViewModel>}
*/
public static mapToBase(records: Array<memberAwards>): Array<MemberAwardViewModel> {
return records.map((r) => this.mapToSingle(r));
}
}

View file

@ -0,0 +1,28 @@
import { memberExecutivePositions } from "../../entity/memberExecutivePositions";
import { MemberExecutivePositionViewModel } from "../../viewmodel/admin/memberExecutivePosition.models";
export default abstract class MemberExecutivePositionFactory {
/**
* @description map record to memberExecutivePosition
* @param {memberExecutivePosition} record
* @returns {MemberExecutivePositionViewModel}
*/
public static mapToSingle(record: memberExecutivePositions): MemberExecutivePositionViewModel {
return {
id: record.id,
note: record.note,
start: record.start,
end: record.end,
executivePosition: record.executivePosition.position,
};
}
/**
* @description map records to memberExecutivePosition
* @param {Array<memberExecutivePosition>} records
* @returns {Array<MemberExecutivePositionViewModel>}
*/
public static mapToBase(records: Array<memberExecutivePositions>): Array<MemberExecutivePositionViewModel> {
return records.map((r) => this.mapToSingle(r));
}
}

View file

@ -0,0 +1,28 @@
import { memberQualifications } from "../../entity/memberQualifications";
import { MemberQualificationViewModel } from "../../viewmodel/admin/memberQualification.models";
export default abstract class MemberQualificationFactory {
/**
* @description map record to memberQualification
* @param {memberQualification} record
* @returns {MemberQualificationViewModel}
*/
public static mapToSingle(record: memberQualifications): MemberQualificationViewModel {
return {
id: record.id,
note: record.note,
start: record.start,
end: record.end,
qualification: record.qualification.qualification,
};
}
/**
* @description map records to memberQualification
* @param {Array<memberQualification>} records
* @returns {Array<MemberQualificationViewModel>}
*/
public static mapToBase(records: Array<memberQualifications>): Array<MemberQualificationViewModel> {
return records.map((r) => this.mapToSingle(r));
}
}

View file

@ -0,0 +1,29 @@
import { membership } from "../../entity/membership";
import { MembershipViewModel } from "../../viewmodel/admin/membership.models";
export default abstract class MembershipFactory {
/**
* @description map record to membership
* @param {membership} record
* @returns {MembershipViewModel}
*/
public static mapToSingle(record: membership): MembershipViewModel {
return {
id: record.id,
internalId: record.internalId,
start: record.start,
end: record.end,
terminationReason: record.terminationReason,
status: record.status.status,
};
}
/**
* @description map records to membership
* @param {Array<membership>} records
* @returns {Array<MembershipViewModel>}
*/
public static mapToBase(records: Array<membership>): Array<MembershipViewModel> {
return records.map((r) => this.mapToSingle(r));
}
}

View file

@ -3,7 +3,6 @@ import {
createAward, createAward,
deleteAward, deleteAward,
getAllAwards, getAllAwards,
getAwardAssignedMembers,
getAwardById, getAwardById,
updateAward, updateAward,
} from "../../controller/admin/awardController"; } from "../../controller/admin/awardController";
@ -18,10 +17,6 @@ router.get("/:id", async (req: Request, res: Response) => {
await getAwardById(req, res); await getAwardById(req, res);
}); });
router.get("/:id/assigned", async (req: Request, res: Response) => {
await getAwardAssignedMembers(req, res);
});
router.post("/", async (req: Request, res: Response) => { router.post("/", async (req: Request, res: Response) => {
await createAward(req, res); await createAward(req, res);
}); });

View file

@ -3,7 +3,6 @@ import {
createExecutivePosition, createExecutivePosition,
deleteExecutivePosition, deleteExecutivePosition,
getAllExecutivePositions, getAllExecutivePositions,
getExecutivePositionAssignedMembers,
getExecutivePositionById, getExecutivePositionById,
updateExecutivePosition, updateExecutivePosition,
} from "../../controller/admin/executivePositionController"; } from "../../controller/admin/executivePositionController";
@ -18,10 +17,6 @@ router.get("/:id", async (req: Request, res: Response) => {
await getExecutivePositionById(req, res); await getExecutivePositionById(req, res);
}); });
router.get("/:id/assigned", async (req: Request, res: Response) => {
await getExecutivePositionAssignedMembers(req, res);
});
router.post("/", async (req: Request, res: Response) => { router.post("/", async (req: Request, res: Response) => {
await createExecutivePosition(req, res); await createExecutivePosition(req, res);
}); });

View file

@ -85,23 +85,23 @@ router.patch("/:id", async (req: Request, res: Response) => {
await updateMemberById(req, res); await updateMemberById(req, res);
}); });
router.patch("/:memberId/membership/:membershipId", async (req: Request, res: Response) => { router.patch("/:memberId/membership/:recordId", async (req: Request, res: Response) => {
await updateMembershipOfMember(req, res); await updateMembershipOfMember(req, res);
}); });
router.patch("/:memberId/award/:awardId", async (req: Request, res: Response) => { router.patch("/:memberId/award/:recordId", async (req: Request, res: Response) => {
await updateAwardOfMember(req, res); await updateAwardOfMember(req, res);
}); });
router.patch("/:memberId/qualification/:qualificationId", async (req: Request, res: Response) => { router.patch("/:memberId/qualification/:recordId", async (req: Request, res: Response) => {
await updateQualificationOfMember(req, res); await updateQualificationOfMember(req, res);
}); });
router.patch("/:memberId/position/:positionId", async (req: Request, res: Response) => { router.patch("/:memberId/position/:recordId", async (req: Request, res: Response) => {
await updateExecutivePositionOfMember(req, res); await updateExecutivePositionOfMember(req, res);
}); });
router.patch("/:memberId/communication/:communicationId", async (req: Request, res: Response) => { router.patch("/:memberId/communication/:recordId", async (req: Request, res: Response) => {
await updateCommunicationOfMember(req, res); await updateCommunicationOfMember(req, res);
}); });
@ -109,23 +109,23 @@ router.delete("/:id", async (req: Request, res: Response) => {
await deleteMemberById(req, res); await deleteMemberById(req, res);
}); });
router.delete("/:memberId/membership/:membershipId", async (req: Request, res: Response) => { router.delete("/:memberId/membership/:recordId", async (req: Request, res: Response) => {
await deleteMembershipOfMember(req, res); await deleteMembershipOfMember(req, res);
}); });
router.delete("/:memberId/award/:awardId", async (req: Request, res: Response) => { router.delete("/:memberId/award/:recordId", async (req: Request, res: Response) => {
await deleteAwardOfMember(req, res); await deleteAwardOfMember(req, res);
}); });
router.delete("/:memberId/qualification/:qualificationId", async (req: Request, res: Response) => { router.delete("/:memberId/qualification/:recordId", async (req: Request, res: Response) => {
await deleteQualificationOfMember(req, res); await deleteQualificationOfMember(req, res);
}); });
router.delete("/:memberId/position/:positionId", async (req: Request, res: Response) => { router.delete("/:memberId/position/:recordId", async (req: Request, res: Response) => {
await deleteExecutivePositionOfMember(req, res); await deleteExecutivePositionOfMember(req, res);
}); });
router.delete("/:memberId/communication/:communicationId", async (req: Request, res: Response) => { router.delete("/:memberId/communication/:recordId", async (req: Request, res: Response) => {
await deleteCommunicationOfMember(req, res); await deleteCommunicationOfMember(req, res);
}); });

View file

@ -3,7 +3,6 @@ import {
createMembershipStatus, createMembershipStatus,
deleteMembershipStatus, deleteMembershipStatus,
getAllMembershipStatus, getAllMembershipStatus,
getMembershipStatusAssignedMembers,
getMembershipStatusById, getMembershipStatusById,
updateMembershipStatus, updateMembershipStatus,
} from "../../controller/admin/membershipStatusController"; } from "../../controller/admin/membershipStatusController";
@ -18,10 +17,6 @@ router.get("/:id", async (req: Request, res: Response) => {
await getMembershipStatusById(req, res); await getMembershipStatusById(req, res);
}); });
router.get("/:id/assigned", async (req: Request, res: Response) => {
await getMembershipStatusAssignedMembers(req, res);
});
router.post("/", async (req: Request, res: Response) => { router.post("/", async (req: Request, res: Response) => {
await createMembershipStatus(req, res); await createMembershipStatus(req, res);
}); });

View file

@ -3,7 +3,6 @@ import {
createQualification, createQualification,
deleteQualification, deleteQualification,
getAllQualifications, getAllQualifications,
getQualificationAssignedMembers,
getQualificationById, getQualificationById,
updateQualification, updateQualification,
} from "../../controller/admin/qualificationController"; } from "../../controller/admin/qualificationController";
@ -18,10 +17,6 @@ router.get("/:id", async (req: Request, res: Response) => {
await getQualificationById(req, res); await getQualificationById(req, res);
}); });
router.get("/:id/assigned", async (req: Request, res: Response) => {
await getQualificationAssignedMembers(req, res);
});
router.post("/", async (req: Request, res: Response) => { router.post("/", async (req: Request, res: Response) => {
await createQualification(req, res); await createQualification(req, res);
}); });

View file

@ -4,21 +4,48 @@ import InternalException from "../exceptions/internalException";
export default abstract class CommunicationService { export default abstract class CommunicationService {
/** /**
* @description get communications by user * @description get all by member id
* @param {number} memberId
* @returns {Promise<Array<communication>>} * @returns {Promise<Array<communication>>}
*/ */
static async getById(userId: number): Promise<communication> { static async getAll(memberId: number): Promise<Array<communication>> {
return await dataSource return await dataSource
.getRepository(communication) .getRepository(communication)
.createQueryBuilder("communication") .createQueryBuilder("communication")
.leftJoin("communication.user", "user") .leftJoinAndSelect("communication.type", "communicationType")
.where("user.id = :id", { id: userId }) .leftJoinAndSelect("communication.member", "member")
.leftJoinAndSelect("member.sendNewsletter", "sendNewsletter")
.where("communication.memberId = :memberId", { memberId: memberId })
.getMany()
.then((res) => {
return res;
})
.catch((err) => {
throw new InternalException("member communications not found", err);
});
}
/**
* @description get all by memberId and recordId
* @param {number} memberId
* @param {number} recordId
* @returns {Promise<communication>}
*/
static async getById(memberId: number, recordId: number): Promise<communication> {
return await dataSource
.getRepository(communication)
.createQueryBuilder("communication")
.leftJoinAndSelect("communication.type", "communicationType")
.leftJoinAndSelect("communication.member", "member")
.leftJoinAndSelect("member.sendNewsletter", "sendNewsletter")
.where("communication.memberId = :memberId", { memberId: memberId })
.andWhere("communication.id = :recordId", { recordId: recordId })
.getOneOrFail() .getOneOrFail()
.then((res) => { .then((res) => {
return res; return res;
}) })
.catch((err) => { .catch((err) => {
throw new InternalException("communications not found by userid", err); throw new InternalException("member communication not found by id", err);
}); });
} }

View file

@ -0,0 +1,47 @@
import { dataSource } from "../data-source";
import { memberAwards } from "../entity/memberAwards";
import InternalException from "../exceptions/internalException";
export default abstract class MemberAwardService {
/**
* @description get all by member id
* @param {number} memberId
* @returns {Promise<Array<memberAwards>>}
*/
static async getAll(memberId: number): Promise<Array<memberAwards>> {
return await dataSource
.getRepository(memberAwards)
.createQueryBuilder("memberAwards")
.leftJoinAndSelect("memberAwards.award", "award")
.where("memberAwards.memberId = :memberId", { memberId: memberId })
.getMany()
.then((res) => {
return res;
})
.catch((err) => {
throw new InternalException("member awards not found", err);
});
}
/**
* @description get by memberId and recordId
* @param {number} memberId
* @param {number} recordId
* @returns {Promise<Array<member>>}
*/
static async getById(memberId: number, recordId: number): Promise<memberAwards> {
return await dataSource
.getRepository(memberAwards)
.createQueryBuilder("memberAwards")
.leftJoinAndSelect("memberAwards.award", "award")
.where("memberAwards.memberId = :memberId", { memberId: memberId })
.andWhere("memberAwards.id = :recordId", { recordId: recordId })
.getOneOrFail()
.then((res) => {
return res;
})
.catch((err) => {
throw new InternalException("member award not found by id", err);
});
}
}

View file

@ -0,0 +1,49 @@
import { dataSource } from "../data-source";
import { memberExecutivePositions } from "../entity/memberExecutivePositions";
import InternalException from "../exceptions/internalException";
export default abstract class MemberExecutivePositionService {
/**
* @description get all by member id
* @param {number} memberId
* @returns {Promise<Array<memberExecutivePositions>>}
*/
static async getAll(memberId: number): Promise<Array<memberExecutivePositions>> {
return await dataSource
.getRepository(memberExecutivePositions)
.createQueryBuilder("memberExecutivePositions")
.leftJoinAndSelect("memberExecutivePositions.executivePosition", "executivePosition")
.where("memberExecutivePositions.memberId = :memberId", { memberId: memberId })
.getMany()
.then((res) => {
return res;
})
.catch((err) => {
throw new InternalException("member executivePositions not found", err);
});
}
/**
* @description get by memberId and recordId
* @param {number} memberId
* @param {number} recordId
* @returns {Promise<Array<member>>}
*/
static async getById(memberId: number, recordId: number): Promise<memberExecutivePositions> {
return await dataSource
.getRepository(memberExecutivePositions)
.createQueryBuilder("memberExecutivePositions")
.leftJoinAndSelect("memberExecutivePositions.executivePosition", "executivePosition")
.where("memberExecutivePositions.memberId = :memberId", { memberId: memberId })
.andWhere("memberExecutivePositions.id = :recordId", {
recordId: recordId,
})
.getOneOrFail()
.then((res) => {
return res;
})
.catch((err) => {
throw new InternalException("member executivePosition not found by id", err);
});
}
}

View file

@ -0,0 +1,47 @@
import { dataSource } from "../data-source";
import { memberQualifications } from "../entity/memberQualifications";
import InternalException from "../exceptions/internalException";
export default abstract class MemberQualificationService {
/**
* @description get all by member id
* @param {number} memberId
* @returns {Promise<Array<memberQualifications>>}
*/
static async getAll(memberId: number): Promise<Array<memberQualifications>> {
return await dataSource
.getRepository(memberQualifications)
.createQueryBuilder("memberQualifications")
.leftJoinAndSelect("memberQualifications.qualification", "qualification")
.where("memberQualifications.memberId = :memberId", { memberId: memberId })
.getMany()
.then((res) => {
return res;
})
.catch((err) => {
throw new InternalException("member qualifications not found", err);
});
}
/**
* @description get by memberId and recordId
* @param {number} memberId
* @param {number} recordId
* @returns {Promise<Array<member>>}
*/
static async getById(memberId: number, recordId: number): Promise<memberQualifications> {
return await dataSource
.getRepository(memberQualifications)
.createQueryBuilder("memberQualifications")
.leftJoinAndSelect("memberQualifications.qualification", "qualification")
.where("memberQualifications.memberId = :memberId", { memberId: memberId })
.andWhere("memberQualifications.id = :recordId", { recordId: recordId })
.getOneOrFail()
.then((res) => {
return res;
})
.catch((err) => {
throw new InternalException("member qualification not found by id", err);
});
}
}

View file

@ -1,5 +1,6 @@
import { dataSource } from "../data-source"; import { dataSource } from "../data-source";
import { member } from "../entity/member"; import { member } from "../entity/member";
import { membership } from "../entity/membership";
import InternalException from "../exceptions/internalException"; import InternalException from "../exceptions/internalException";
export default abstract class MemberService { export default abstract class MemberService {
@ -11,6 +12,18 @@ export default abstract class MemberService {
return await dataSource return await dataSource
.getRepository(member) .getRepository(member)
.createQueryBuilder("member") .createQueryBuilder("member")
.leftJoinAndMapOne(
"member.firstMembershipEntry",
"member.memberships",
"membership_first",
"membership_first.memberId = member.id AND membership_first.start = (SELECT MIN(m.start) FROM membership m WHERE m.memberId = member.id)"
)
.leftJoinAndMapOne(
"member.lastMembershipEntry",
"member.memberships",
"membership_last",
"membership_last.memberId = member.id AND membership_last.start = (SELECT MAX(m.start) FROM membership m WHERE m.memberId = member.id)"
)
.getMany() .getMany()
.then((res) => { .then((res) => {
return res; return res;
@ -29,6 +42,28 @@ export default abstract class MemberService {
return await dataSource return await dataSource
.getRepository(member) .getRepository(member)
.createQueryBuilder("member") .createQueryBuilder("member")
.leftJoinAndMapOne(
"member.firstMembershipEntry",
(subQuery) => {
return subQuery
.from(membership, "membership")
.where("membership.memberId = member.id")
.orderBy("membership.date", "ASC")
.limit(1);
},
"membership_first"
)
.leftJoinAndMapOne(
"member.lastMembershipEntry",
(subQuery) => {
return subQuery
.from(membership, "membership")
.where("membership.memberId = member.id")
.orderBy("membership.date", "DESC")
.limit(1);
},
"membership_last"
)
.where("member.id = :id", { id: id }) .where("member.id = :id", { id: id })
.getOneOrFail() .getOneOrFail()
.then((res) => { .then((res) => {

View file

@ -0,0 +1,47 @@
import { dataSource } from "../data-source";
import { membership } from "../entity/membership";
import InternalException from "../exceptions/internalException";
export default abstract class Membershipervice {
/**
* @description get all by member id
* @param {number} memberId
* @returns {Promise<Array<membership>>}
*/
static async getAll(memberId: number): Promise<Array<membership>> {
return await dataSource
.getRepository(membership)
.createQueryBuilder("membership")
.leftJoinAndSelect("membership.membership", "membership")
.where("membership.memberId = :memberId", { memberId: memberId })
.getMany()
.then((res) => {
return res;
})
.catch((err) => {
throw new InternalException("member memberships not found", err);
});
}
/**
* @description get by memberId and recordId
* @param {number} memberId
* @param {number} recordId
* @returns {Promise<Array<member>>}
*/
static async getById(memberId: number, recordId: number): Promise<membership> {
return await dataSource
.getRepository(membership)
.createQueryBuilder("membership")
.leftJoinAndSelect("membership.membership", "membership")
.where("membership.memberId = :memberId", { memberId: memberId })
.andWhere("membership.id = :recordId", { recordId: recordId })
.getOneOrFail()
.then((res) => {
return res;
})
.catch((err) => {
throw new InternalException("member membership not found by id", err);
});
}
}

View file

@ -0,0 +1,14 @@
import { CommunicationTypeViewModel } from "./communicationType.models";
export interface CommunicationViewModel {
id: number;
preferred: boolean;
mobile: string;
email: string;
city: string;
street: string;
streetNumber: number;
streetNumberAddition: string;
type: CommunicationTypeViewModel;
isNewsletterMain: boolean;
}

View file

@ -1,4 +1,5 @@
import { Salutation } from "../../enums/salutation"; import { Salutation } from "../../enums/salutation";
import { MembershipViewModel } from "./membership.models";
export interface MemberViewModel { export interface MemberViewModel {
id: number; id: number;
@ -7,4 +8,6 @@ export interface MemberViewModel {
lastname: string; lastname: string;
nameaffix: string; nameaffix: string;
birthdate: Date; birthdate: Date;
firstMembershipEntry?: MembershipViewModel;
lastMembershipEntry?: MembershipViewModel;
} }

View file

@ -0,0 +1,7 @@
export interface MemberAwardViewModel {
id: number;
given: boolean;
note?: string;
date: Date;
award: string;
}

View file

@ -0,0 +1,7 @@
export interface MemberExecutivePositionViewModel {
id: number;
note?: string;
start: Date;
end?: Date;
executivePosition: string;
}

View file

@ -0,0 +1,8 @@
export interface MemberQualificationViewModel {
id: number;
note?: string;
start: Date;
end?: Date;
terminationReason?: string;
qualification: string;
}

View file

@ -0,0 +1,8 @@
export interface MembershipViewModel {
id: number;
internalId?: string;
start: Date;
end?: Date;
terminationReason?: string;
status: string;
}