Fix: controllers and middlewares (#50)

fix middlewares and error handling

fix GET methods requests
This commit is contained in:
Arnaud D. Natali 2023-07-12 11:27:56 +02:00 committed by GitHub
commit 14fa3caadd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
48 changed files with 153 additions and 159 deletions

View File

@ -49,7 +49,7 @@
"cors": "^2.8.5",
"express": "^4.18.2",
"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",
"multer": "^1.4.5-lts.1",
"next": "^13.1.5",

View File

@ -30,8 +30,9 @@ export default class DeedTypesController extends ApiController {
query = JSON.parse(req.query["q"] as string);
}
const officeId: string = req.body.user.office_Id;
const officeWhereInput: Prisma.DeedTypesWhereInput = { office: { uid: officeId } };
query.where = officeWhereInput;
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
if(!query.where) query.where = { office: officeWhereInput};
query.where.office = officeWhereInput;
//call service to get prisma entity
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);
}
const officeId: string = req.body.user.office_Id;
const officeWhereInput: Prisma.DeedsWhereInput = { deed_type: { office: { uid: officeId } } };
query.where = officeWhereInput;
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
if(!query.where) query.where = { deed_type : {office: officeWhereInput}};
query.where.deed_type!.office = officeWhereInput;
//call service to get prisma entity
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);
}
const officeId: string = req.body.user.office_Id;
const officeWhereInput: Prisma.DocumentTypesWhereInput = { office: { uid: officeId } };
query.where = officeWhereInput;
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
if(!query.where) query.where = { office: officeWhereInput};
query.where.office = officeWhereInput;
//call service to get prisma entity
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);
}
const officeId: string = req.body.user.office_Id;
const officeWhereInput: Prisma.DocumentsWhereInput = { document_type: { office: { uid: officeId } } };
query.where = officeWhereInput;
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
if(!query.where) query.where = { document_type : {office: officeWhereInput}};
query.where.document_type!.office = officeWhereInput;
//call service to get prisma entity
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);
}
const officeId: string = req.body.user.office_Id;
const officeWhereInput: Prisma.FilesWhereInput = { document: { folder: { office: { uid: officeId } } } };
query.where = officeWhereInput;
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
if(!query.where) query.where = { document: { folder: {office: officeWhereInput}}};
query.where.document!.folder!.office = officeWhereInput;
//call service to get prisma entity
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);
}
const officeId: string = req.body.user.office_Id;
const officeWhereInput: Prisma.OfficeFoldersWhereInput = { office: { uid: officeId } };
query.where = officeWhereInput;
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
if(!query.where) query.where = { office: officeWhereInput};
query.where.office = officeWhereInput;
//call service to get prisma entity
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);
}
const officeId: string = req.body.user.office_Id;
const officeWhereInput: Prisma.OfficeRolesWhereInput = { office: { uid: officeId } };
query.where = officeWhereInput;
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
if(!query.where) query.where = { office: officeWhereInput};
query.where.office = officeWhereInput;
//call service to get prisma entity
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);
}
const officeId: string = req.body.user.office_Id;
const officeWhereInput: Prisma.UsersWhereInput = { office_membership: { uid: officeId } };
query.where = officeWhereInput;
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
if(!query.where) query.where = { office_membership: officeWhereInput};
query.where.office_membership = officeWhereInput;
//call service to get prisma entity
const usersEntities = await this.usersService.get(query);

View File

@ -7,7 +7,7 @@ import { Files, Prisma } from "@prisma/client";
import { File } from "le-coffre-resources/dist/Customer";
import { Document } from "le-coffre-resources/dist/Customer";
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 fileHandler from "@App/middlewares/CustomerHandler/FileHandler";

View File

