refacto query for GET methods

This commit is contained in:
OxSaitama 2023-07-11 18:05:29 +02:00
parent 7022e41fcb
commit 2cbdc1db02
29 changed files with 91 additions and 70 deletions

View File

@ -30,8 +30,9 @@ export default class DeedTypesController extends ApiController {
query = JSON.parse(req.query["q"] as string); query = JSON.parse(req.query["q"] as string);
} }
const officeId: string = req.body.user.office_Id; const officeId: string = req.body.user.office_Id;
const officeWhereInput: Prisma.DeedTypesWhereInput = { office: { uid: officeId } }; const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
query.where = officeWhereInput; if(!query.where) query.where = { office: officeWhereInput};
query.where.office = officeWhereInput;
//call service to get prisma entity //call service to get prisma entity
const deedTypeEntities: DeedTypes[] = await this.deedTypesService.get(query); const deedTypeEntities: DeedTypes[] = await this.deedTypesService.get(query);

View File

@ -30,8 +30,9 @@ export default class DeedsController extends ApiController {
query = JSON.parse(req.query["q"] as string); query = JSON.parse(req.query["q"] as string);
} }
const officeId: string = req.body.user.office_Id; const officeId: string = req.body.user.office_Id;
const officeWhereInput: Prisma.DeedsWhereInput = { deed_type: { office: { uid: officeId } } }; const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
query.where = officeWhereInput; if(!query.where) query.where = { deed_type : {office: officeWhereInput}};
query.where.deed_type!.office = officeWhereInput;
//call service to get prisma entity //call service to get prisma entity
const deedEntities: Deeds[] = await this.deedsService.get(query); const deedEntities: Deeds[] = await this.deedsService.get(query);

View File

@ -30,8 +30,9 @@ export default class DocumentTypesController extends ApiController {
query = JSON.parse(req.query["q"] as string); query = JSON.parse(req.query["q"] as string);
} }
const officeId: string = req.body.user.office_Id; const officeId: string = req.body.user.office_Id;
const officeWhereInput: Prisma.DocumentTypesWhereInput = { office: { uid: officeId } }; const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
query.where = officeWhereInput; if(!query.where) query.where = { office: officeWhereInput};
query.where.office = officeWhereInput;
//call service to get prisma entity //call service to get prisma entity
const documentTypeEntities: DocumentTypes[] = await this.documentTypesService.get(query); const documentTypeEntities: DocumentTypes[] = await this.documentTypesService.get(query);

View File

@ -30,8 +30,9 @@ export default class DocumentsController extends ApiController {
query = JSON.parse(req.query["q"] as string); query = JSON.parse(req.query["q"] as string);
} }
const officeId: string = req.body.user.office_Id; const officeId: string = req.body.user.office_Id;
const officeWhereInput: Prisma.DocumentsWhereInput = { document_type: { office: { uid: officeId } } }; const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
query.where = officeWhereInput; if(!query.where) query.where = { document_type : {office: officeWhereInput}};
query.where.document_type!.office = officeWhereInput;
//call service to get prisma entity //call service to get prisma entity
const documentEntities = await this.documentsService.get(query); const documentEntities = await this.documentsService.get(query);

View File

@ -29,8 +29,9 @@ export default class FilesController extends ApiController {
query = JSON.parse(req.query["q"] as string); query = JSON.parse(req.query["q"] as string);
} }
const officeId: string = req.body.user.office_Id; const officeId: string = req.body.user.office_Id;
const officeWhereInput: Prisma.FilesWhereInput = { document: { folder: { office: { uid: officeId } } } }; const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
query.where = officeWhereInput; if(!query.where) query.where = { document: { folder: {office: officeWhereInput}}};
query.where.document!.folder!.office = officeWhereInput;
//call service to get prisma entity //call service to get prisma entity
const fileEntities = await this.filesService.get(query); const fileEntities = await this.filesService.get(query);

View File

