refacto GET method with search param for folders

This commit is contained in:
OxSaitama 2023-07-12 12:39:58 +02:00
parent 3ca6a0565d
commit 129cb6ad86
5 changed files with 90 additions and 9 deletions

View File

@ -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};

View File

@ -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};

View File

@ -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

View File

@ -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");

View File

@ -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,