Fix: controllers and middlewares (#50)
fix middlewares and error handling fix GET methods requests
This commit is contained in:
commit
14fa3caadd
@ -49,7 +49,7 @@
|
|||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"express": "^4.18.2",
|
"express": "^4.18.2",
|
||||||
"jsonwebtoken": "^9.0.0",
|
"jsonwebtoken": "^9.0.0",
|
||||||
"le-coffre-resources": "git@github.com:smart-chain-fr/leCoffre-resources.git#v2.55",
|
"le-coffre-resources": "git@github.com:smart-chain-fr/leCoffre-resources.git#v2.56",
|
||||||
"module-alias": "^2.2.2",
|
"module-alias": "^2.2.2",
|
||||||
"multer": "^1.4.5-lts.1",
|
"multer": "^1.4.5-lts.1",
|
||||||
"next": "^13.1.5",
|
"next": "^13.1.5",
|
||||||
|
@ -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);
|
||||||
|
@ -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);
|
||||||
|
@ -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);
|
||||||
|
@ -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);
|
||||||
|
@ -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);
|
||||||
|
|
||||||
|
@ -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);
|
||||||
|
|
||||||
|
@ -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);
|
||||||
|
@ -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);
|
||||||
|
@ -7,7 +7,7 @@ import { Files, Prisma } from "@prisma/client";
|
|||||||
import { File } from "le-coffre-resources/dist/Customer";
|
import { File } from "le-coffre-resources/dist/Customer";
|
||||||
import { Document } from "le-coffre-resources/dist/Customer";
|
import { Document } from "le-coffre-resources/dist/Customer";
|
||||||
import { validateOrReject } from "class-validator";
|
import { validateOrReject } from "class-validator";
|
||||||
import DocumentsService from "@Services/super-admin/DocumentsService/DocumentsService";
|
import DocumentsService from "@Services/customer/DocumentsService/DocumentsService";
|
||||||
import authHandler from "@App/middlewares/AuthHandler";
|
import authHandler from "@App/middlewares/AuthHandler";
|
||||||
import fileHandler from "@App/middlewares/CustomerHandler/FileHandler";
|
import fileHandler from "@App/middlewares/CustomerHandler/FileHandler";
|
||||||
|
|
||||||
|
@ -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);
|
||||||
|
@ -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);
|
||||||
|
@ -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);
|
||||||
|
@ -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);
|
||||||
|
@ -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);
|
||||||
|
|
||||||
|
@ -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);
|
||||||
|
|
||||||
|
@ -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);
|
||||||
|
@ -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);
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -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,18 +126,12 @@ export default class OfficeFoldersController extends ApiController {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let officeFolderEntity: OfficeFolders | null;
|
let query;
|
||||||
//get query
|
|
||||||
if (req.query["q"]) {
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
officeFolderEntity = await this.officeFoldersService.getByUid(uid, query);
|
|
||||||
} else {
|
const officeFolderEntity = await this.officeFoldersService.getByUid(uid, query);
|
||||||
//call service to get prisma entity
|
|
||||||
officeFolderEntity = await this.officeFoldersService.getByUid(uid);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!officeFolderEntity) {
|
if (!officeFolderEntity) {
|
||||||
this.httpNotFoundRequest(response, "folder not found");
|
this.httpNotFoundRequest(response, "folder not found");
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -8,14 +8,14 @@ export default function authHandler(req: Request, response: Response, next: Next
|
|||||||
const token = authHeader && authHeader.split(" ")[1];
|
const token = authHeader && authHeader.split(" ")[1];
|
||||||
|
|
||||||
if (!token) {
|
if (!token) {
|
||||||
response.sendStatus(HttpCodes.UNAUTHORIZED);
|
response.status(HttpCodes.UNAUTHORIZED).send("Missing token in authorization header");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const authService = Container.get(AuthService);
|
const authService = Container.get(AuthService);
|
||||||
authService.verifyAccessToken(token, (err, userPayload) => {
|
authService.verifyAccessToken(token, (err, userPayload) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
response.sendStatus(HttpCodes.UNAUTHORIZED);
|
response.status(HttpCodes.UNAUTHORIZED).send("Error while verifying token");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
req.body.user = userPayload;
|
req.body.user = userPayload;
|
||||||
|
@ -8,7 +8,7 @@ export default async function documentHandler(req: Request, response: Response,
|
|||||||
const uid = req.path && req.path.split("/")[5];
|
const uid = req.path && req.path.split("/")[5];
|
||||||
|
|
||||||
if(!uid) {
|
if(!uid) {
|
||||||
response.sendStatus(HttpCodes.BAD_REQUEST);
|
response.status(HttpCodes.BAD_REQUEST).send("Missing document uid");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -16,7 +16,7 @@ export default async function documentHandler(req: Request, response: Response,
|
|||||||
const document = await documentService.getByUid(uid);
|
const document = await documentService.getByUid(uid);
|
||||||
|
|
||||||
if(document?.depositor_uid != customerId) {
|
if(document?.depositor_uid != customerId) {
|
||||||
response.sendStatus(HttpCodes.UNAUTHORIZED);
|
response.status(HttpCodes.UNAUTHORIZED).send("Not authorized with this depositor");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,11 +13,11 @@ export default async function fileHandler(req: Request, response: Response, next
|
|||||||
const fileService = Container.get(FilesService);
|
const fileService = Container.get(FilesService);
|
||||||
const file = await fileService.getByUidWithDocument(uid);
|
const file = await fileService.getByUidWithDocument(uid);
|
||||||
if (!file) {
|
if (!file) {
|
||||||
response.sendStatus(HttpCodes.BAD_REQUEST);
|
response.status(HttpCodes.NOT_FOUND).send("File not found");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (file.document.depositor_uid != customerId) {
|
if (file.document.depositor_uid != customerId) {
|
||||||
response.sendStatus(HttpCodes.UNAUTHORIZED);
|
response.status(HttpCodes.UNAUTHORIZED).send("Not authorized with this depositor");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -26,11 +26,11 @@ export default async function fileHandler(req: Request, response: Response, next
|
|||||||
const documentService = Container.get(DocumentsService);
|
const documentService = Container.get(DocumentsService);
|
||||||
const documentFound = await documentService.getByUid(document.uid!);
|
const documentFound = await documentService.getByUid(document.uid!);
|
||||||
if(!documentFound) {
|
if(!documentFound) {
|
||||||
response.sendStatus(HttpCodes.BAD_REQUEST);
|
response.status(HttpCodes.NOT_FOUND).send("Document not found");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (documentFound.depositor_uid != customerId) {
|
if (documentFound.depositor_uid != customerId) {
|
||||||
response.sendStatus(HttpCodes.UNAUTHORIZED);
|
response.status(HttpCodes.UNAUTHORIZED).send("Not authorized with this depositor");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,15 +12,15 @@ export default async function deedHandler(req: Request, response: Response, next
|
|||||||
|
|
||||||
if (uid) {
|
if (uid) {
|
||||||
const deedService = Container.get(DeedsService);
|
const deedService = Container.get(DeedsService);
|
||||||
const deed = await deedService.getOneByUidWithOffice(uid);
|
const deed = await deedService.getByUidWithOffice(uid);
|
||||||
|
|
||||||
if (!deed) {
|
if (!deed) {
|
||||||
response.sendStatus(HttpCodes.NOT_FOUND);
|
response.status(HttpCodes.NOT_FOUND).send("Deed not found");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (deed.deed_type.office.uid != officeId) {
|
if (deed.deed_type.office.uid != officeId) {
|
||||||
response.sendStatus(HttpCodes.UNAUTHORIZED);
|
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -30,11 +30,11 @@ export default async function deedHandler(req: Request, response: Response, next
|
|||||||
documentTypes.forEach(async (documentType) => {
|
documentTypes.forEach(async (documentType) => {
|
||||||
const deedTypeWithOffice = await documentTypeService.getByUidWithOffice(documentType.uid!);
|
const deedTypeWithOffice = await documentTypeService.getByUidWithOffice(documentType.uid!);
|
||||||
if (!deedTypeWithOffice) {
|
if (!deedTypeWithOffice) {
|
||||||
response.sendStatus(HttpCodes.NOT_FOUND);
|
response.status(HttpCodes.NOT_FOUND).send("Deed type not found");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (deedTypeWithOffice.office?.uid != officeId) {
|
if (deedTypeWithOffice.office?.uid != officeId) {
|
||||||
response.sendStatus(HttpCodes.UNAUTHORIZED);
|
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -12,7 +12,7 @@ export default async function deedTypeHandler(req: Request, response: Response,
|
|||||||
const office = req.body.office;
|
const office = req.body.office;
|
||||||
|
|
||||||
if (office && office.uid != officeId) {
|
if (office && office.uid != officeId) {
|
||||||
response.sendStatus(HttpCodes.UNAUTHORIZED);
|
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21,12 +21,12 @@ export default async function deedTypeHandler(req: Request, response: Response,
|
|||||||
const deedType = await deedTypeService.getByUidWithOffice(uid!);
|
const deedType = await deedTypeService.getByUidWithOffice(uid!);
|
||||||
|
|
||||||
if (!deedType) {
|
if (!deedType) {
|
||||||
response.sendStatus(HttpCodes.NOT_FOUND);
|
response.status(HttpCodes.NOT_FOUND).send("Deed type not found");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (deedType.office.uid != officeId) {
|
if (deedType.office.uid != officeId) {
|
||||||
response.sendStatus(HttpCodes.UNAUTHORIZED);
|
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -36,11 +36,11 @@ export default async function deedTypeHandler(req: Request, response: Response,
|
|||||||
documentTypes.forEach(async (documentType) => {
|
documentTypes.forEach(async (documentType) => {
|
||||||
const documentTypeWithOffice = await documentTypeService.getByUidWithOffice(documentType.uid!);
|
const documentTypeWithOffice = await documentTypeService.getByUidWithOffice(documentType.uid!);
|
||||||
if (!documentTypeWithOffice) {
|
if (!documentTypeWithOffice) {
|
||||||
response.sendStatus(HttpCodes.NOT_FOUND);
|
response.status(HttpCodes.NOT_FOUND).send("Document type not found");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (documentTypeWithOffice.office?.uid != officeId) {
|
if (documentTypeWithOffice.office?.uid != officeId) {
|
||||||
response.sendStatus(HttpCodes.UNAUTHORIZED);
|
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -17,11 +17,11 @@ export default async function documentHandler(req: Request, response: Response,
|
|||||||
const officeFolderService = Container.get(OfficeFoldersService);
|
const officeFolderService = Container.get(OfficeFoldersService);
|
||||||
const officeFolderWithOffice = await officeFolderService.getByUidWithOffice(folder.uid!);
|
const officeFolderWithOffice = await officeFolderService.getByUidWithOffice(folder.uid!);
|
||||||
if (!officeFolderWithOffice) {
|
if (!officeFolderWithOffice) {
|
||||||
response.sendStatus(HttpCodes.NOT_FOUND);
|
response.status(HttpCodes.NOT_FOUND).send("Folder not found");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (officeFolderWithOffice.office?.uid != officeId) {
|
if (officeFolderWithOffice.office?.uid != officeId) {
|
||||||
response.sendStatus(HttpCodes.UNAUTHORIZED);
|
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -30,11 +30,11 @@ export default async function documentHandler(req: Request, response: Response,
|
|||||||
const documentTypeService = Container.get(DocumentTypesService);
|
const documentTypeService = Container.get(DocumentTypesService);
|
||||||
const documentTypeWithOffice = await documentTypeService.getByUidWithOffice(documentType.uid!);
|
const documentTypeWithOffice = await documentTypeService.getByUidWithOffice(documentType.uid!);
|
||||||
if (!documentTypeWithOffice) {
|
if (!documentTypeWithOffice) {
|
||||||
response.sendStatus(HttpCodes.NOT_FOUND);
|
response.status(HttpCodes.NOT_FOUND).send("Document type not found");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (documentTypeWithOffice.office?.uid != officeId) {
|
if (documentTypeWithOffice.office?.uid != officeId) {
|
||||||
response.sendStatus(HttpCodes.UNAUTHORIZED);
|
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ export default async function documentTypeHandler(req: Request, response: Respon
|
|||||||
const office = req.body.office;
|
const office = req.body.office;
|
||||||
|
|
||||||
if (office && office.uid != officeId) {
|
if (office && office.uid != officeId) {
|
||||||
response.sendStatus(HttpCodes.UNAUTHORIZED);
|
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -18,12 +18,12 @@ export default async function documentTypeHandler(req: Request, response: Respon
|
|||||||
const documentType = await documentTypeService.getByUidWithOffice(uid!);
|
const documentType = await documentTypeService.getByUidWithOffice(uid!);
|
||||||
|
|
||||||
if (!documentType) {
|
if (!documentType) {
|
||||||
response.sendStatus(HttpCodes.NOT_FOUND);
|
response.status(HttpCodes.NOT_FOUND).send("Document type not found");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (documentType.office.uid != officeId) {
|
if (documentType.office.uid != officeId) {
|
||||||
response.sendStatus(HttpCodes.UNAUTHORIZED);
|
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,11 +13,11 @@ export default async function fileHandler(req: Request, response: Response, next
|
|||||||
const documentService = Container.get(DocumentsService);
|
const documentService = Container.get(DocumentsService);
|
||||||
const documentWithOffice = await documentService.getByUidWithOffice(document.uid!);
|
const documentWithOffice = await documentService.getByUidWithOffice(document.uid!);
|
||||||
if (!documentWithOffice) {
|
if (!documentWithOffice) {
|
||||||
response.sendStatus(HttpCodes.NOT_FOUND);
|
response.status(HttpCodes.NOT_FOUND).send("Document not found");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (documentWithOffice.folder.office?.uid != officeId) {
|
if (documentWithOffice.folder.office?.uid != officeId) {
|
||||||
response.sendStatus(HttpCodes.UNAUTHORIZED);
|
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -29,11 +29,11 @@ export default async function fileHandler(req: Request, response: Response, next
|
|||||||
const file = await fileService.getByUidWithOffice(uid!);
|
const file = await fileService.getByUidWithOffice(uid!);
|
||||||
|
|
||||||
if (!file) {
|
if (!file) {
|
||||||
response.sendStatus(HttpCodes.NOT_FOUND);
|
response.status(HttpCodes.NOT_FOUND).send("File not found");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (file.document.folder.office.uid != officeId) {
|
if (file.document.folder.office.uid != officeId) {
|
||||||
response.sendStatus(HttpCodes.UNAUTHORIZED);
|
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,31 +12,33 @@ 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) {
|
||||||
response.sendStatus(HttpCodes.UNAUTHORIZED);
|
console.log("wrong 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);
|
||||||
const deedTypeWithOffice = await deedTypeService.getByUidWithOffice(deed.deedType.uid!);
|
console.log("deed : ",deed);
|
||||||
|
const deedTypeWithOffice = await deedTypeService.getByUidWithOffice(deed.deed_type.uid!);
|
||||||
if (!deedTypeWithOffice) {
|
if (!deedTypeWithOffice) {
|
||||||
response.sendStatus(HttpCodes.NOT_FOUND);
|
response.status(HttpCodes.NOT_FOUND).send("Deed type not found");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (deedTypeWithOffice.office.uid != officeId) {
|
if (deedTypeWithOffice.office.uid != officeId) {
|
||||||
response.sendStatus(HttpCodes.UNAUTHORIZED);
|
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this deed type");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 } },
|
||||||
});
|
});
|
||||||
if (officeFoldersWithSameNumber.length) {
|
if (officeFoldersWithSameNumber.length) {
|
||||||
response.sendStatus(HttpCodes.BAD_REQUEST);
|
response.status(HttpCodes.BAD_REQUEST).send("Office number already used");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -45,12 +47,12 @@ export default async function folderHandler(req: Request, response: Response, ne
|
|||||||
const officeFolder = await officeFolderService.getByUidWithOffice(uid!);
|
const officeFolder = await officeFolderService.getByUidWithOffice(uid!);
|
||||||
|
|
||||||
if (!officeFolder) {
|
if (!officeFolder) {
|
||||||
response.sendStatus(HttpCodes.NOT_FOUND);
|
response.status(HttpCodes.NOT_FOUND).send("Office folder not found");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (officeFolder.office.uid != officeId) {
|
if (officeFolder.office.uid != officeId) {
|
||||||
response.sendStatus(HttpCodes.UNAUTHORIZED);
|
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ export default async function officeRoleHandler(req: Request, response: Response
|
|||||||
const office = req.body.office;
|
const office = req.body.office;
|
||||||
|
|
||||||
if (office && office.uid != officeId) {
|
if (office && office.uid != officeId) {
|
||||||
response.sendStatus(HttpCodes.UNAUTHORIZED);
|
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -18,12 +18,12 @@ export default async function officeRoleHandler(req: Request, response: Response
|
|||||||
const officeRole = await officeRoleService.getByUidWithOffice(uid!);
|
const officeRole = await officeRoleService.getByUidWithOffice(uid!);
|
||||||
|
|
||||||
if (!officeRole) {
|
if (!officeRole) {
|
||||||
response.sendStatus(HttpCodes.NOT_FOUND);
|
response.status(HttpCodes.NOT_FOUND).send("Office role not found");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (officeRole.office.uid != officeId) {
|
if (officeRole.office.uid != officeId) {
|
||||||
response.sendStatus(HttpCodes.UNAUTHORIZED);
|
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ export default async function userHandler(req: Request, response: Response, next
|
|||||||
const office = req.body.office_membership;
|
const office = req.body.office_membership;
|
||||||
|
|
||||||
if (office && office.uid != officeId) {
|
if (office && office.uid != officeId) {
|
||||||
response.sendStatus(HttpCodes.UNAUTHORIZED);
|
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -18,12 +18,12 @@ export default async function userHandler(req: Request, response: Response, next
|
|||||||
const user = await userService.getByUidWithOffice(uid!);
|
const user = await userService.getByUidWithOffice(uid!);
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
response.sendStatus(HttpCodes.NOT_FOUND);
|
response.status(HttpCodes.NOT_FOUND).send("User not found");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user.office_membership.uid != officeId) {
|
if (user.office_membership.uid != officeId) {
|
||||||
response.sendStatus(HttpCodes.UNAUTHORIZED);
|
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,12 +8,12 @@ export default async function ruleHandler(req: Request, response: Response, next
|
|||||||
const role = req.body.user.role;
|
const role = req.body.user.role;
|
||||||
|
|
||||||
if (namespace != "notary" && role != namespace) {
|
if (namespace != "notary" && role != namespace) {
|
||||||
response.sendStatus(HttpCodes.UNAUTHORIZED);
|
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this role");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!rules.includes(req.method + " " + service)) {
|
if (!rules.includes(req.method + " " + service)) {
|
||||||
response.sendStatus(HttpCodes.UNAUTHORIZED);
|
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with those rules");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -554,7 +554,7 @@ export default async function main() {
|
|||||||
updated_at: new Date(),
|
updated_at: new Date(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "GET documentTypes",
|
name: "GET document-types",
|
||||||
created_at: new Date(),
|
created_at: new Date(),
|
||||||
updated_at: new Date(),
|
updated_at: new Date(),
|
||||||
},
|
},
|
||||||
@ -614,7 +614,7 @@ export default async function main() {
|
|||||||
updated_at: new Date(),
|
updated_at: new Date(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "PUT documentTypes",
|
name: "PUT document-types",
|
||||||
created_at: new Date(),
|
created_at: new Date(),
|
||||||
updated_at: new Date(),
|
updated_at: new Date(),
|
||||||
},
|
},
|
||||||
@ -674,7 +674,7 @@ export default async function main() {
|
|||||||
updated_at: new Date(),
|
updated_at: new Date(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "POST documentTypes",
|
name: "POST document-types",
|
||||||
created_at: new Date(),
|
created_at: new Date(),
|
||||||
updated_at: new Date(),
|
updated_at: new Date(),
|
||||||
},
|
},
|
||||||
@ -724,7 +724,7 @@ export default async function main() {
|
|||||||
updated_at: new Date(),
|
updated_at: new Date(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "POST deedtypes",
|
name: "POST deed-types",
|
||||||
created_at: new Date(),
|
created_at: new Date(),
|
||||||
updated_at: new Date(),
|
updated_at: new Date(),
|
||||||
},
|
},
|
||||||
@ -734,7 +734,7 @@ export default async function main() {
|
|||||||
updated_at: new Date(),
|
updated_at: new Date(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "POST documentTypes",
|
name: "POST document-types",
|
||||||
created_at: new Date(),
|
created_at: new Date(),
|
||||||
updated_at: new Date(),
|
updated_at: new Date(),
|
||||||
},
|
},
|
||||||
@ -784,7 +784,7 @@ export default async function main() {
|
|||||||
updated_at: new Date(),
|
updated_at: new Date(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "DELETE deedtypes",
|
name: "DELETE deed-types",
|
||||||
created_at: new Date(),
|
created_at: new Date(),
|
||||||
updated_at: new Date(),
|
updated_at: new Date(),
|
||||||
},
|
},
|
||||||
@ -794,7 +794,7 @@ export default async function main() {
|
|||||||
updated_at: new Date(),
|
updated_at: new Date(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "DELETE documentTypes",
|
name: "DELETE document-types",
|
||||||
created_at: new Date(),
|
created_at: new Date(),
|
||||||
updated_at: new Date(),
|
updated_at: new Date(),
|
||||||
},
|
},
|
||||||
|
@ -3,6 +3,7 @@ import BaseRepository from "@Repositories/BaseRepository";
|
|||||||
import { Service } from "typedi";
|
import { Service } from "typedi";
|
||||||
import { Documents, EDocumentStatus, Prisma } from "@prisma/client";
|
import { Documents, EDocumentStatus, Prisma } from "@prisma/client";
|
||||||
import { Document } from "le-coffre-resources/dist/SuperAdmin";
|
import { Document } from "le-coffre-resources/dist/SuperAdmin";
|
||||||
|
import { Document as DocumentCustomer } from "le-coffre-resources/dist/Customer";
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class DocumentsRepository extends BaseRepository {
|
export default class DocumentsRepository extends BaseRepository {
|
||||||
@ -94,7 +95,7 @@ export default class DocumentsRepository extends BaseRepository {
|
|||||||
/**
|
/**
|
||||||
* @description : Update data of a document
|
* @description : Update data of a document
|
||||||
*/
|
*/
|
||||||
public async update(uid: string, document: Partial<Document>, refusedReason?: string): Promise<Documents> {
|
public async update(uid: string, document: Partial<DocumentCustomer>, refusedReason?: string): Promise<Documents> {
|
||||||
return this.model.update({
|
return this.model.update({
|
||||||
where: {
|
where: {
|
||||||
uid: uid,
|
uid: uid,
|
||||||
|
@ -82,7 +82,7 @@ export default class AuthService extends BaseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public generateAccessToken(user: any): string {
|
public generateAccessToken(user: any): string {
|
||||||
return jwt.sign({ ...user }, this.variables.ACCESS_TOKEN_SECRET, { expiresIn: "15m" });
|
return jwt.sign({ ...user }, this.variables.ACCESS_TOKEN_SECRET, { expiresIn: "1h" });
|
||||||
}
|
}
|
||||||
|
|
||||||
public generateRefreshToken(user: any): string {
|
public generateRefreshToken(user: any): string {
|
||||||
|
@ -18,22 +18,6 @@ export default class DocumentsService extends BaseService {
|
|||||||
return this.documentsRepository.findMany(query);
|
return this.documentsRepository.findMany(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @description : Create a new document
|
|
||||||
* @throws {Error} If document cannot be created
|
|
||||||
*/
|
|
||||||
public async create(document: Document): Promise<Documents> {
|
|
||||||
return this.documentsRepository.create(document);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description : Create new documents
|
|
||||||
* @throws {Error} If documents or one of them cannot be created
|
|
||||||
*/
|
|
||||||
public async createMany(documents: Document[]): Promise<Documents[]> {
|
|
||||||
return this.documentsRepository.createMany(documents);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description : Modify a document
|
* @description : Modify a document
|
||||||
* @throws {Error} If document cannot be modified
|
* @throws {Error} If document cannot be modified
|
||||||
@ -42,14 +26,6 @@ export default class DocumentsService extends BaseService {
|
|||||||
return this.documentsRepository.update(uid, document);
|
return this.documentsRepository.update(uid, document);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @description : Delete a document
|
|
||||||
* @throws {Error} If document cannot be deleted
|
|
||||||
*/
|
|
||||||
public async delete(uid: string): Promise<Documents> {
|
|
||||||
return this.documentsRepository.delete(uid);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description : Get a document by uid
|
* @description : Get a document by uid
|
||||||
* @throws {Error} If document cannot be get by uid
|
* @throws {Error} If document cannot be get by uid
|
||||||
|
@ -42,7 +42,7 @@ export default class DeedsService extends BaseService {
|
|||||||
return this.deedRepository.findOneByUid(uid, query);
|
return this.deedRepository.findOneByUid(uid, query);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getOneByUidWithOffice(uid: string) {
|
public async getByUidWithOffice(uid: string) {
|
||||||
return this.deedRepository.findOneByUidWithOffice(uid);
|
return this.deedRepository.findOneByUidWithOffice(uid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { EOfficeStatus } from "le-coffre-resources/dist/Customer/Office";
|
import { EOfficeStatus } from "le-coffre-resources/dist/Notary/Office";
|
||||||
import User, { Address, Contact, Office, DeedType, DocumentType, Customer, OfficeFolder, Deed } from "le-coffre-resources/dist/SuperAdmin";
|
import User, { Address, Contact, Office, DeedType, DocumentType, Customer, OfficeFolder, Deed } from "le-coffre-resources/dist/SuperAdmin";
|
||||||
|
|
||||||
export const userAddress: Address = {
|
export const userAddress: Address = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user