Compare commits

...

3 commits

3 changed files with 28 additions and 5 deletions

View file

@ -61,8 +61,13 @@ export async function getAllMembers(req: Request, res: Response): Promise<any> {
let offset = parseInt((req.query.offset as string) ?? "0"); let offset = parseInt((req.query.offset as string) ?? "0");
let count = parseInt((req.query.count as string) ?? "25"); let count = parseInt((req.query.count as string) ?? "25");
let search = (req.query.search as string) ?? ""; let search = (req.query.search as string) ?? "";
let noLimit = req.query.noLimit === "true";
let ids = ((req.query.ids ?? "") as string)
.split(",")
.filter((i) => i)
.map((i) => parseInt(i));
let [members, total] = await MemberService.getAll(offset, count, search); let [members, total] = await MemberService.getAll({ offset, count, search, noLimit, ids });
res.json({ res.json({
members: MemberFactory.mapToBase(members), members: MemberFactory.mapToBase(members),

View file

@ -141,7 +141,7 @@ export abstract class NewsletterHelper {
} }
} }
let members = await MemberService.getAll(0, 1000); let members = await MemberService.getAll({ noLimit: true });
return members[0].filter((m) => queryMemberIds.includes(m.id)); return members[0].filter((m) => queryMemberIds.includes(m.id));
} }

View file

@ -8,7 +8,19 @@ export default abstract class MemberService {
* @description get all members * @description get all members
* @returns {Promise<[Array<member>, number]>} * @returns {Promise<[Array<member>, number]>}
*/ */
static async getAll(offset: number = 0, count: number = 25, search: string = ""): Promise<[Array<member>, number]> { static async getAll({
offset = 0,
count = 25,
search = "",
noLimit = false,
ids = [],
}: {
offset?: number;
count?: number;
search?: string;
noLimit?: boolean;
ids?: Array<number>;
}): Promise<[Array<member>, number]> {
let query = dataSource let query = dataSource
.getRepository(member) .getRepository(member)
.createQueryBuilder("member") .createQueryBuilder("member")
@ -54,9 +66,15 @@ export default abstract class MemberService {
}); });
} }
if (ids.length != 0) {
query = query.where({ id: ids });
}
if (!noLimit) {
query = query.offset(offset).limit(count);
}
return await query return await query
.offset(offset)
.limit(count)
.orderBy("member.lastname") .orderBy("member.lastname")
.addOrderBy("member.firstname") .addOrderBy("member.firstname")
.addOrderBy("member.nameaffix") .addOrderBy("member.nameaffix")