#25-cleanup-&-enhancements #27

Merged
jkeffects merged 2 commits from #25-cleanup-&-enhancements into main 2025-01-03 14:22:21 +00:00
3 changed files with 27 additions and 5 deletions
Showing only changes of commit b68e546788 - Show all commits

2
.gitignore vendored
View file

@ -131,3 +131,5 @@ dist
.pnp.*
export
.idea

View file

@ -58,7 +58,9 @@ import CommunicationCommandHandler from "../../command/communicationCommandHandl
export async function getAllMembers(req: Request, res: Response): Promise<any> {
let offset = parseInt((req.query.offset as string) ?? "0");
let count = parseInt((req.query.count as string) ?? "25");
let [members, total] = await MemberService.getAll(offset, count);
let search = (req.query.search as string) ?? "";
let [members, total] = await MemberService.getAll(offset, count, search);
res.json({
members: MemberFactory.mapToBase(members),

View file

@ -8,8 +8,8 @@ export default abstract class MemberService {
* @description get all members
* @returns {Promise<[Array<member>, number]>}
*/
static async getAll(offset: number = 0, count: number = 25): Promise<[Array<member>, number]> {
return await dataSource
static async getAll(offset: number = 0, count: number = 25, search: string = ""): Promise<[Array<member>, number]> {
let query = await dataSource
.getRepository(member)
.createQueryBuilder("member")
.leftJoinAndMapOne(
@ -36,7 +36,25 @@ export default abstract class MemberService {
)
.leftJoinAndSelect("preferredCommunication.type", "communicationtype_preferred")
.leftJoinAndMapMany("member.smsAlarming", "member.communications", "smsAlarming", "smsAlarming.isSMSAlarming = 1")
.leftJoinAndSelect("smsAlarming.type", "communicationtype_smsAlarming")
.leftJoinAndSelect("smsAlarming.type", "communicationtype_smsAlarming");
if (search != "") {
search.split(" ").forEach((term, index) => {
const searchQuery = `%${term}%`;
const dynamic = "searchQuery" + Math.random().toString(36).substring(2);
if (index == 0) {
query = query.where(`member.firstname LIKE :${dynamic} OR member.lastname LIKE :${dynamic}`, {
[dynamic]: searchQuery,
});
} else {
query = query.orWhere(`member.firstname LIKE :${dynamic} OR member.lastname LIKE :${dynamic}`, {
[dynamic]: searchQuery,
});
}
});
}
return query
.offset(offset)
.limit(count)
.orderBy("member.lastname")