Compare commits
No commits in common. "83e145a93b098013e7294af24260a63c98e780a3" and "9afb205da54da103a88b2aea7c4f876d68a7d3b4" have entirely different histories.
83e145a93b
...
9afb205da5
4 changed files with 6 additions and 28 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -130,6 +130,4 @@ dist
|
||||||
.yarn/install-state.gz
|
.yarn/install-state.gz
|
||||||
.pnp.*
|
.pnp.*
|
||||||
|
|
||||||
export
|
export
|
||||||
|
|
||||||
.idea
|
|
|
@ -58,9 +58,7 @@ 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 search = (req.query.search as string) ?? "";
|
let [members, total] = await MemberService.getAll(offset, count);
|
||||||
|
|
||||||
let [members, total] = await MemberService.getAll(offset, count, search);
|
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
members: MemberFactory.mapToBase(members),
|
members: MemberFactory.mapToBase(members),
|
||||||
|
|
|
@ -263,7 +263,7 @@ export default abstract class DynamicQueryBuilder {
|
||||||
results = tempResults;
|
results = tempResults;
|
||||||
} else {
|
} else {
|
||||||
results.forEach((res) => {
|
results.forEach((res) => {
|
||||||
if (String(value) != "undefined") res[newKey] = String(value);
|
res[newKey] = String(value);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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, search: string = ""): Promise<[Array<member>, number]> {
|
static async getAll(offset: number = 0, count: number = 25): Promise<[Array<member>, number]> {
|
||||||
let query = await dataSource
|
return await dataSource
|
||||||
.getRepository(member)
|
.getRepository(member)
|
||||||
.createQueryBuilder("member")
|
.createQueryBuilder("member")
|
||||||
.leftJoinAndMapOne(
|
.leftJoinAndMapOne(
|
||||||
|
@ -36,25 +36,7 @@ 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")
|
||||||
|
|
Loading…
Reference in a new issue