@ -29,8 +29,10 @@ export default class OfficeFoldersController extends ApiController {
query = JSON.parse(req.query["q"] as string); query = JSON.parse(req.query["q"] as string);
} }
const officeId: string = req.body.user.office_Id; const officeId: string = req.body.user.office_Id;
const officeWhereInput: Prisma.OfficeFoldersWhereInput = { office: { uid: officeId } }; const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
query.where = officeWhereInput; if(!query.where) query.where = { office: officeWhereInput};
query.where.office = officeWhereInput;
//call service to get prisma entity //call service to get prisma entity
const officeFolderEntities: OfficeFolders[] = await this.officeFoldersService.get(query); const officeFolderEntities: OfficeFolders[] = await this.officeFoldersService.get(query);

View File

@ -29,8 +29,9 @@ export default class OfficeRolesController extends ApiController {
query = JSON.parse(req.query["q"] as string); query = JSON.parse(req.query["q"] as string);
} }
const officeId: string = req.body.user.office_Id; const officeId: string = req.body.user.office_Id;
const officeWhereInput: Prisma.OfficeRolesWhereInput = { office: { uid: officeId } }; const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
query.where = officeWhereInput; if(!query.where) query.where = { office: officeWhereInput};
query.where.office = officeWhereInput;
//call service to get prisma entity //call service to get prisma entity
const officeRolesEntities = await this.officeRolesService.get(query); const officeRolesEntities = await this.officeRolesService.get(query);

View File

@ -28,8 +28,9 @@ export default class UsersController extends ApiController {
query = JSON.parse(req.query["q"] as string); query = JSON.parse(req.query["q"] as string);
} }
const officeId: string = req.body.user.office_Id; const officeId: string = req.body.user.office_Id;
const officeWhereInput: Prisma.UsersWhereInput = { office_membership: { uid: officeId } }; const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
query.where = officeWhereInput; if(!query.where) query.where = { office_membership: officeWhereInput};
query.where.office_membership = officeWhereInput;
//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);

View File

@ -30,8 +30,9 @@ export default class DeedTypesController extends ApiController {
query = JSON.parse(req.query["q"] as string); query = JSON.parse(req.query["q"] as string);
} }
const officeId: string = req.body.user.office_Id; const officeId: string = req.body.user.office_Id;
const officeWhereInput: Prisma.DeedTypesWhereInput = { office: { uid: officeId } }; const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
query.where = officeWhereInput; if(!query.where) query.where = { office: officeWhereInput};
query.where.office = officeWhereInput;
//call service to get prisma entity //call service to get prisma entity
const deedTypeEntities: DeedTypes[] = await this.deedTypesService.get(query); const deedTypeEntities: DeedTypes[] = await this.deedTypesService.get(query);

View File

@ -30,8 +30,9 @@ export default class DeedsController extends ApiController {
query = JSON.parse(req.query["q"] as string); query = JSON.parse(req.query["q"] as string);
} }
const officeId: string = req.body.user.office_Id; const officeId: string = req.body.user.office_Id;
const officeWhereInput: Prisma.DeedsWhereInput = { deed_type: { office: { uid: officeId } } }; const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
query.where = officeWhereInput; if(!query.where) query.where = { deed_type : {office: officeWhereInput}};
query.where.deed_type!.office = officeWhereInput;
//call service to get prisma entity //call service to get prisma entity
const deedEntities: Deeds[] = await this.deedsService.get(query); const deedEntities: Deeds[] = await this.deedsService.get(query);

View File

@ -30,8 +30,9 @@ export default class DocumentTypesController extends ApiController {
query = JSON.parse(req.query["q"] as string); query = JSON.parse(req.query["q"] as string);
} }
const officeId: string = req.body.user.office_Id; const officeId: string = req.body.user.office_Id;
const officeWhereInput: Prisma.DocumentTypesWhereInput = { office: { uid: officeId } }; const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
query.where = officeWhereInput; if(!query.where) query.where = { office: officeWhereInput};
query.where.office = officeWhereInput;
//call service to get prisma entity //call service to get prisma entity
const documentTypeEntities: DocumentTypes[] = await this.documentTypesService.get(query); const documentTypeEntities: DocumentTypes[] = await this.documentTypesService.get(query);

