Merge Dev in Staging
This commit is contained in:
commit
f3198ff212
21780
doc/Le Coffre Api.postman_collection.json
Normal file
21780
doc/Le Coffre Api.postman_collection.json
Normal file
File diff suppressed because it is too large
Load Diff
6744
doc/swagger.json
Normal file
6744
doc/swagger.json
Normal file
File diff suppressed because it is too large
Load Diff
@ -70,6 +70,7 @@ export default class DocumentsController extends ApiController {
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
if (query.folder) delete query.folder;
|
||||
|
||||
}
|
||||
|
||||
const documentEntity = await this.documentsService.getByUid(uid, query);
|
||||
@ -85,6 +86,7 @@ export default class DocumentsController extends ApiController {
|
||||
//success
|
||||
this.httpSuccess(response, document);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Delete, Get, Post, Put } from "@ControllerPattern/index";
|
||||
import { Controller, Delete, Get, Post } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import { Service } from "typedi";
|
||||
import FilesService from "@Services/common/FilesService/FilesService";
|
||||
import { Files, Prisma } from "@prisma/client";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { File } from "le-coffre-resources/dist/Customer";
|
||||
import { Document } from "le-coffre-resources/dist/Customer";
|
||||
import DocumentsService from "@Services/customer/DocumentsService/DocumentsService";
|
||||
@ -15,7 +15,11 @@ import { validateOrReject } from "class-validator";
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class FilesController extends ApiController {
|
||||
constructor(private filesService: FilesService, private documentService: DocumentsService, private notificationBuilder : NotificationBuilder) {
|
||||
constructor(
|
||||
private filesService: FilesService,
|
||||
private documentService: DocumentsService,
|
||||
private notificationBuilder: NotificationBuilder,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
@ -31,10 +35,15 @@ export default class FilesController extends ApiController {
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
}
|
||||
const customerId: string = req.body.user.customerId;
|
||||
const customerWhereInput: Prisma.FilesWhereInput = { document: { depositor: { uid: customerId } } };
|
||||
const email: string = req.body.user.email;
|
||||
if (!email) {
|
||||
this.httpBadRequest(response, "Missing customer email");
|
||||
return;
|
||||
}
|
||||
if (query.where?.document?.depositor) delete query.where.document.depositor;
|
||||
const customerWhereInput: Prisma.FilesWhereInput = { ...query.where, document: { depositor: { contact: { email: email } } } };
|
||||
query.where = customerWhereInput;
|
||||
if(query.include?.document) delete query.include.document;
|
||||
if (query.include?.document) delete query.include.document;
|
||||
|
||||
//call service to get prisma entity
|
||||
const fileEntities = await this.filesService.get(query);
|
||||
@ -115,7 +124,6 @@ export default class FilesController extends ApiController {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
|
||||
//success
|
||||
this.httpCreated(response, fileEntityHydrated);
|
||||
} catch (error) {
|
||||
@ -124,41 +132,6 @@ export default class FilesController extends ApiController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Update a specific file
|
||||
*/
|
||||
@Put("/api/v1/customer/files/:uid", [authHandler, fileHandler])
|
||||
protected async update(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
throw new Error("No uid provided");
|
||||
}
|
||||
|
||||
const fileFound = await this.filesService.getByUid(uid);
|
||||
|
||||
if (!fileFound) {
|
||||
this.httpNotFoundRequest(response, "file not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//init File resource with request body values
|
||||
const fileEntity = File.hydrate<File>(req.body);
|
||||
|
||||
//call service to get prisma entity
|
||||
const fileEntityUpdated: Files = await this.filesService.update(uid, fileEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const file = File.hydrate<File>(fileEntityUpdated, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, file);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Delete a specific File
|
||||
*/
|
||||
@ -212,7 +185,7 @@ export default class FilesController extends ApiController {
|
||||
let query;
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
if(query.document) delete query.document;
|
||||
if (query.document) delete query.document;
|
||||
}
|
||||
|
||||
const fileEntity = await this.filesService.getByUid(uid, query);
|
||||
|
@ -125,27 +125,29 @@ export default class CustomersController extends ApiController {
|
||||
return;
|
||||
}
|
||||
|
||||
const customers = await this.customersService.get({
|
||||
where: {
|
||||
contact: { email: customerEntity.contact?.email },
|
||||
office_folders: {
|
||||
some: {
|
||||
office_uid: req.body.user.office_Id,
|
||||
if (customerEntity.contact?.email) {
|
||||
const customers = await this.customersService.get({
|
||||
where: {
|
||||
contact: { email: customerEntity.contact?.email },
|
||||
office_folders: {
|
||||
some: {
|
||||
office_uid: req.body.user.office_Id,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
if (customers.length != 0) {
|
||||
try {
|
||||
customers.forEach((customer) => {
|
||||
if (customer.uid != uid) {
|
||||
throw new Error("email déjà utilisé");
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
this.httpValidationError(response, [{ property: "email", constraints: { unique: "email déjà utilisé" } }]);
|
||||
return;
|
||||
if (customers.length != 0) {
|
||||
try {
|
||||
customers.forEach((customer) => {
|
||||
if (customer.uid != uid) {
|
||||
throw new Error("email déjà utilisé");
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
this.httpValidationError(response, [{ property: "email", constraints: { unique: "email déjà utilisé" } }]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@ import UserNotification from "le-coffre-resources/dist/Notary/UserNotification";
|
||||
import UserNotificationService from "@Services/common/UserNotificationService/UserNotificationService";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import roleHandler from "@App/middlewares/RolesHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
@ -17,7 +18,7 @@ export default class UserNotificationController extends ApiController {
|
||||
/**
|
||||
* @description Get all customers
|
||||
*/
|
||||
@Get("/api/v1/notary/notifications", [authHandler])
|
||||
@Get("/api/v1/notary/notifications", [authHandler, roleHandler])
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
@ -51,7 +52,7 @@ export default class UserNotificationController extends ApiController {
|
||||
/**
|
||||
* @description Modify a specific customer by uid
|
||||
*/
|
||||
@Put("/api/v1/notary/notifications/:uid", [authHandler])
|
||||
@Put("/api/v1/notary/notifications/:uid", [authHandler, roleHandler])
|
||||
protected async put(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
@ -94,7 +95,7 @@ export default class UserNotificationController extends ApiController {
|
||||
/**
|
||||
* @description Get a specific customer by uid
|
||||
*/
|
||||
@Get("/api/v1/notary/notifications/:uid", [authHandler])
|
||||
@Get("/api/v1/notary/notifications/:uid", [authHandler, roleHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
|
@ -3,9 +3,9 @@ import DocumentsService from "@Services/customer/DocumentsService/DocumentsServi
|
||||
import Document from "le-coffre-resources/dist/SuperAdmin/Document";
|
||||
import { NextFunction, Request, Response } from "express";
|
||||
import Container from "typedi";
|
||||
import ContactsService from "@Services/common/ContactService/ContactService";
|
||||
import OfficeFoldersService from "@Services/super-admin/OfficeFoldersService/OfficeFoldersService";
|
||||
import { OfficeFolder } from "le-coffre-resources/dist/SuperAdmin";
|
||||
import CustomersService from "@Services/super-admin/CustomersService/CustomersService";
|
||||
|
||||
export default async function documentHandler(req: Request, response: Response, next: NextFunction) {
|
||||
try {
|
||||
@ -23,8 +23,8 @@ export default async function documentHandler(req: Request, response: Response,
|
||||
}
|
||||
|
||||
if (document?.depositor_uid != customerId) {
|
||||
const contactService = Container.get(ContactsService);
|
||||
const customers = await contactService.getByEmail(customerEmail);
|
||||
const customerService = Container.get(CustomersService);
|
||||
const customers = await customerService.get({where: {contact: { email: customerEmail}}});
|
||||
if (customers && !customers.find((customer) => customer.uid === document?.depositor_uid)) {
|
||||
response.status(HttpCodes.UNAUTHORIZED).send("Not authorized with this depositor");
|
||||
return;
|
||||
|
@ -7,6 +7,11 @@ export default async function roleHandler(req: Request, response: Response, next
|
||||
const namespace = req.path && req.path.split("/")[3];
|
||||
const role = req.body.user.role;
|
||||
|
||||
if(!role) {
|
||||
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized without role");
|
||||
return;
|
||||
}
|
||||
|
||||
if (namespace != "notary" && role != namespace && role != "super-admin") {
|
||||
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this role");
|
||||
return;
|
||||
|
Loading…
x
Reference in New Issue
Block a user