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"]) {
|
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: {
|
||||||
|
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 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: officeWhereInput};
|
if(!query.where) query.where = { office: officeWhereInput};
|
||||||
|
@ -28,6 +28,35 @@ export default class OfficeFoldersController 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: {
|
||||||
|
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 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: officeWhereInput};
|
if(!query.where) query.where = { office: officeWhereInput};
|
||||||
|
@ -28,9 +28,37 @@ export default class OfficeFoldersController 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: {
|
||||||
|
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 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: officeWhereInput};
|
if (!query.where) query.where = { office: officeWhereInput };
|
||||||
query.where.office = officeWhereInput;
|
query.where.office = officeWhereInput;
|
||||||
|
|
||||||
//call service to get prisma entity
|
//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;
|
const deed = req.body.deed;
|
||||||
|
|
||||||
if (office && office.uid != officeId) {
|
if (office && office.uid != officeId) {
|
||||||
console.log("wrong office");
|
|
||||||
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
|
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (deed) {
|
if (deed) {
|
||||||
const deedTypeService = Container.get(DeedTypesService);
|
const deedTypeService = Container.get(DeedTypesService);
|
||||||
console.log("deed : ",deed);
|
|
||||||
const deedTypeWithOffice = await deedTypeService.getByUidWithOffice(deed.deed_type.uid!);
|
const deedTypeWithOffice = await deedTypeService.getByUidWithOffice(deed.deed_type.uid!);
|
||||||
if (!deedTypeWithOffice) {
|
if (!deedTypeWithOffice) {
|
||||||
response.status(HttpCodes.NOT_FOUND).send("Deed type not found");
|
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
|
* @description : Update data of an office folder
|
||||||
*/
|
*/
|
||||||
public async update(
|
public async update(officeFolderuid: string, officeFolder: OfficeFolder): Promise<OfficeFolders> {
|
||||||
officeFolderuid: string,
|
|
||||||
officeFolder: OfficeFolder,
|
|
||||||
): Promise<OfficeFolders> {
|
|
||||||
const updateArgs: Prisma.OfficeFoldersUpdateArgs = {
|
const updateArgs: Prisma.OfficeFoldersUpdateArgs = {
|
||||||
where: {
|
where: {
|
||||||
uid: officeFolderuid,
|
uid: officeFolderuid,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user