diff --git a/src/controller/admin/awardController.ts b/src/controller/admin/awardController.ts index 0aa7fa2..695e3b1 100644 --- a/src/controller/admin/awardController.ts +++ b/src/controller/admin/awardController.ts @@ -29,18 +29,6 @@ export async function getAwardById(req: Request, res: Response): Promise { res.json(AwardFactory.mapToSingle(award)); } -/** - * @description get members assigned to award by id - * @param req {Request} Express req object - * @param res {Response} Express res object - * @returns {Promise<*>} - */ -export async function getAwardAssignedMembers(req: Request, res: Response): Promise { - const awardId = parseInt(req.params.id); - - res.json([]); -} - /** * @description create new award * @param req {Request} Express req object diff --git a/src/controller/admin/executivePositionController.ts b/src/controller/admin/executivePositionController.ts index 6902d68..2c1c77d 100644 --- a/src/controller/admin/executivePositionController.ts +++ b/src/controller/admin/executivePositionController.ts @@ -33,18 +33,6 @@ export async function getExecutivePositionById(req: Request, res: Response): Pro res.json(ExecutivePositionFactory.mapToSingle(position)); } -/** - * @description get members assigned to executivePosition by id - * @param req {Request} Express req object - * @param res {Response} Express res object - * @returns {Promise<*>} - */ -export async function getExecutivePositionAssignedMembers(req: Request, res: Response): Promise { - const executivePositionId = parseInt(req.params.id); - - res.json([]); -} - /** * @description create new executivePosition * @param req {Request} Express req object diff --git a/src/controller/admin/memberController.ts b/src/controller/admin/memberController.ts new file mode 100644 index 0000000..51e01c0 --- /dev/null +++ b/src/controller/admin/memberController.ts @@ -0,0 +1,312 @@ +import { Request, Response } from "express"; +import MemberService from "../../service/memberService"; +import MemberFactory from "../../factory/admin/member"; + +/** + * @description get all members + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function getAllMembers(req: Request, res: Response): Promise { + let members = await MemberService.getAll(); + + res.json(MemberFactory.mapToBase(members)); +} + +/** + * @description get member by id + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function getMemberById(req: Request, res: Response): Promise { + const memberid = parseInt(req.params.id); + let member = await MemberService.getById(memberid); + + res.json(MemberFactory.mapToSingle(member)); +} + +/** + * @description get memberships by member + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function getMembershipsByMember(req: Request, res: Response): Promise { + const memberid = parseInt(req.params.memberId); + + res.json([]); +} + +/** + * @description get awards by member + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function getAwardsByMember(req: Request, res: Response): Promise { + const memberid = parseInt(req.params.memberId); + + res.json([]); +} + +/** + * @description get qualifications by member + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function getQualificationsByMember(req: Request, res: Response): Promise { + const memberid = parseInt(req.params.memberId); + + res.json([]); +} + +/** + * @description get executive positions by member + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function getExecutivePositionsByMember(req: Request, res: Response): Promise { + const memberid = parseInt(req.params.memberId); + + res.json([]); +} + +/** + * @description get communications by member + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function getCommunicationsByMember(req: Request, res: Response): Promise { + const memberid = parseInt(req.params.memberId); + + res.json([]); +} + +/** + * @description create member + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function createMember(req: Request, res: Response): Promise { + res.status(200).send(0); +} + +/** + * @description add memberships to member + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function addMembershipToMember(req: Request, res: Response): Promise { + const memberid = parseInt(req.params.memberId); + + res.sendStatus(204); +} + +/** + * @description add awards to member + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function addAwardToMember(req: Request, res: Response): Promise { + const memberid = parseInt(req.params.memberId); + + res.sendStatus(204); +} + +/** + * @description add qualifications to member + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function addQualificationToMember(req: Request, res: Response): Promise { + const memberid = parseInt(req.params.memberId); + + res.sendStatus(204); +} + +/** + * @description add executive positions to member + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function addExecutivePositionToMember(req: Request, res: Response): Promise { + const memberid = parseInt(req.params.memberId); + + res.sendStatus(204); +} + +/** + * @description add communications to member + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function addCommunicationToMember(req: Request, res: Response): Promise { + const memberid = parseInt(req.params.memberId); + + res.sendStatus(204); +} + +/** + * @description update member by id + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function updateMemberById(req: Request, res: Response): Promise { + const memberid = parseInt(req.params.id); + + res.sendStatus(204); +} + +/** + * @description update membership of member + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function updateMembershipOfMember(req: Request, res: Response): Promise { + const memberid = parseInt(req.params.memberId); + const membershipId = parseInt(req.params.membershipId); + + res.sendStatus(204); +} + +/** + * @description update award of member + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function updateAwardOfMember(req: Request, res: Response): Promise { + const memberid = parseInt(req.params.memberId); + const awardId = parseInt(req.params.awardId); + + res.sendStatus(204); +} + +/** + * @description update qualification of member + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function updateQualificationOfMember(req: Request, res: Response): Promise { + const memberid = parseInt(req.params.memberId); + const qualificationId = parseInt(req.params.qualificationId); + + res.sendStatus(204); +} + +/** + * @description update executive position of member + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function updateExecutivePositionOfMember(req: Request, res: Response): Promise { + const memberid = parseInt(req.params.memberId); + const positionId = parseInt(req.params.positionId); + + res.sendStatus(204); +} + +/** + * @description update communication of member + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function updateCommunicationOfMember(req: Request, res: Response): Promise { + const memberid = parseInt(req.params.memberId); + const communicationId = parseInt(req.params.communicationId); + + res.sendStatus(204); +} + +/** + * @description delete member by id + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function deleteMemberById(req: Request, res: Response): Promise { + const memberid = parseInt(req.params.id); + + res.sendStatus(204); +} + +/** + * @description delete membership from member + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function deleteMembershipOfMember(req: Request, res: Response): Promise { + const memberid = parseInt(req.params.memberId); + const membershipId = parseInt(req.params.membershipId); + + res.sendStatus(204); +} + +/** + * @description delete award from member + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function deleteAwardOfMember(req: Request, res: Response): Promise { + const memberid = parseInt(req.params.memberId); + const awardId = parseInt(req.params.awardId); + + res.sendStatus(204); +} + +/** + * @description delete qualification from member + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function deleteQualificationOfMember(req: Request, res: Response): Promise { + const memberid = parseInt(req.params.memberId); + const qualificationId = parseInt(req.params.qualificationId); + + res.sendStatus(204); +} + +/** + * @description delete executive position from member + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function deleteExecutivePositionOfMember(req: Request, res: Response): Promise { + const memberid = parseInt(req.params.memberId); + const positionId = parseInt(req.params.positionId); + + res.sendStatus(204); +} + +/** + * @description delete communication from member + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function deleteCommunicationOfMember(req: Request, res: Response): Promise { + const memberid = parseInt(req.params.memberId); + const communicationId = parseInt(req.params.communicationId); + + res.sendStatus(204); +} diff --git a/src/controller/admin/membershipStatusController.ts b/src/controller/admin/membershipStatusController.ts index 04c153b..e840773 100644 --- a/src/controller/admin/membershipStatusController.ts +++ b/src/controller/admin/membershipStatusController.ts @@ -33,18 +33,6 @@ export async function getMembershipStatusById(req: Request, res: Response): Prom res.json(MembershipStatusFactory.mapToSingle(status)); } -/** - * @description get members assigned to membershipStatus by id - * @param req {Request} Express req object - * @param res {Response} Express res object - * @returns {Promise<*>} - */ -export async function getMembershipStatusAssignedMembers(req: Request, res: Response): Promise { - const membershipStatusId = parseInt(req.params.id); - - res.json({}); -} - /** * @description create new membershipStatus * @param req {Request} Express req object diff --git a/src/controller/admin/qualificationController.ts b/src/controller/admin/qualificationController.ts index 1164b2a..c7074d5 100644 --- a/src/controller/admin/qualificationController.ts +++ b/src/controller/admin/qualificationController.ts @@ -33,18 +33,6 @@ export async function getQualificationById(req: Request, res: Response): Promise res.json(QualificationFactory.mapToSingle(qualification)); } -/** - * @description get members assigned to qualification by id - * @param req {Request} Express req object - * @param res {Response} Express res object - * @returns {Promise<*>} - */ -export async function getQualificationAssignedMembers(req: Request, res: Response): Promise { - const qualificationId = parseInt(req.params.id); - - res.json({}); -} - /** * @description create new qualification * @param req {Request} Express req object diff --git a/src/factory/admin/member.ts b/src/factory/admin/member.ts new file mode 100644 index 0000000..68fa034 --- /dev/null +++ b/src/factory/admin/member.ts @@ -0,0 +1,29 @@ +import { member } from "../../entity/member"; +import { MemberViewModel } from "../../viewmodel/admin/member.models"; + +export default abstract class MemberFactory { + /** + * @description map record to member + * @param {member} record + * @returns {MemberViewModel} + */ + public static mapToSingle(record: member): MemberViewModel { + return { + id: record.id, + salutation: record.salutation, + firstname: record.firstname, + lastname: record.lastname, + nameaffix: record.nameaffix, + birthdate: record.birthdate, + }; + } + + /** + * @description map records to member + * @param {Array} records + * @returns {Array} + */ + public static mapToBase(records: Array): Array { + return records.map((r) => this.mapToSingle(r)); + } +} diff --git a/src/routes/admin/index.ts b/src/routes/admin/index.ts index 654c8d4..c0c1ab9 100644 --- a/src/routes/admin/index.ts +++ b/src/routes/admin/index.ts @@ -7,6 +7,8 @@ import executivePosition from "./executivePosition"; import membershipStatus from "./membershipStatus"; import qualification from "./qualification"; +import member from "./member"; + import role from "./role"; import user from "./user"; @@ -30,6 +32,8 @@ router.use( ); router.use("/qualification", PermissionHelper.passCheckMiddleware("read", "settings", "qualification"), qualification); +router.use("/member", PermissionHelper.passCheckMiddleware("read", "club", "member"), member); + router.use("/role", PermissionHelper.passCheckMiddleware("read", "user", "role"), role); router.use("/user", PermissionHelper.passCheckMiddleware("read", "user", "user"), user); diff --git a/src/routes/admin/member.ts b/src/routes/admin/member.ts new file mode 100644 index 0000000..af4f54b --- /dev/null +++ b/src/routes/admin/member.ts @@ -0,0 +1,132 @@ +import express, { Request, Response } from "express"; +import { + addAwardToMember, + addCommunicationToMember, + addExecutivePositionToMember, + addMembershipToMember, + addQualificationToMember, + createMember, + deleteAwardOfMember, + deleteCommunicationOfMember, + deleteExecutivePositionOfMember, + deleteMemberById, + deleteMembershipOfMember, + deleteQualificationOfMember, + getAllMembers, + getAwardsByMember, + getCommunicationsByMember, + getExecutivePositionsByMember, + getMemberById, + getMembershipsByMember, + getQualificationsByMember, + updateAwardOfMember, + updateCommunicationOfMember, + updateExecutivePositionOfMember, + updateMemberById, + updateMembershipOfMember, + updateQualificationOfMember, +} from "../../controller/admin/memberController"; + +var router = express.Router({ mergeParams: true }); + +router.get("/", async (req: Request, res: Response) => { + await getAllMembers(req, res); +}); + +router.get("/:id", async (req: Request, res: Response) => { + await getMemberById(req, res); +}); + +router.get("/:memberId/memberships", async (req: Request, res: Response) => { + await getMembershipsByMember(req, res); +}); + +router.get("/:memberId/awards", async (req: Request, res: Response) => { + await getAwardsByMember(req, res); +}); + +router.get("/:memberId/qualifications", async (req: Request, res: Response) => { + await getQualificationsByMember(req, res); +}); + +router.get("/:memberId/positions", async (req: Request, res: Response) => { + await getExecutivePositionsByMember(req, res); +}); + +router.get("/:memberId/communications", async (req: Request, res: Response) => { + await getCommunicationsByMember(req, res); +}); + +router.post("/", async (req: Request, res: Response) => { + await createMember(req, res); +}); + +router.post("/:memberId/membership", async (req: Request, res: Response) => { + await addMembershipToMember(req, res); +}); + +router.post("/:memberId/award", async (req: Request, res: Response) => { + await addAwardToMember(req, res); +}); + +router.post("/:memberId/qualification", async (req: Request, res: Response) => { + await addQualificationToMember(req, res); +}); + +router.post("/:memberId/position", async (req: Request, res: Response) => { + await addExecutivePositionToMember(req, res); +}); + +router.post("/:memberId/communication", async (req: Request, res: Response) => { + await addCommunicationToMember(req, res); +}); + +router.patch("/:id", async (req: Request, res: Response) => { + await updateMemberById(req, res); +}); + +router.patch("/:memberId/membership/:membershipId", async (req: Request, res: Response) => { + await updateMembershipOfMember(req, res); +}); + +router.patch("/:memberId/award/:awardId", async (req: Request, res: Response) => { + await updateAwardOfMember(req, res); +}); + +router.patch("/:memberId/qualification/:qualificationId", async (req: Request, res: Response) => { + await updateQualificationOfMember(req, res); +}); + +router.patch("/:memberId/position/:positionId", async (req: Request, res: Response) => { + await updateExecutivePositionOfMember(req, res); +}); + +router.patch("/:memberId/communication/:communicationId", async (req: Request, res: Response) => { + await updateCommunicationOfMember(req, res); +}); + +router.delete("/:id", async (req: Request, res: Response) => { + await deleteMemberById(req, res); +}); + +router.delete("/:memberId/membership/:membershipId", async (req: Request, res: Response) => { + await deleteMembershipOfMember(req, res); +}); + +router.delete("/:memberId/award/:awardId", async (req: Request, res: Response) => { + await deleteAwardOfMember(req, res); +}); + +router.delete("/:memberId/qualification/:qualificationId", async (req: Request, res: Response) => { + await deleteQualificationOfMember(req, res); +}); + +router.delete("/:memberId/position/:positionId", async (req: Request, res: Response) => { + await deleteExecutivePositionOfMember(req, res); +}); + +router.delete("/:memberId/communication/:communicationId", async (req: Request, res: Response) => { + await deleteCommunicationOfMember(req, res); +}); + +export default router; diff --git a/src/service/awardService.ts b/src/service/awardService.ts index 4d8c7b4..a24f126 100644 --- a/src/service/awardService.ts +++ b/src/service/awardService.ts @@ -38,23 +38,4 @@ export default abstract class AwardService { throw new InternalException("award not found by id", err); }); } - - /** - * @description get members assigned to award - * @returns {Promise>} - */ - static async getMembersByAwardId(id: number): Promise> { - return await dataSource - .getRepository(award) - .createQueryBuilder("award") - .leftJoinAndSelect("award.members", "members") - .where("award.id = :id", { id: id }) - .getOneOrFail() - .then((res) => { - return []; - }) - .catch((err) => { - throw new InternalException("award assigned members not found by id", err); - }); - } } diff --git a/src/service/executivePositionService.ts b/src/service/executivePositionService.ts index e632254..344ad20 100644 --- a/src/service/executivePositionService.ts +++ b/src/service/executivePositionService.ts @@ -38,24 +38,4 @@ export default abstract class ExecutivePositionService { throw new InternalException("executivePosition not found by id", err); }); } - - /** - * @description get members assigned to executivePosition - * @returns {Promise>} - */ - static async getMembersByexecutivePositionId(id: number): Promise> { - return await dataSource - .getRepository(executivePosition) - .createQueryBuilder("executivePosition") - .leftJoinAndSelect("executivePosition.members", "memberExecutivePositions") - .leftJoinAndSelect("memberExecutivePositions.member", "member") - .where("executivePosition.id = :id", { id: id }) - .getOneOrFail() - .then((res) => { - return res.members; - }) - .catch(() => { - throw new InternalException("executivePosition assigned members not found by id"); - }); - } } diff --git a/src/service/memberService.ts b/src/service/memberService.ts new file mode 100644 index 0000000..22d430f --- /dev/null +++ b/src/service/memberService.ts @@ -0,0 +1,41 @@ +import { dataSource } from "../data-source"; +import { member } from "../entity/member"; +import InternalException from "../exceptions/internalException"; + +export default abstract class MemberService { + /** + * @description get all members + * @returns {Promise>} + */ + static async getAll(): Promise> { + return await dataSource + .getRepository(member) + .createQueryBuilder("member") + .getMany() + .then((res) => { + return res; + }) + .catch((err) => { + throw new InternalException("members not found", err); + }); + } + + /** + * @description get member by id + * @param {number} id + * @returns {Promise>} + */ + static async getById(id: number): Promise { + return await dataSource + .getRepository(member) + .createQueryBuilder("member") + .where("member.id = :id", { id: id }) + .getOneOrFail() + .then((res) => { + return res; + }) + .catch((err) => { + throw new InternalException("member not found by id", err); + }); + } +} diff --git a/src/service/membershipStatusService.ts b/src/service/membershipStatusService.ts index 642aafb..b1032c6 100644 --- a/src/service/membershipStatusService.ts +++ b/src/service/membershipStatusService.ts @@ -38,27 +38,4 @@ export default abstract class MembershipStatusService { throw new InternalException("membershipStatus not found by id", err); }); } - - /** - * @description get active memberships assigned to membershipStatus - * @returns {Promise>} - */ - static async getMembersBymembershipStatusId(id: number): Promise> { - return await dataSource - .getRepository(membershipStatus) - .createQueryBuilder("membershipStatus") - .leftJoinAndSelect("membershipStatus.memberships", "memberships") - .leftJoinAndSelect("memberships.member", "member") - .where("membershipStatus.id = :id", { id: id }) - .andWhere("membership.start <= :start", { start: new Date() }) - .andWhere("membership.end >= :end", { end: new Date() }) - .orWhere("membership.end IS NULL") - .getOneOrFail() - .then((res) => { - return res.memberships; - }) - .catch((err) => { - throw new InternalException("membershipStatus assigned members not found by id", err); - }); - } } diff --git a/src/service/qualification.ts b/src/service/qualification.ts index 9db6bb1..4009b64 100644 --- a/src/service/qualification.ts +++ b/src/service/qualification.ts @@ -39,24 +39,4 @@ export default abstract class QualificationService { throw new InternalException("qualification not found by id", err); }); } - - /** - * @description get members assigned to qualification - * @returns {Promise>} - */ - static async getMembersByqualificationId(id: number): Promise> { - return await dataSource - .getRepository(qualification) - .createQueryBuilder("qualification") - .leftJoinAndSelect("qualification.members", "memberQualifications") - .leftJoinAndSelect("memberQualifications.members", "members") - .where("qualification.id = :id", { id: id }) - .getOneOrFail() - .then((res) => { - return res.members; - }) - .catch((err) => { - throw new InternalException("qualification assigned members not found by id", err); - }); - } } diff --git a/src/type/permissionTypes.ts b/src/type/permissionTypes.ts index 7e8751d..3bd54c8 100644 --- a/src/type/permissionTypes.ts +++ b/src/type/permissionTypes.ts @@ -1,7 +1,7 @@ export type PermissionSection = "club" | "settings" | "user"; export type PermissionModule = - | "members" + | "member" | "calendar" | "newsletter" | "protocoll" @@ -36,7 +36,7 @@ export type SectionsAndModulesObject = { export const permissionSections: Array = ["club", "settings", "user"]; export const permissionModules: Array = [ - "members", + "member", "calendar", "newsletter", "protocoll", @@ -50,7 +50,7 @@ export const permissionModules: Array = [ ]; export const permissionTypes: Array = ["read", "create", "update", "delete"]; export const sectionsAndModules: SectionsAndModulesObject = { - club: ["members", "calendar", "newsletter", "protocoll"], + club: ["member", "calendar", "newsletter", "protocoll"], settings: ["qualification", "award", "executive_position", "communication", "membership_status"], user: ["user", "role"], }; diff --git a/src/viewmodel/admin/member.models.ts b/src/viewmodel/admin/member.models.ts new file mode 100644 index 0000000..afd04aa --- /dev/null +++ b/src/viewmodel/admin/member.models.ts @@ -0,0 +1,10 @@ +import { Salutation } from "../../enums/salutation"; + +export interface MemberViewModel { + id: number; + salutation: Salutation; + firstname: string; + lastname: string; + nameaffix: string; + birthdate: Date; +}