Compare commits
2 commits
8b59f3b7a8
...
0bbe22e9ae
Author | SHA1 | Date | |
---|---|---|---|
0bbe22e9ae | |||
9734149848 |
3 changed files with 28 additions and 5 deletions
|
@ -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),
|
||||||
|
|
|
@ -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));
|
||||||
}
|
}
|
||||||
|
|
|
@ -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")
|
||||||
|
|
Loading…
Reference in a new issue