View File

@ -30,8 +30,9 @@ export default class DocumentsController extends ApiController {
query = JSON.parse(req.query["q"] as string); query = JSON.parse(req.query["q"] as string);
} }
const officeId: string = req.body.user.office_Id; const officeId: string = req.body.user.office_Id;
const officeWhereInput: Prisma.DocumentsWhereInput = { document_type: { office: { uid: officeId } } }; const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
query.where = officeWhereInput; if(!query.where) query.where = { document_type : {office: officeWhereInput}};
query.where.document_type!.office = officeWhereInput;
//call service to get prisma entity //call service to get prisma entity
const documentEntities = await this.documentsService.get(query); const documentEntities = await this.documentsService.get(query);

View File

@ -29,8 +29,9 @@ export default class FilesController extends ApiController {
query = JSON.parse(req.query["q"] as string); query = JSON.parse(req.query["q"] as string);
} }
const officeId: string = req.body.user.office_Id; const officeId: string = req.body.user.office_Id;
const officeWhereInput: Prisma.FilesWhereInput = { document: { folder: { office: { uid: officeId } } } }; const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
query.where = officeWhereInput; if(!query.where) query.where = { document: { folder: {office: officeWhereInput}}};
query.where.document!.folder!.office = officeWhereInput;
//call service to get prisma entity //call service to get prisma entity
const fileEntities = await this.filesService.get(query); const fileEntities = await this.filesService.get(query);

View File

@ -29,8 +29,9 @@ export default class OfficeFoldersController extends ApiController {
query = JSON.parse(req.query["q"] as string); query = JSON.parse(req.query["q"] as string);
} }
const officeId: string = req.body.user.office_Id; const officeId: string = req.body.user.office_Id;
const officeWhereInput: Prisma.OfficeFoldersWhereInput = { office: { uid: officeId } }; const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
query.where = officeWhereInput; if(!query.where) query.where = { office: officeWhereInput};
query.where.office = officeWhereInput;
//call service to get prisma entity //call service to get prisma entity
const officeFolderEntities: OfficeFolders[] = await this.officeFoldersService.get(query); const officeFolderEntities: OfficeFolders[] = await this.officeFoldersService.get(query);

View File

@ -28,8 +28,9 @@ export default class OfficeRolesController extends ApiController {
query = JSON.parse(req.query["q"] as string); query = JSON.parse(req.query["q"] as string);
} }
const officeId: string = req.body.user.office_Id; const officeId: string = req.body.user.office_Id;
const officeWhereInput: Prisma.OfficeRolesWhereInput = { office: { uid: officeId } }; const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
query.where = officeWhereInput; if(!query.where) query.where = { office: officeWhereInput};
query.where.office = officeWhereInput;
//call service to get prisma entity //call service to get prisma entity
const officeRolesEntities = await this.officeRolesService.get(query); const officeRolesEntities = await this.officeRolesService.get(query);

View File

@ -28,8 +28,9 @@ export default class UsersController extends ApiController {
query = JSON.parse(req.query["q"] as string); query = JSON.parse(req.query["q"] as string);
} }
const officeId: string = req.body.user.office_Id; const officeId: string = req.body.user.office_Id;
const officeWhereInput: Prisma.UsersWhereInput = { office_membership: { uid: officeId } }; const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
query.where = officeWhereInput; if(!query.where) query.where = { office_membership: officeWhereInput};
query.where.office_membership = officeWhereInput;
//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);

View File