@ -30,8 +30,9 @@ export default class DeedTypesController extends ApiController {
query = JSON.parse(req.query["q"] as string);
}
const officeId: string = req.body.user.office_Id;
const officeWhereInput: Prisma.DeedTypesWhereInput = { office: { uid: officeId } };
query.where = officeWhereInput;
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
if(!query.where) query.where = { office: officeWhereInput};
query.where.office = officeWhereInput;
//call service to get prisma entity
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);
}
const officeId: string = req.body.user.office_Id;
const officeWhereInput: Prisma.DeedsWhereInput = { deed_type: { office: { uid: officeId } } };
query.where = officeWhereInput;
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
if(!query.where) query.where = { deed_type : {office: officeWhereInput}};
query.where.deed_type!.office = officeWhereInput;
//call service to get prisma entity
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);
}
const officeId: string = req.body.user.office_Id;
const officeWhereInput: Prisma.DocumentTypesWhereInput = { office: { uid: officeId } };
query.where = officeWhereInput;
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
if(!query.where) query.where = { office: officeWhereInput};
query.where.office = officeWhereInput;
//call service to get prisma entity
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);
}
const officeId: string = req.body.user.office_Id;
const officeWhereInput: Prisma.DocumentsWhereInput = { document_type: { office: { uid: officeId } } };
query.where = officeWhereInput;
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
if(!query.where) query.where = { document_type : {office: officeWhereInput}};
query.where.document_type!.office = officeWhereInput;
//call service to get prisma entity
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);
}
const officeId: string = req.body.user.office_Id;
const officeWhereInput: Prisma.FilesWhereInput = { document: { folder: { office: { uid: officeId } } } };
query.where = officeWhereInput;
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
if(!query.where) query.where = { document: { folder: {office: officeWhereInput}}};
query.where.document!.folder!.office = officeWhereInput;
//call service to get prisma entity
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);
}
const officeId: string = req.body.user.office_Id;
const officeWhereInput: Prisma.OfficeFoldersWhereInput = { office: { uid: officeId } };
query.where = officeWhereInput;
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
if(!query.where) query.where = { office: officeWhereInput};
query.where.office = officeWhereInput;
//call service to get prisma entity
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);
}
const officeId: string = req.body.user.office_Id;
const officeWhereInput: Prisma.OfficeRolesWhereInput = { office: { uid: officeId } };
query.where = officeWhereInput;
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
if(!query.where) query.where = { office: officeWhereInput};
query.where.office = officeWhereInput;
//call service to get prisma entity
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);
}
const officeId: string = req.body.user.office_Id;
const officeWhereInput: Prisma.UsersWhereInput = { office_membership: { uid: officeId } };
query.where = officeWhereInput;
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
if(!query.where) query.where = { office_membership: officeWhereInput};
query.where.office_membership = officeWhereInput;
//call service to get prisma entity
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) {
try {
//get query
let query = {};
let query;
if (req.query["q"]) {
query = JSON.parse(req.query["q"] as string);
}
@ -120,7 +120,7 @@ export default class CustomersController extends ApiController {
return;
}
let query = {};
let query;
if (req.query["q"]) {
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);
}
const officeId: string = req.body.user.office_Id;
const officeWhereInput: Prisma.DeedTypesWhereInput = { office: { uid: officeId } };
query.where = officeWhereInput;
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
if(!query.where) query.where = { office: officeWhereInput};
query.where.office = officeWhereInput;
//call service to get prisma entity
const deedTypeEntities: DeedTypes[] = await this.deedTypesService.get(query);
@ -131,7 +132,7 @@ export default class DeedTypesController extends ApiController {
return;
}
let query = {};
let query;
if (req.query["q"]) {
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);
}
const officeId: string = req.body.user.office_Id;
const officeWhereInput: Prisma.DeedsWhereInput = { deed_type: { office: { uid: officeId } } };
query.where = officeWhereInput;
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
if(!query.where) query.where = { deed_type : {office: officeWhereInput}};
query.where.deed_type!.office = officeWhereInput;
//call service to get prisma entity
const deedEntities: Deeds[] = await this.deedsService.get(query);
@ -60,7 +61,7 @@ export default class DeedsController extends ApiController {
return;
}
let query = {};
let query;
if (req.query["q"]) {
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);
}
const officeId: string = req.body.user.office_Id;
const officeWhereInput: Prisma.DocumentTypesWhereInput = { office: { uid: officeId } };
query.where = officeWhereInput;
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
if(!query.where) query.where = { office: officeWhereInput};
query.where.office = officeWhereInput;
//call service to get prisma entity
const documentTypeEntities: DocumentTypes[] = await this.documentTypesService.get(query);
@ -125,7 +126,7 @@ export default class DocumentTypesController extends ApiController {
return;
}
let query = {};
let query;
if (req.query["q"]) {
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);
}
const officeId: string = req.body.user.office_Id;
const officeWhereInput: Prisma.DocumentsWhereInput = { document_type: { office: { uid: officeId } } };
query.where = officeWhereInput;
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
if(!query.where) query.where = { document_type : {office: officeWhereInput}};
query.where.document_type!.office = officeWhereInput;
//call service to get prisma entity
const documentEntities = await this.documentsService.get(query);
@ -160,7 +161,7 @@ export default class DocumentsController extends ApiController {
return;
}
let query = {};
let query;
if (req.query["q"]) {
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);
}
const officeId: string = req.body.user.office_Id;
const officeWhereInput: Prisma.FilesWhereInput = { document: { folder: { office: { uid: officeId } } } };
query.where = officeWhereInput;
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
if(!query.where) query.where = { document: { folder: {office: officeWhereInput}}};
query.where.document!.folder!.office = officeWhereInput;
//call service to get prisma entity
const fileEntities = await this.filesService.get(query);
@ -123,7 +125,7 @@ export default class FilesController extends ApiController {
return;
}
let query = {};
let query;
if (req.query["q"]) {
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);
}
const officeId: string = req.body.user.office_Id;
const officeWhereInput: Prisma.OfficeFoldersWhereInput = { office: { uid: officeId } };
query.where = officeWhereInput;
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
if(!query.where) query.where = { office: officeWhereInput};
query.where.office = officeWhereInput;
//call service to get prisma entity
const officeFolderEntities: OfficeFolders[] = await this.officeFoldersService.get(query);
@ -82,12 +84,7 @@ export default class OfficeFoldersController extends ApiController {
return;
}
let query = {};
if (req.query["q"]) {
query = JSON.parse(req.query["q"] as string);
}
const officeFolderFound = await this.officeFoldersService.getByUid(uid, query);
const officeFolderFound = await this.officeFoldersService.getByUid(uid);
if (!officeFolderFound) {
this.httpNotFoundRequest(response, "office folder not found");
@ -129,18 +126,12 @@ export default class OfficeFoldersController extends ApiController {
return;
}
let officeFolderEntity: OfficeFolders | null;
//get query
if (req.query["q"]) {
let query = {};
let query;
if (req.query["q"]) {
query = JSON.parse(req.query["q"] as string);
}
officeFolderEntity = await this.officeFoldersService.getByUid(uid, query);
} else {
//call service to get prisma entity
officeFolderEntity = await this.officeFoldersService.getByUid(uid);
}
const officeFolderEntity = await this.officeFoldersService.getByUid(uid, query);
if (!officeFolderEntity) {
this.httpNotFoundRequest(response, "folder not found");

View File

@ -29,8 +29,9 @@ export default class OfficeRolesController extends ApiController {
query = JSON.parse(req.query["q"] as string);
}
const officeId: string = req.body.user.office_Id;
const officeWhereInput: Prisma.OfficeRolesWhereInput = { office: { uid: officeId } };
query.where = officeWhereInput;
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
if(!query.where) query.where = { office: officeWhereInput};
query.where.office = officeWhereInput;
//call service to get prisma entity
const officeRolesEntities = await this.officeRolesService.get(query);
@ -127,7 +128,7 @@ export default class OfficeRolesController extends ApiController {
return;
}
let query = {};
let query;
if (req.query["q"]) {
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) {
try {
//get query
let query = {};
let query;
if (req.query["q"]) {
query = JSON.parse(req.query["q"] as string);
}
@ -107,7 +107,7 @@ export default class OfficesController extends ApiController {
return;
}
let query = {};
let query;
if (req.query["q"]) {
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) {
try {
//get query
let query = {};
let query;
if (req.query["q"]) {
query = JSON.parse(req.query["q"] as string);
}
@ -122,7 +122,7 @@ export default class RolesController extends ApiController {
return;
}
let query = {};
let query;
if (req.query["q"]) {
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) {
try {
//get query
let query = {};
let query;
if (req.query["q"]) {
query = JSON.parse(req.query["q"] as string);
}
@ -121,7 +121,7 @@ export default class RulesController extends ApiController {
this.httpBadRequest(response, "No uid provided");
return;
}
let query = {};
let query;
if (req.query["q"]) {
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) {
try {
//get query
let query = {};
let query;
if (req.query["q"]) {
query = JSON.parse(req.query["q"] as string);
}
@ -121,7 +121,7 @@ export default class UsersController extends ApiController {
this.httpBadRequest(response, "No uid provided");
return;
}
let query = {};
let query;
if (req.query["q"]) {
query = JSON.parse(req.query["q"] as string);
}

View File

@ -8,14 +8,14 @@ export default function authHandler(req: Request, response: Response, next: Next
const token = authHeader && authHeader.split(" ")[1];
if (!token) {
response.sendStatus(HttpCodes.UNAUTHORIZED);
response.status(HttpCodes.UNAUTHORIZED).send("Missing token in authorization header");
return;
}
const authService = Container.get(AuthService);
authService.verifyAccessToken(token, (err, userPayload) => {
if (err) {
response.sendStatus(HttpCodes.UNAUTHORIZED);
response.status(HttpCodes.UNAUTHORIZED).send("Error while verifying token");
return;
}
req.body.user = userPayload;

View File

@ -8,7 +8,7 @@ export default async function documentHandler(req: Request, response: Response,
const uid = req.path && req.path.split("/")[5];
if(!uid) {
response.sendStatus(HttpCodes.BAD_REQUEST);
response.status(HttpCodes.BAD_REQUEST).send("Missing document uid");
return;
}
@ -16,7 +16,7 @@ export default async function documentHandler(req: Request, response: Response,
const document = await documentService.getByUid(uid);
if(document?.depositor_uid != customerId) {
response.sendStatus(HttpCodes.UNAUTHORIZED);
response.status(HttpCodes.UNAUTHORIZED).send("Not authorized with this depositor");
return;
}

View File

@ -13,11 +13,11 @@ export default async function fileHandler(req: Request, response: Response, next
const fileService = Container.get(FilesService);
const file = await fileService.getByUidWithDocument(uid);
if (!file) {
response.sendStatus(HttpCodes.BAD_REQUEST);
response.status(HttpCodes.NOT_FOUND).send("File not found");
return;
}
if (file.document.depositor_uid != customerId) {
response.sendStatus(HttpCodes.UNAUTHORIZED);
response.status(HttpCodes.UNAUTHORIZED).send("Not authorized with this depositor");
return;
}
}
@ -26,11 +26,11 @@ export default async function fileHandler(req: Request, response: Response, next
const documentService = Container.get(DocumentsService);
const documentFound = await documentService.getByUid(document.uid!);
if(!documentFound) {
response.sendStatus(HttpCodes.BAD_REQUEST);
response.status(HttpCodes.NOT_FOUND).send("Document not found");
return;
}
if (documentFound.depositor_uid != customerId) {
response.sendStatus(HttpCodes.UNAUTHORIZED);
response.status(HttpCodes.UNAUTHORIZED).send("Not authorized with this depositor");
return;
}
}

View File

@ -12,15 +12,15 @@ export default async function deedHandler(req: Request, response: Response, next
if (uid) {
const deedService = Container.get(DeedsService);
const deed = await deedService.getOneByUidWithOffice(uid);
const deed = await deedService.getByUidWithOffice(uid);
if (!deed) {
response.sendStatus(HttpCodes.NOT_FOUND);
response.status(HttpCodes.NOT_FOUND).send("Deed not found");
return;
}
if (deed.deed_type.office.uid != officeId) {
response.sendStatus(HttpCodes.UNAUTHORIZED);
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
return;
}
}
@ -30,11 +30,11 @@ export default async function deedHandler(req: Request, response: Response, next
documentTypes.forEach(async (documentType) => {
const deedTypeWithOffice = await documentTypeService.getByUidWithOffice(documentType.uid!);
if (!deedTypeWithOffice) {
response.sendStatus(HttpCodes.NOT_FOUND);
response.status(HttpCodes.NOT_FOUND).send("Deed type not found");
return;
}
if (deedTypeWithOffice.office?.uid != officeId) {
response.sendStatus(HttpCodes.UNAUTHORIZED);
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
return;
}
});

View File

@ -12,7 +12,7 @@ export default async function deedTypeHandler(req: Request, response: Response,
const office = req.body.office;
if (office && office.uid != officeId) {
response.sendStatus(HttpCodes.UNAUTHORIZED);
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
return;
}
@ -21,12 +21,12 @@ export default async function deedTypeHandler(req: Request, response: Response,
const deedType = await deedTypeService.getByUidWithOffice(uid!);
if (!deedType) {
response.sendStatus(HttpCodes.NOT_FOUND);
response.status(HttpCodes.NOT_FOUND).send("Deed type not found");
return;
}
if (deedType.office.uid != officeId) {
response.sendStatus(HttpCodes.UNAUTHORIZED);
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
return;
}
}
@ -36,11 +36,11 @@ export default async function deedTypeHandler(req: Request, response: Response,
documentTypes.forEach(async (documentType) => {
const documentTypeWithOffice = await documentTypeService.getByUidWithOffice(documentType.uid!);
if (!documentTypeWithOffice) {
response.sendStatus(HttpCodes.NOT_FOUND);
response.status(HttpCodes.NOT_FOUND).send("Document type not found");
return;
}
if (documentTypeWithOffice.office?.uid != officeId) {
response.sendStatus(HttpCodes.UNAUTHORIZED);
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
return;
}
});

View File

@ -17,11 +17,11 @@ export default async function documentHandler(req: Request, response: Response,
const officeFolderService = Container.get(OfficeFoldersService);
const officeFolderWithOffice = await officeFolderService.getByUidWithOffice(folder.uid!);
if (!officeFolderWithOffice) {
response.sendStatus(HttpCodes.NOT_FOUND);
response.status(HttpCodes.NOT_FOUND).send("Folder not found");
return;
}
if (officeFolderWithOffice.office?.uid != officeId) {
response.sendStatus(HttpCodes.UNAUTHORIZED);
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
return;
}
}
@ -30,11 +30,11 @@ export default async function documentHandler(req: Request, response: Response,
const documentTypeService = Container.get(DocumentTypesService);
const documentTypeWithOffice = await documentTypeService.getByUidWithOffice(documentType.uid!);
if (!documentTypeWithOffice) {
response.sendStatus(HttpCodes.NOT_FOUND);
response.status(HttpCodes.NOT_FOUND).send("Document type not found");
return;
}
if (documentTypeWithOffice.office?.uid != officeId) {
response.sendStatus(HttpCodes.UNAUTHORIZED);
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
return;
}
}

View File

@ -9,7 +9,7 @@ export default async function documentTypeHandler(req: Request, response: Respon
const office = req.body.office;
if (office && office.uid != officeId) {
response.sendStatus(HttpCodes.UNAUTHORIZED);
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
return;
}
@ -18,12 +18,12 @@ export default async function documentTypeHandler(req: Request, response: Respon
const documentType = await documentTypeService.getByUidWithOffice(uid!);
if (!documentType) {
response.sendStatus(HttpCodes.NOT_FOUND);
response.status(HttpCodes.NOT_FOUND).send("Document type not found");
return;
}
if (documentType.office.uid != officeId) {
response.sendStatus(HttpCodes.UNAUTHORIZED);
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
return;
}
}

View File

@ -13,11 +13,11 @@ export default async function fileHandler(req: Request, response: Response, next
const documentService = Container.get(DocumentsService);
const documentWithOffice = await documentService.getByUidWithOffice(document.uid!);
if (!documentWithOffice) {
response.sendStatus(HttpCodes.NOT_FOUND);
response.status(HttpCodes.NOT_FOUND).send("Document not found");
return;
}
if (documentWithOffice.folder.office?.uid != officeId) {
response.sendStatus(HttpCodes.UNAUTHORIZED);
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
return;
}
}
@ -29,11 +29,11 @@ export default async function fileHandler(req: Request, response: Response, next
const file = await fileService.getByUidWithOffice(uid!);
if (!file) {
response.sendStatus(HttpCodes.NOT_FOUND);
response.status(HttpCodes.NOT_FOUND).send("File not found");
return;
}
if (file.document.folder.office.uid != officeId) {
response.sendStatus(HttpCodes.UNAUTHORIZED);
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
return;
}
}

View File

@ -12,31 +12,33 @@ export default async function folderHandler(req: Request, response: Response, ne
const deed = req.body.deed;
if (office && office.uid != officeId) {
response.sendStatus(HttpCodes.UNAUTHORIZED);
console.log("wrong office");
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
return;
}
if (deed) {
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) {
response.sendStatus(HttpCodes.NOT_FOUND);
response.status(HttpCodes.NOT_FOUND).send("Deed type not found");
return;
}
if (deedTypeWithOffice.office.uid != officeId) {
response.sendStatus(HttpCodes.UNAUTHORIZED);
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this deed type");
return;
}
}
const officeFolderService = Container.get(OfficeFoldersService);
if (officeFolderNumber) {
if (officeFolderNumber && req.method == "POST") {
const officeFoldersWithSameNumber = await officeFolderService.get({
where: { folder_number: officeFolderNumber, office: { uid: officeId } },
});
if (officeFoldersWithSameNumber.length) {
response.sendStatus(HttpCodes.BAD_REQUEST);
response.status(HttpCodes.BAD_REQUEST).send("Office number already used");
return;
}
}
@ -45,12 +47,12 @@ export default async function folderHandler(req: Request, response: Response, ne
const officeFolder = await officeFolderService.getByUidWithOffice(uid!);
if (!officeFolder) {
response.sendStatus(HttpCodes.NOT_FOUND);
response.status(HttpCodes.NOT_FOUND).send("Office folder not found");
return;
}
if (officeFolder.office.uid != officeId) {
response.sendStatus(HttpCodes.UNAUTHORIZED);
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
return;
}
}

View File

@ -9,7 +9,7 @@ export default async function officeRoleHandler(req: Request, response: Response
const office = req.body.office;
if (office && office.uid != officeId) {
response.sendStatus(HttpCodes.UNAUTHORIZED);
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
return;
}
@ -18,12 +18,12 @@ export default async function officeRoleHandler(req: Request, response: Response
const officeRole = await officeRoleService.getByUidWithOffice(uid!);
if (!officeRole) {
response.sendStatus(HttpCodes.NOT_FOUND);
response.status(HttpCodes.NOT_FOUND).send("Office role not found");
return;
}
if (officeRole.office.uid != officeId) {
response.sendStatus(HttpCodes.UNAUTHORIZED);
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
return;
}
}

View File

@ -9,7 +9,7 @@ export default async function userHandler(req: Request, response: Response, next
const office = req.body.office_membership;
if (office && office.uid != officeId) {
response.sendStatus(HttpCodes.UNAUTHORIZED);
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
return;
}
@ -18,12 +18,12 @@ export default async function userHandler(req: Request, response: Response, next
const user = await userService.getByUidWithOffice(uid!);
if (!user) {
response.sendStatus(HttpCodes.NOT_FOUND);
response.status(HttpCodes.NOT_FOUND).send("User not found");
return;
}
if (user.office_membership.uid != officeId) {
response.sendStatus(HttpCodes.UNAUTHORIZED);
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
return;
}
}

View File

@ -8,12 +8,12 @@ export default async function ruleHandler(req: Request, response: Response, next
const role = req.body.user.role;
if (namespace != "notary" && role != namespace) {
response.sendStatus(HttpCodes.UNAUTHORIZED);
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this role");
return;
}
if (!rules.includes(req.method + " " + service)) {
response.sendStatus(HttpCodes.UNAUTHORIZED);
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with those rules");
return;
}

View File

@ -554,7 +554,7 @@ export default async function main() {
updated_at: new Date(),
},
{
name: "GET documentTypes",
name: "GET document-types",
created_at: new Date(),
updated_at: new Date(),
},
@ -614,7 +614,7 @@ export default async function main() {
updated_at: new Date(),
},
{
name: "PUT documentTypes",
name: "PUT document-types",
created_at: new Date(),
updated_at: new Date(),
},
@ -674,7 +674,7 @@ export default async function main() {
updated_at: new Date(),
},
{
name: "POST documentTypes",
name: "POST document-types",
created_at: new Date(),
updated_at: new Date(),
},
@ -724,7 +724,7 @@ export default async function main() {
updated_at: new Date(),
},
{
name: "POST deedtypes",
name: "POST deed-types",
created_at: new Date(),
updated_at: new Date(),
},
@ -734,7 +734,7 @@ export default async function main() {
updated_at: new Date(),
},
{
name: "POST documentTypes",
name: "POST document-types",
created_at: new Date(),
updated_at: new Date(),
},
@ -784,7 +784,7 @@ export default async function main() {
updated_at: new Date(),
},
{
name: "DELETE deedtypes",
name: "DELETE deed-types",
created_at: new Date(),
updated_at: new Date(),
},
@ -794,7 +794,7 @@ export default async function main() {
updated_at: new Date(),
},
{
name: "DELETE documentTypes",
name: "DELETE document-types",
created_at: new Date(),
updated_at: new Date(),
},

View File

@ -3,6 +3,7 @@ import BaseRepository from "@Repositories/BaseRepository";
import { Service } from "typedi";
import { Documents, EDocumentStatus, Prisma } from "@prisma/client";
import { Document } from "le-coffre-resources/dist/SuperAdmin";
import { Document as DocumentCustomer } from "le-coffre-resources/dist/Customer";
@Service()
export default class DocumentsRepository extends BaseRepository {
@ -94,7 +95,7 @@ export default class DocumentsRepository extends BaseRepository {
/**
* @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({
where: {
uid: uid,

View File

@ -82,7 +82,7 @@ export default class AuthService extends BaseService {
}
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 {

View File

@ -18,22 +18,6 @@ export default class DocumentsService extends BaseService {
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
* @throws {Error} If document cannot be modified
@ -42,14 +26,6 @@ export default class DocumentsService extends BaseService {
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
* @throws {Error} If document cannot be get by uid

View File

@ -42,7 +42,7 @@ export default class DeedsService extends BaseService {
return this.deedRepository.findOneByUid(uid, query);
}
public async getOneByUidWithOffice(uid: string) {
public async getByUidWithOffice(uid: string) {
return this.deedRepository.findOneByUidWithOffice(uid);
}
}

View File

@ -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";
export const userAddress: Address = {