From e455b5c8f69bd2c027499ffc1c1a821706fc9b19 Mon Sep 17 00:00:00 2001 From: Julian Krauser Date: Sun, 15 Sep 2024 14:03:15 +0200 Subject: [PATCH] service to memberdata --- src/service/awardService.ts | 40 +++++++++++----------- src/service/communicationService.ts | 2 +- src/service/communicationTypeService.ts | 23 +------------ src/service/executivePositionService.ts | 41 ++++++++++++----------- src/service/membershipStatusService.ts | 44 ++++++++++++++----------- src/service/qualification.ts | 40 +++++++++++----------- 6 files changed, 88 insertions(+), 102 deletions(-) diff --git a/src/service/awardService.ts b/src/service/awardService.ts index 17c4690..4d8c7b4 100644 --- a/src/service/awardService.ts +++ b/src/service/awardService.ts @@ -1,6 +1,6 @@ import { dataSource } from "../data-source"; import { award } from "../entity/award"; -import { user } from "../entity/user"; +import { member } from "../entity/member"; import InternalException from "../exceptions/internalException"; export default abstract class AwardService { @@ -29,7 +29,7 @@ export default abstract class AwardService { return await dataSource .getRepository(award) .createQueryBuilder("award") - .andWhere("award.id = :id", { id: id }) + .where("award.id = :id", { id: id }) .getOneOrFail() .then((res) => { return res; @@ -39,22 +39,22 @@ export default abstract class AwardService { }); } - // /** - // * @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") - // .andWhere("award.id = :id", { id: id }) - // .getOneOrFail() - // .then((res) => { - // return []; - // }) - // .catch((err) => { - // throw new InternalException("award assigned members 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/communicationService.ts b/src/service/communicationService.ts index 38f4917..09bf1f3 100644 --- a/src/service/communicationService.ts +++ b/src/service/communicationService.ts @@ -12,7 +12,7 @@ export default abstract class CommunicationService { .getRepository(communication) .createQueryBuilder("communication") .leftJoin("communication.user", "user") - .andWhere("user.id = :id", { id: userId }) + .where("user.id = :id", { id: userId }) .getOneOrFail() .then((res) => { return res; diff --git a/src/service/communicationTypeService.ts b/src/service/communicationTypeService.ts index 6e010f7..7edb4e2 100644 --- a/src/service/communicationTypeService.ts +++ b/src/service/communicationTypeService.ts @@ -1,7 +1,5 @@ import { dataSource } from "../data-source"; -import { communication } from "../entity/communication"; import { communicationType } from "../entity/communicationType"; -import { user } from "../entity/user"; import InternalException from "../exceptions/internalException"; export default abstract class CommunicationTypeService { @@ -30,7 +28,7 @@ export default abstract class CommunicationTypeService { return await dataSource .getRepository(communicationType) .createQueryBuilder("communicationType") - .andWhere("communicationType.id = :id", { id: id }) + .where("communicationType.id = :id", { id: id }) .getOneOrFail() .then((res) => { return res; @@ -39,23 +37,4 @@ export default abstract class CommunicationTypeService { throw new InternalException("communicationType not found by id", err); }); } - - // /** - // * @description get members assigned to communicationType - // * @returns {Promise>} - // */ - // static async getMembersBycommunicationTypeId(id: number): Promise> { - // return await dataSource - // .getRepository(communicationType) - // .createQueryBuilder("communicationType") - // .leftJoinAndSelect("communicationType.members", "members") - // .andWhere("communicationType.id = :id", { id: id }) - // .getOneOrFail() - // .then((res) => { - // return []; - // }) - // .catch((err) => { - // throw new InternalException("communicationType assigned members not found by id", err); - // }); - // } } diff --git a/src/service/executivePositionService.ts b/src/service/executivePositionService.ts index 6fb3013..e632254 100644 --- a/src/service/executivePositionService.ts +++ b/src/service/executivePositionService.ts @@ -1,6 +1,6 @@ import { dataSource } from "../data-source"; import { executivePosition } from "../entity/executivePosition"; -import { user } from "../entity/user"; +import { memberExecutivePositions } from "../entity/memberExecutivePositions"; import InternalException from "../exceptions/internalException"; export default abstract class ExecutivePositionService { @@ -29,7 +29,7 @@ export default abstract class ExecutivePositionService { return await dataSource .getRepository(executivePosition) .createQueryBuilder("executivePosition") - .andWhere("executivePosition.id = :id", { id: id }) + .where("executivePosition.id = :id", { id: id }) .getOneOrFail() .then((res) => { return res; @@ -39,22 +39,23 @@ export default abstract class ExecutivePositionService { }); } - // /** - // * @description get members assigned to executivePosition - // * @returns {Promise>} - // */ - // static async getMembersByexecutivePositionId(id: number): Promise> { - // return await dataSource - // .getRepository(executivePosition) - // .createQueryBuilder("executivePosition") - // .leftJoinAndSelect("executivePosition.members", "members") - // .andWhere("executivePosition.id = :id", { id: id }) - // .getOneOrFail() - // .then((res) => { - // return []; - // }) - // .catch(() => { - // throw new InternalException("executivePosition assigned members not found by id"); - // }); - // } + /** + * @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/membershipStatusService.ts b/src/service/membershipStatusService.ts index 5b33f46..642aafb 100644 --- a/src/service/membershipStatusService.ts +++ b/src/service/membershipStatusService.ts @@ -1,7 +1,7 @@ import { dataSource } from "../data-source"; import { membershipStatus } from "../entity/membershipStatus"; -import { user } from "../entity/user"; import InternalException from "../exceptions/internalException"; +import { membership } from "../entity/membership"; export default abstract class MembershipStatusService { /** @@ -29,7 +29,7 @@ export default abstract class MembershipStatusService { return await dataSource .getRepository(membershipStatus) .createQueryBuilder("membershipStatus") - .andWhere("membershipStatus.id = :id", { id: id }) + .where("membershipStatus.id = :id", { id: id }) .getOneOrFail() .then((res) => { return res; @@ -39,22 +39,26 @@ export default abstract class MembershipStatusService { }); } - // /** - // * @description get members assigned to membershipStatus - // * @returns {Promise>} - // */ - // static async getMembersBymembershipStatusId(id: number): Promise> { - // return await dataSource - // .getRepository(membershipStatus) - // .createQueryBuilder("membershipStatus") - // .leftJoinAndSelect("membershipStatus.members", "members") - // .andWhere("membershipStatus.id = :id", { id: id }) - // .getOneOrFail() - // .then((res) => { - // return []; - // }) - // .catch((err) => { - // throw new InternalException("membershipStatus assigned members 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 a98fdf6..9db6bb1 100644 --- a/src/service/qualification.ts +++ b/src/service/qualification.ts @@ -1,4 +1,5 @@ import { dataSource } from "../data-source"; +import { memberQualifications } from "../entity/memberQualifications"; import { qualification } from "../entity/qualification"; import { user } from "../entity/user"; import InternalException from "../exceptions/internalException"; @@ -29,7 +30,7 @@ export default abstract class QualificationService { return await dataSource .getRepository(qualification) .createQueryBuilder("qualification") - .andWhere("qualification.id = :id", { id: id }) + .where("qualification.id = :id", { id: id }) .getOneOrFail() .then((res) => { return res; @@ -39,22 +40,23 @@ export default abstract class QualificationService { }); } - // /** - // * @description get members assigned to qualification - // * @returns {Promise>} - // */ - // static async getMembersByqualificationId(id: number): Promise> { - // return await dataSource - // .getRepository(qualification) - // .createQueryBuilder("qualification") - // .leftJoinAndSelect("qualification.members", "members") - // .andWhere("qualification.id = :id", { id: id }) - // .getOneOrFail() - // .then((res) => { - // return []; - // }) - // .catch((err) => { - // throw new InternalException("qualification assigned members 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); + }); + } }