#25-cleanup-&-enhancements #27
3 changed files with 27 additions and 5 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -130,4 +130,6 @@ dist
|
|||
.yarn/install-state.gz
|
||||
.pnp.*
|
||||
|
||||
export
|
||||
export
|
||||
|
||||
.idea
|
|
@ -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),
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Reference in a new issue