@ -22,7 +22,7 @@ export default class CustomersController extends ApiController {
protected async get(req: Request, response: Response) { protected async get(req: Request, response: Response) {
try { try {
//get query //get query
let query = {}; let query;
if (req.query["q"]) { if (req.query["q"]) {
query = JSON.parse(req.query["q"] as string); query = JSON.parse(req.query["q"] as string);
} }
@ -120,7 +120,7 @@ export default class CustomersController extends ApiController {
return; return;
} }
let query = {}; let query;
if (req.query["q"]) { if (req.query["q"]) {
query = JSON.parse(req.query["q"] as string); query = JSON.parse(req.query["q"] as string);
} }

View File

@ -30,8 +30,9 @@ export default class DeedTypesController extends ApiController {
query = JSON.parse(req.query["q"] as string); query = JSON.parse(req.query["q"] as string);
} }
const officeId: string = req.body.user.office_Id; const officeId: string = req.body.user.office_Id;
const officeWhereInput: Prisma.DeedTypesWhereInput = { office: { uid: officeId } }; const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
query.where = officeWhereInput; if(!query.where) query.where = { office: officeWhereInput};
query.where.office = officeWhereInput;
//call service to get prisma entity //call service to get prisma entity
const deedTypeEntities: DeedTypes[] = await this.deedTypesService.get(query); const deedTypeEntities: DeedTypes[] = await this.deedTypesService.get(query);
@ -131,7 +132,7 @@ export default class DeedTypesController extends ApiController {
return; return;
} }
let query = {}; let query;
if (req.query["q"]) { if (req.query["q"]) {
query = JSON.parse(req.query["q"] as string); query = JSON.parse(req.query["q"] as string);
} }

View File

@ -30,8 +30,9 @@ export default class DeedsController extends ApiController {
query = JSON.parse(req.query["q"] as string); query = JSON.parse(req.query["q"] as string);
} }
const officeId: string = req.body.user.office_Id; const officeId: string = req.body.user.office_Id;
const officeWhereInput: Prisma.DeedsWhereInput = { deed_type: { office: { uid: officeId } } }; const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
query.where = officeWhereInput; if(!query.where) query.where = { deed_type : {office: officeWhereInput}};
query.where.deed_type!.office = officeWhereInput;
//call service to get prisma entity //call service to get prisma entity
const deedEntities: Deeds[] = await this.deedsService.get(query); const deedEntities: Deeds[] = await this.deedsService.get(query);
@ -60,7 +61,7 @@ export default class DeedsController extends ApiController {
return; return;
} }
let query = {}; let query;
if (req.query["q"]) { if (req.query["q"]) {
query = JSON.parse(req.query["q"] as string); query = JSON.parse(req.query["q"] as string);
} }

View File

@ -30,8 +30,9 @@ export default class DocumentTypesController extends ApiController {
query = JSON.parse(req.query["q"] as string); query = JSON.parse(req.query["q"] as string);
} }
const officeId: string = req.body.user.office_Id; const officeId: string = req.body.user.office_Id;
const officeWhereInput: Prisma.DocumentTypesWhereInput = { office: { uid: officeId } }; const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
query.where = officeWhereInput; if(!query.where) query.where = { office: officeWhereInput};
query.where.office = officeWhereInput;
//call service to get prisma entity //call service to get prisma entity
const documentTypeEntities: DocumentTypes[] = await this.documentTypesService.get(query); const documentTypeEntities: DocumentTypes[] = await this.documentTypesService.get(query);
@ -125,7 +126,7 @@ export default class DocumentTypesController extends ApiController {
return; return;
} }
let query = {}; let query;
if (req.query["q"]) { if (req.query["q"]) {
query = JSON.parse(req.query["q"] as string); query = JSON.parse(req.query["q"] as string);
} }

View File

