refacto GET method with search param for folders
This commit is contained in:
parent
3ca6a0565d
commit
129cb6ad86
@ -28,6 +28,35 @@ export default class OfficeFoldersController extends ApiController {
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
}
|
||||
|
||||
if (req.query["search"] && typeof req.query["search"] === "string") {
|
||||
const filter = req.query["search"];
|
||||
query = {
|
||||
where: {
|
||||
OR: [
|
||||
{
|
||||
name: { contains: filter, mode: "insensitive" },
|
||||
},
|
||||
{
|
||||
folder_number: { contains: filter, mode: "insensitive" },
|
||||
},
|
||||
{
|
||||
customers: {
|
||||
some: {
|
||||
contact: {
|
||||
OR: [
|
||||
{ first_name: { contains: filter, mode: "insensitive" } },
|
||||
{ last_name: { contains: filter, mode: "insensitive" } },
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
|
||||
if(!query.where) query.where = { office: officeWhereInput};
|
||||
|
@ -28,6 +28,35 @@ export default class OfficeFoldersController extends ApiController {
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
}
|
||||
|
||||
if (req.query["search"] && typeof req.query["search"] === "string") {
|
||||
const filter = req.query["search"];
|
||||
query = {
|
||||
where: {
|
||||
OR: [
|
||||
{
|
||||
name: { contains: filter, mode: "insensitive" },
|
||||
},
|
||||
{
|
||||
folder_number: { contains: filter, mode: "insensitive" },
|
||||
},
|
||||
{
|
||||
customers: {
|
||||
some: {
|
||||
contact: {
|
||||
OR: [
|
||||
{ first_name: { contains: filter, mode: "insensitive" } },
|
||||
{ last_name: { contains: filter, mode: "insensitive" } },
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
|
||||
if(!query.where) query.where = { office: officeWhereInput};
|
||||
|
@ -28,9 +28,37 @@ export default class OfficeFoldersController extends ApiController {
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
}
|
||||
|
||||
if (req.query["search"] && typeof req.query["search"] === "string") {
|
||||
const filter = req.query["search"];
|
||||
query = {
|
||||
where: {
|
||||
OR: [
|
||||
{
|
||||
name: { contains: filter, mode: "insensitive" },
|
||||
},
|
||||
{
|
||||
folder_number: { contains: filter, mode: "insensitive" },
|
||||
},
|
||||
{
|
||||
customers: {
|
||||
some: {
|
||||
contact: {
|
||||
OR: [
|
||||
{ first_name: { contains: filter, mode: "insensitive" } },
|
||||
{ last_name: { contains: filter, mode: "insensitive" } },
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
}
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
|
||||
if(!query.where) query.where = { office: officeWhereInput};
|
||||
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId };
|
||||
if (!query.where) query.where = { office: officeWhereInput };
|
||||
query.where.office = officeWhereInput;
|
||||
|
||||
//call service to get prisma entity
|
||||
|
@ -12,14 +12,12 @@ export default async function folderHandler(req: Request, response: Response, ne
|
||||
const deed = req.body.deed;
|
||||
|
||||
if (office && office.uid != officeId) {
|
||||
console.log("wrong office");
|
||||
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
|
||||
return;
|
||||
}
|
||||
|
||||
if (deed) {
|
||||
const deedTypeService = Container.get(DeedTypesService);
|
||||
console.log("deed : ",deed);
|
||||
const deedTypeWithOffice = await deedTypeService.getByUidWithOffice(deed.deed_type.uid!);
|
||||
if (!deedTypeWithOffice) {
|
||||
response.status(HttpCodes.NOT_FOUND).send("Deed type not found");
|
||||
|
@ -58,10 +58,7 @@ export default class OfficeFoldersRepository extends BaseRepository {
|
||||
/**
|
||||
* @description : Update data of an office folder
|
||||
*/
|
||||
public async update(
|
||||
officeFolderuid: string,
|
||||
officeFolder: OfficeFolder,
|
||||
): Promise<OfficeFolders> {
|
||||
public async update(officeFolderuid: string, officeFolder: OfficeFolder): Promise<OfficeFolders> {
|
||||
const updateArgs: Prisma.OfficeFoldersUpdateArgs = {
|
||||
where: {
|
||||
uid: officeFolderuid,
|
||||
|
Loading…
x
Reference in New Issue
Block a user