#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

4
.gitignore vendored
View file

@ -130,4 +130,6 @@ dist
.yarn/install-state.gz
.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> {
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

@ -263,7 +263,7 @@ export default abstract class DynamicQueryBuilder {
results = tempResults;
} else {
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
* @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")