@ -30,8 +30,9 @@ export default class DocumentsController extends ApiController {
query = JSON.parse(req.query["q"] as string); query = JSON.parse(req.query["q"] as string);
} }
const officeId: string = req.body.user.office_Id; const officeId: string = req.body.user.office_Id;
const officeWhereInput: Prisma.DocumentsWhereInput = { document_type: { office: { uid: officeId } } }; const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
query.where = officeWhereInput; if(!query.where) query.where = { document_type : {office: officeWhereInput}};
query.where.document_type!.office = officeWhereInput;
//call service to get prisma entity //call service to get prisma entity
const documentEntities = await this.documentsService.get(query); const documentEntities = await this.documentsService.get(query);
@ -160,7 +161,7 @@ export default class DocumentsController extends ApiController {
return; return;
} }
let query = {}; let query;
if (req.query["q"]) { if (req.query["q"]) {
query = JSON.parse(req.query["q"] as string); query = JSON.parse(req.query["q"] as string);
} }

View File

@ -29,8 +29,10 @@ export default class FilesController extends ApiController {
query = JSON.parse(req.query["q"] as string); query = JSON.parse(req.query["q"] as string);
} }
const officeId: string = req.body.user.office_Id; const officeId: string = req.body.user.office_Id;
const officeWhereInput: Prisma.FilesWhereInput = { document: { folder: { office: { uid: officeId } } } }; const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
query.where = officeWhereInput; if(!query.where) query.where = { document: { folder: {office: officeWhereInput}}};
query.where.document!.folder!.office = officeWhereInput;
//call service to get prisma entity //call service to get prisma entity
const fileEntities = await this.filesService.get(query); const fileEntities = await this.filesService.get(query);
@ -123,7 +125,7 @@ export default class FilesController extends ApiController {
return; return;
} }
let query = {}; let query;
if (req.query["q"]) { if (req.query["q"]) {
query = JSON.parse(req.query["q"] as string); query = JSON.parse(req.query["q"] as string);
} }

View File

@ -29,8 +29,10 @@ export default class OfficeFoldersController extends ApiController {
query = JSON.parse(req.query["q"] as string); query = JSON.parse(req.query["q"] as string);
} }
const officeId: string = req.body.user.office_Id; const officeId: string = req.body.user.office_Id;
const officeWhereInput: Prisma.OfficeFoldersWhereInput = { office: { uid: officeId } }; const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
query.where = officeWhereInput; if(!query.where) query.where = { office: officeWhereInput};
query.where.office = officeWhereInput;
//call service to get prisma entity //call service to get prisma entity
const officeFolderEntities: OfficeFolders[] = await this.officeFoldersService.get(query); const officeFolderEntities: OfficeFolders[] = await this.officeFoldersService.get(query);
@ -82,12 +84,7 @@ export default class OfficeFoldersController extends ApiController {
return; return;
} }
let query = {}; const officeFolderFound = await this.officeFoldersService.getByUid(uid);
if (req.query["q"]) {
query = JSON.parse(req.query["q"] as string);
}
const officeFolderFound = await this.officeFoldersService.getByUid(uid, query);
if (!officeFolderFound) { if (!officeFolderFound) {
this.httpNotFoundRequest(response, "office folder not found"); this.httpNotFoundRequest(response, "office folder not found");
@ -129,7 +126,7 @@ export default class OfficeFoldersController extends ApiController {
return; return;
} }
let query = {}; let query;
if (req.query["q"]) { if (req.query["q"]) {
query = JSON.parse(req.query["q"] as string); query = JSON.parse(req.query["q"] as string);
} }

View File

@ -29,8 +29,9 @@ export default class OfficeRolesController extends ApiController {
query = JSON.parse(req.query["q"] as string); query = JSON.parse(req.query["q"] as string);
} }
const officeId: string = req.body.user.office_Id; const officeId: string = req.body.user.office_Id;
const officeWhereInput: Prisma.OfficeRolesWhereInput = { office: { uid: officeId } }; const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
query.where = officeWhereInput; if(!query.where) query.where = { office: officeWhereInput};
query.where.office = officeWhereInput;
//call service to get prisma entity //call service to get prisma entity
const officeRolesEntities = await this.officeRolesService.get(query); const officeRolesEntities = await this.officeRolesService.get(query);
@ -127,7 +128,7 @@ export default class OfficeRolesController extends ApiController {
return; return;
} }
let query = {}; let query;
if (req.query["q"]) { if (req.query["q"]) {
query = JSON.parse(req.query["q"] as string); query = JSON.parse(req.query["q"] as string);
} }

