diff --git a/src/controller/admin/club/memberController.ts b/src/controller/admin/club/memberController.ts index 1111346..4970ead 100644 --- a/src/controller/admin/club/memberController.ts +++ b/src/controller/admin/club/memberController.ts @@ -123,10 +123,10 @@ export async function getMembershipsByMember(req: Request, res: Response): Promi * @returns {Promise<*>} */ export async function getMembershipStatisticsById(req: Request, res: Response): Promise { - const memberId = parseInt(req.params.id); + const memberId = parseInt(req.params.memberId); let member = await MembershipService.getStatisticsById(memberId); - res.json(MembershipFactory.mapToMembershipStatistic(member)); + res.json(MembershipFactory.mapToBaseStatistics(member)); } /** diff --git a/src/factory/admin/club/member/membership.ts b/src/factory/admin/club/member/membership.ts index 56e0dbc..42980ab 100644 --- a/src/factory/admin/club/member/membership.ts +++ b/src/factory/admin/club/member/membership.ts @@ -36,7 +36,7 @@ export default abstract class MembershipFactory { * @param {membershipView} record * @returns {MembershipStatisticsViewModel} */ - public static mapToMembershipStatistic(record: membershipView): MembershipStatisticsViewModel { + public static mapToSingleStatistic(record: membershipView): MembershipStatisticsViewModel { return { durationInDays: record.durationInDays, durationInYears: record.durationInYears, @@ -50,4 +50,13 @@ export default abstract class MembershipFactory { memberBirthdate: record.memberBirthdate, }; } + + /** + * @description map records to MembershipStatisticsViewModel + * @param {Array} records + * @returns {Array} + */ + public static mapToBaseStatistics(records: Array): Array { + return records.map((r) => this.mapToSingleStatistic(r)); + } } diff --git a/src/routes/admin/club/member.ts b/src/routes/admin/club/member.ts index f621e0e..66e57aa 100644 --- a/src/routes/admin/club/member.ts +++ b/src/routes/admin/club/member.ts @@ -58,7 +58,7 @@ router.get("/:memberId/memberships", async (req: Request, res: Response) => { await getMembershipsByMember(req, res); }); -router.get("/:memberId/statistics/memberships", async (req: Request, res: Response) => { +router.get("/:memberId/memberships/statistics", async (req: Request, res: Response) => { await getMembershipStatisticsById(req, res); }); diff --git a/src/service/club/member/membershipService.ts b/src/service/club/member/membershipService.ts index 604151f..8ef99e1 100644 --- a/src/service/club/member/membershipService.ts +++ b/src/service/club/member/membershipService.ts @@ -50,14 +50,14 @@ export default abstract class MembershipService { /** * @description get membership statistics by memberId * @param {number} memberId - * @returns {Promise} + * @returns {Promise>} */ - static async getStatisticsById(memberId: number): Promise { + static async getStatisticsById(memberId: number): Promise> { return await dataSource .getRepository(membershipView) .createQueryBuilder("membershipView") .where("membershipView.memberId = :memberId", { memberId: memberId }) - .getOneOrFail() + .getMany() .then((res) => { return res; })