fix types and params

This commit is contained in:
Julian Krauser 2025-01-22 08:59:38 +01:00
parent 07d31bfe7d
commit ba2155d7c3
4 changed files with 16 additions and 7 deletions

View file

@ -123,10 +123,10 @@ export async function getMembershipsByMember(req: Request, res: Response): Promi
* @returns {Promise<*>} * @returns {Promise<*>}
*/ */
export async function getMembershipStatisticsById(req: Request, res: Response): Promise<any> { 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); 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 * @param {membershipView} record
* @returns {MembershipStatisticsViewModel} * @returns {MembershipStatisticsViewModel}
*/ */
public static mapToMembershipStatistic(record: membershipView): MembershipStatisticsViewModel { public static mapToSingleStatistic(record: membershipView): MembershipStatisticsViewModel {
return { return {
durationInDays: record.durationInDays, durationInDays: record.durationInDays,
durationInYears: record.durationInYears, durationInYears: record.durationInYears,
@ -50,4 +50,13 @@ export default abstract class MembershipFactory {
memberBirthdate: record.memberBirthdate, 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); 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); await getMembershipStatisticsById(req, res);
}); });

View file

@ -50,14 +50,14 @@ export default abstract class MembershipService {
/** /**
* @description get membership statistics by memberId * @description get membership statistics by memberId
* @param {number} 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 return await dataSource
.getRepository(membershipView) .getRepository(membershipView)
.createQueryBuilder("membershipView") .createQueryBuilder("membershipView")
.where("membershipView.memberId = :memberId", { memberId: memberId }) .where("membershipView.memberId = :memberId", { memberId: memberId })
.getOneOrFail() .getMany()
.then((res) => { .then((res) => {
return res; return res;
}) })