View File

@ -22,7 +22,7 @@ export default class OfficesController extends ApiController {
protected async get(req: Request, response: Response) { protected async get(req: Request, response: Response) {
try { try {
//get query //get query
let query = {}; let query;
if (req.query["q"]) { if (req.query["q"]) {
query = JSON.parse(req.query["q"] as string); query = JSON.parse(req.query["q"] as string);
} }
@ -107,7 +107,7 @@ export default class OfficesController extends ApiController {
return; return;
} }
let query = {}; let query;
if (req.query["q"]) { if (req.query["q"]) {
query = JSON.parse(req.query["q"] as string); query = JSON.parse(req.query["q"] as string);
} }

View File

@ -22,7 +22,7 @@ export default class RolesController extends ApiController {
protected async get(req: Request, response: Response) { protected async get(req: Request, response: Response) {
try { try {
//get query //get query
let query = {}; let query;
if (req.query["q"]) { if (req.query["q"]) {
query = JSON.parse(req.query["q"] as string); query = JSON.parse(req.query["q"] as string);
} }
@ -122,7 +122,7 @@ export default class RolesController extends ApiController {
return; return;
} }
let query = {}; let query;
if (req.query["q"]) { if (req.query["q"]) {
query = JSON.parse(req.query["q"] as string); query = JSON.parse(req.query["q"] as string);
} }

View File

@ -22,7 +22,7 @@ export default class RulesController extends ApiController {
protected async get(req: Request, response: Response) { protected async get(req: Request, response: Response) {
try { try {
//get query //get query
let query = {}; let query;
if (req.query["q"]) { if (req.query["q"]) {
query = JSON.parse(req.query["q"] as string); query = JSON.parse(req.query["q"] as string);
} }
@ -121,7 +121,7 @@ export default class RulesController extends ApiController {
this.httpBadRequest(response, "No uid provided"); this.httpBadRequest(response, "No uid provided");
return; return;
} }
let query = {}; let query;
if (req.query["q"]) { if (req.query["q"]) {
query = JSON.parse(req.query["q"] as string); query = JSON.parse(req.query["q"] as string);
} }

View File

@ -22,7 +22,7 @@ export default class UsersController extends ApiController {
protected async get(req: Request, response: Response) { protected async get(req: Request, response: Response) {
try { try {
//get query //get query
let query = {}; let query;
if (req.query["q"]) { if (req.query["q"]) {
query = JSON.parse(req.query["q"] as string); query = JSON.parse(req.query["q"] as string);
} }
@ -121,7 +121,7 @@ export default class UsersController extends ApiController {
this.httpBadRequest(response, "No uid provided"); this.httpBadRequest(response, "No uid provided");
return; return;
} }
let query = {}; let query;
if (req.query["q"]) { if (req.query["q"]) {
query = JSON.parse(req.query["q"] as string); query = JSON.parse(req.query["q"] as string);
} }

View File

@ -33,7 +33,7 @@ export default async function folderHandler(req: Request, response: Response, ne
const officeFolderService = Container.get(OfficeFoldersService); const officeFolderService = Container.get(OfficeFoldersService);
if (officeFolderNumber) { if (officeFolderNumber && req.method == "POST") {
const officeFoldersWithSameNumber = await officeFolderService.get({ const officeFoldersWithSameNumber = await officeFolderService.get({
where: { folder_number: officeFolderNumber, office: { uid: officeId } }, where: { folder_number: officeFolderNumber, office: { uid: officeId } },
}); });