feature/#32-Membership-statistics #48

Merged
jkeffects merged 2 commits from feature/#32-Membership-statistics into develop 2025-01-22 08:06:26 +00:00
4 changed files with 16 additions and 7 deletions
Showing only changes of commit ba2155d7c3 - Show all commits

View file

@ -123,10 +123,10 @@ export async function getMembershipsByMember(req: Request, res: Response): Promi
* @returns {Promise<*>}
*/
export async function getMembershipStatisticsById(req: Request, res: Response): Promise<any> {
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));
}
/**

View file

@ -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<membershipView>} records
* @returns {Array<MembershipStatisticsViewModel>}
*/
public static mapToBaseStatistics(records: Array<membershipView>): Array<MembershipStatisticsViewModel> {
return records.map((r) => this.mapToSingleStatistic(r));
}
}

View file

@ -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);
});

View file

@ -50,14 +50,14 @@ export default abstract class MembershipService {
/**
* @description get membership statistics by memberId
* @param {number} memberId
* @returns {Promise<membershipView>}
* @returns {Promise<Array<membershipView>>}
*/
static async getStatisticsById(memberId: number): Promise<membershipView> {
static async getStatisticsById(memberId: number): Promise<Array<membershipView>> {
return await dataSource
.getRepository(membershipView)
.createQueryBuilder("membershipView")
.where("membershipView.memberId = :memberId", { memberId: memberId })
.getOneOrFail()
.getMany()
.then((res) => {
return res;
})