refacto GET method with search params for users
This commit is contained in:
parent
3ca6a0565d
commit
0bfe80b9a0
@ -27,9 +27,24 @@ export default class UsersController extends ApiController {
|
|||||||
if (req.query["q"]) {
|
if (req.query["q"]) {
|
||||||
query = JSON.parse(req.query["q"] as string);
|
query = JSON.parse(req.query["q"] as string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (req.query["search"] && typeof req.query["search"] === "string") {
|
||||||
|
const filter = req.query["search"];
|
||||||
|
query = {
|
||||||
|
where: {
|
||||||
|
contact: {
|
||||||
|
OR: [
|
||||||
|
{ first_name: { contains: filter, mode: "insensitive" } },
|
||||||
|
{ last_name: { contains: filter, mode: "insensitive" } },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const officeId: string = req.body.user.office_Id;
|
const officeId: string = req.body.user.office_Id;
|
||||||
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
|
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId };
|
||||||
if(!query.where) query.where = { office_membership: officeWhereInput};
|
if (!query.where) query.where = { office_membership: officeWhereInput };
|
||||||
query.where.office_membership = officeWhereInput;
|
query.where.office_membership = officeWhereInput;
|
||||||
|
|
||||||
//call service to get prisma entity
|
//call service to get prisma entity
|
||||||
|
@ -27,6 +27,20 @@ export default class UsersController extends ApiController {
|
|||||||
query = JSON.parse(req.query["q"] as string);
|
query = JSON.parse(req.query["q"] as string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (req.query["search"] && typeof req.query["search"] === "string") {
|
||||||
|
const filter = req.query["search"];
|
||||||
|
query = {
|
||||||
|
where: {
|
||||||
|
contact: {
|
||||||
|
OR: [
|
||||||
|
{ first_name: { contains: filter, mode: "insensitive" } },
|
||||||
|
{ last_name: { contains: filter, mode: "insensitive" } },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
//call service to get prisma entity
|
//call service to get prisma entity
|
||||||
const usersEntities = await this.usersService.get(query);
|
const usersEntities = await this.usersService.get(query);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user