Fixed
This commit is contained in:
parent
42c72713fb
commit
ecc0342155
43
src/app/api/customer/OfficeRibController.ts
Normal file
43
src/app/api/customer/OfficeRibController.ts
Normal file
@ -0,0 +1,43 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Get } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
|
||||
import { Service } from "typedi";
|
||||
import OfficerRibService from "@Services/common/OfficeRibService/OfficeRibService";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import OfficesService from "@Services/customer/OfficesService/OfficesService";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class OfficeRibController extends ApiController {
|
||||
constructor(private officeRibService: OfficerRibService, private officesService: OfficesService) {
|
||||
super();
|
||||
}
|
||||
|
||||
@Get("/api/v1/customer/office/:uid/rib", [authHandler])
|
||||
protected async getRibStream(req: Request, response: Response) {
|
||||
const officeId = req.params["uid"];
|
||||
if (!officeId) throw new Error("No officeId provided");
|
||||
|
||||
const office = await this.officesService.getByUid(officeId, { address: true });
|
||||
|
||||
if (!office) {
|
||||
this.httpNotFoundRequest(response, "Office not found");
|
||||
return;
|
||||
}
|
||||
|
||||
const fileName = office.rib_name;
|
||||
if (!fileName) {
|
||||
this.httpNotFoundRequest(response, "No file found");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const file = await this.officeRibService.getByUid(officeId, fileName!);
|
||||
response.attachment(fileName!);
|
||||
response.send(file.Body);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
}
|
||||
}
|
||||
}
|
@ -3,27 +3,24 @@ import { Controller, Delete, Get, Post } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
|
||||
import { Service } from "typedi";
|
||||
import BucketService from "@Services/common/BucketService/BucketService";
|
||||
import OfficerRibService from "@Services/common/OfficeRibService/OfficeRibService";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import OfficesService from "@Services/notary/OfficesService/OfficesService";
|
||||
import { Office as OfficeResource } from "le-coffre-resources/dist/Notary";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class BucketController extends ApiController {
|
||||
constructor(private bucketService: BucketService, private officesService: OfficesService) {
|
||||
export default class OfficeRibController extends ApiController {
|
||||
constructor(private officeRibService: OfficerRibService, private officesService: OfficesService) {
|
||||
super();
|
||||
}
|
||||
|
||||
@Get("/api/v1/notary/bucket/:uid", [authHandler])
|
||||
@Get("/api/v1/notary/office/rib", [authHandler])
|
||||
protected async getRibStream(req: Request, response: Response) {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
if (!officeId) throw new Error("No officeId provided");
|
||||
|
||||
const office = await this.officesService.getByUid(uid, {address: true});
|
||||
const office = await this.officesService.getByUid(officeId, { address: true });
|
||||
|
||||
if (!office) {
|
||||
this.httpNotFoundRequest(response, "Office not found");
|
||||
@ -37,7 +34,7 @@ export default class BucketController extends ApiController {
|
||||
}
|
||||
|
||||
try {
|
||||
const file = await this.bucketService.getByUid(uid, fileName!);
|
||||
const file = await this.officeRibService.getByUid(officeId, fileName!);
|
||||
response.attachment(fileName!);
|
||||
response.send(file.Body);
|
||||
} catch (error) {
|
||||
@ -45,10 +42,10 @@ export default class BucketController extends ApiController {
|
||||
}
|
||||
}
|
||||
|
||||
@Post("/api/v1/notary/bucket", [authHandler])
|
||||
@Post("/api/v1/notary/office/rib", [authHandler])
|
||||
protected async post(req: Request, response: Response) {
|
||||
try {
|
||||
const officeId: string = req.body.user.office_Id
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
if (!req.file) throw new Error("No file provided");
|
||||
if (!officeId) throw new Error("No officeId provided");
|
||||
|
||||
@ -58,7 +55,7 @@ export default class BucketController extends ApiController {
|
||||
this.httpNotFoundRequest(response, "office not found");
|
||||
return;
|
||||
}
|
||||
const fileUrl = await this.bucketService.createOrUpdate(officeId, req.file);
|
||||
const fileUrl = await this.officeRibService.createOrUpdate(officeId, req.file);
|
||||
|
||||
if (!fileUrl || !req.file.originalname) throw new Error("Error while uploading file");
|
||||
|
||||
@ -84,15 +81,13 @@ export default class BucketController extends ApiController {
|
||||
}
|
||||
}
|
||||
|
||||
@Delete("/api/v1/notary/bucket/:uid", [authHandler])
|
||||
@Delete("/api/v1/notary/office/rib", [authHandler])
|
||||
protected async delete(req: Request, response: Response) {
|
||||
try {
|
||||
const officeId: string = req.body.user.office_Id
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
if (!officeId) throw new Error("No officeId provided");
|
||||
|
||||
const office = await this.officesService.getByUid(officeId, { address: true });
|
||||
console.log(office);
|
||||
|
||||
|
||||
if (!office) {
|
||||
this.httpNotFoundRequest(response, "office not found");
|
||||
@ -101,7 +96,7 @@ export default class BucketController extends ApiController {
|
||||
|
||||
const fileName = office.rib_name;
|
||||
|
||||
await this.bucketService.delete(officeId, fileName!);
|
||||
await this.officeRibService.delete(officeId, fileName!);
|
||||
|
||||
office.rib_url = null;
|
||||
office.rib_name = null;
|
@ -7,6 +7,7 @@ import { Offices, Prisma } from "@prisma/client";
|
||||
import { Office as OfficeResource } from "le-coffre-resources/dist/Notary";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import uuidMatcher from "@App/uuidMatcher";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
@ -49,8 +50,9 @@ export default class OfficesController extends ApiController {
|
||||
|
||||
/**
|
||||
* @description Get a specific office by uid
|
||||
* `/:id(${uuidMatcher})`
|
||||
*/
|
||||
@Get("/api/v1/notary/offices/:uid", [authHandler, ruleHandler])
|
||||
@Get(`/api/v1/notary/offices/:uid(${uuidMatcher})`, [authHandler, ruleHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
|
@ -46,7 +46,8 @@ import DocumentControllerId360 from "./api/id360/DocumentController";
|
||||
import CustomerControllerId360 from "./api/id360/CustomerController";
|
||||
import UserNotificationController from "./api/notary/UserNotificationController";
|
||||
import AuthController from "./api/customer/AuthController";
|
||||
import BucketController from "./api/notary/BucketController";
|
||||
import NotaryOfficeRibController from "./api/notary/OfficeRibController";
|
||||
import CustomerOfficeRibController from "./api/customer/OfficeRibController";
|
||||
|
||||
/**
|
||||
* @description This allow to declare all controllers used in the application
|
||||
@ -101,6 +102,7 @@ export default {
|
||||
Container.get(DocumentControllerId360);
|
||||
Container.get(CustomerControllerId360);
|
||||
Container.get(AuthController);
|
||||
Container.get(BucketController);
|
||||
Container.get(NotaryOfficeRibController);
|
||||
Container.get(CustomerOfficeRibController);
|
||||
},
|
||||
};
|
||||
|
2
src/app/uuidMatcher.ts
Normal file
2
src/app/uuidMatcher.ts
Normal file
@ -0,0 +1,2 @@
|
||||
const uuidMatcher = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[89ab][0-9a-f]{3}-[0-9a-f]{12}";
|
||||
export default uuidMatcher;
|
@ -14,18 +14,15 @@ const s3 = new AWS.S3({
|
||||
});
|
||||
|
||||
@Service()
|
||||
export default class BucketService extends BaseService {
|
||||
export default class OfficerRibService extends BaseService {
|
||||
constructor(private variables: BackendVariables) {
|
||||
super();
|
||||
}
|
||||
|
||||
public async download() {
|
||||
|
||||
}
|
||||
|
||||
public async getByUid(uid: string, fileName: string) {
|
||||
const key = path.join(this.variables.ENV, uid, fileName);
|
||||
|
||||
|
||||
return new Promise<AWS.S3.GetObjectOutput>(async (resolve, reject) => {
|
||||
s3.getObject(
|
||||
{
|
28
src/services/customer/OfficesService/OfficesService.ts
Normal file
28
src/services/customer/OfficesService/OfficesService.ts
Normal file
@ -0,0 +1,28 @@
|
||||
import {Prisma } from "@prisma/client";
|
||||
import OfficesRepository from "@Repositories/OfficesRepository";
|
||||
import BaseService from "@Services/BaseService";
|
||||
import { Service } from "typedi";
|
||||
|
||||
|
||||
@Service()
|
||||
export default class OfficesService extends BaseService {
|
||||
constructor(private officeRepository: OfficesRepository) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get all offices
|
||||
* @throws {Error} If offices cannot be get
|
||||
*/
|
||||
public async get(query: Prisma.OfficesFindManyArgs) {
|
||||
return this.officeRepository.findMany(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get a office by uid
|
||||
* @throws {Error} If office cannot be get
|
||||
*/
|
||||
public async getByUid(uid: string, query?: Prisma.OfficesInclude) {
|
||||
return this.officeRepository.findOneByUid(uid, query);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user