#25-cleanup-&-enhancements #27

Merged
jkeffects merged 2 commits from #25-cleanup-&-enhancements into main 2025-01-03 14:22:21 +00:00
4 changed files with 28 additions and 6 deletions

2
.gitignore vendored
View file

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

View file

@ -58,7 +58,9 @@ import CommunicationCommandHandler from "../../command/communicationCommandHandl
export async function getAllMembers(req: Request, res: Response): Promise<any> { 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 [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({ res.json({
members: MemberFactory.mapToBase(members), members: MemberFactory.mapToBase(members),

View file

@ -263,7 +263,7 @@ export default abstract class DynamicQueryBuilder {
results = tempResults; results = tempResults;
} else { } else {
results.forEach((res) => { results.forEach((res) => {
res[newKey] = String(value); if (String(value) != "undefined") res[newKey] = String(value);
}); });
} }
} }

View file

@ -8,8 +8,8 @@ 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): Promise<[Array<member>, number]> { static async getAll(offset: number = 0, count: number = 25, search: string = ""): Promise<[Array<member>, number]> {
return await dataSource let query = await dataSource
.getRepository(member) .getRepository(member)
.createQueryBuilder("member") .createQueryBuilder("member")
.leftJoinAndMapOne( .leftJoinAndMapOne(
@ -36,7 +36,25 @@ export default abstract class MemberService {
) )
.leftJoinAndSelect("preferredCommunication.type", "communicationtype_preferred") .leftJoinAndSelect("preferredCommunication.type", "communicationtype_preferred")
.leftJoinAndMapMany("member.smsAlarming", "member.communications", "smsAlarming", "smsAlarming.isSMSAlarming = 1") .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) .offset(offset)
.limit(count) .limit(count)
.orderBy("member.lastname") .orderBy("member.lastname")