page select folder unmocked
This commit is contained in:
parent
bd815853d0
commit
a086572b14
115
src/app/api/customer/OfficeFoldersController.ts
Normal file
115
src/app/api/customer/OfficeFoldersController.ts
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
import { Response, Request } from "express";
|
||||||
|
import { Controller, Get } from "@ControllerPattern/index";
|
||||||
|
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||||
|
import OfficeFoldersService from "@Services/customer/OfficeFoldersService/OfficeFoldersService";
|
||||||
|
import { Service } from "typedi";
|
||||||
|
import { OfficeFolders, Prisma } from "@prisma/client";
|
||||||
|
import { OfficeFolder } from "le-coffre-resources/dist/Customer";
|
||||||
|
import authHandler from "@App/middlewares/AuthHandler";
|
||||||
|
// import ruleHandler from "@App/middlewares/RulesHandler";
|
||||||
|
// import folderHandler from "@App/middlewares/OfficeMembershipHandlers/FolderHandler";
|
||||||
|
|
||||||
|
@Controller()
|
||||||
|
@Service()
|
||||||
|
export default class OfficeFoldersController extends ApiController {
|
||||||
|
constructor(private officeFoldersService: OfficeFoldersService) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Get all folders
|
||||||
|
*/
|
||||||
|
@Get("/api/v1/customer/folders", [authHandler])
|
||||||
|
protected async get(req: Request, response: Response) {
|
||||||
|
try {
|
||||||
|
//get query
|
||||||
|
let query: Prisma.OfficeFoldersFindManyArgs = {};
|
||||||
|
if (req.query["q"]) {
|
||||||
|
query = JSON.parse(req.query["q"] as string);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(query.where?.customers?.every);
|
||||||
|
|
||||||
|
if (req.query["search"] && typeof req.query["search"] === "string") {
|
||||||
|
const filter = req.query["search"];
|
||||||
|
query = {
|
||||||
|
where: {
|
||||||
|
OR: [
|
||||||
|
{
|
||||||
|
name: { contains: filter, mode: "insensitive" },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
folder_number: { contains: filter, mode: "insensitive" },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
customers: {
|
||||||
|
some: {
|
||||||
|
contact: {
|
||||||
|
OR: [
|
||||||
|
{ first_name: { contains: filter, mode: "insensitive" } },
|
||||||
|
{ last_name: { contains: filter, mode: "insensitive" } },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const officeId: string = req.body.user.office_Id;
|
||||||
|
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);
|
||||||
|
|
||||||
|
//Hydrate ressource with prisma entity
|
||||||
|
const officeFolders = OfficeFolder.hydrateArray<OfficeFolder>(officeFolderEntities, {
|
||||||
|
strategy: "excludeAll",
|
||||||
|
});
|
||||||
|
//success
|
||||||
|
this.httpSuccess(response, officeFolders);
|
||||||
|
} catch (error) {
|
||||||
|
this.httpInternalError(response, error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Get a specific folder by uid
|
||||||
|
* @returns IFolder
|
||||||
|
*/
|
||||||
|
@Get("/api/v1/customer/folders/:uid")
|
||||||
|
protected async getOneByUid(req: Request, response: Response) {
|
||||||
|
try {
|
||||||
|
const uid = req.params["uid"];
|
||||||
|
if (!uid) {
|
||||||
|
this.httpBadRequest(response, "No uid provided");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let query;
|
||||||
|
if (req.query["q"]) {
|
||||||
|
query = JSON.parse(req.query["q"] as string);
|
||||||
|
}
|
||||||
|
|
||||||
|
const officeFolderEntity = await this.officeFoldersService.getByUid(uid, query);
|
||||||
|
|
||||||
|
if (!officeFolderEntity) {
|
||||||
|
this.httpNotFoundRequest(response, "folder not found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Hydrate ressource with prisma entity
|
||||||
|
const officeFolder = OfficeFolder.hydrate<OfficeFolder>(officeFolderEntity, { strategy: "excludeAll" });
|
||||||
|
|
||||||
|
//success
|
||||||
|
this.httpSuccess(response, officeFolder);
|
||||||
|
} catch (error) {
|
||||||
|
this.httpInternalError(response, error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -40,6 +40,7 @@ import RolesControllerNotary from "./api/notary/RolesController";
|
|||||||
import OfficeRolesControllerNotary from "./api/notary/OfficeRolesController";
|
import OfficeRolesControllerNotary from "./api/notary/OfficeRolesController";
|
||||||
import FilesControllerCustomer from "./api/customer/FilesController";
|
import FilesControllerCustomer from "./api/customer/FilesController";
|
||||||
import DocumentsControllerCustomer from "./api/customer/DocumentsController";
|
import DocumentsControllerCustomer from "./api/customer/DocumentsController";
|
||||||
|
import OfficeFoldersController from "./api/customer/OfficeFoldersController";
|
||||||
import AppointmentsController from "./api/super-admin/AppointmentsController";
|
import AppointmentsController from "./api/super-admin/AppointmentsController";
|
||||||
import VotesController from "./api/super-admin/VotesController";
|
import VotesController from "./api/super-admin/VotesController";
|
||||||
import LiveVoteController from "./api/super-admin/LiveVoteController";
|
import LiveVoteController from "./api/super-admin/LiveVoteController";
|
||||||
@ -95,5 +96,6 @@ export default {
|
|||||||
Container.get(OfficeRolesControllerNotary);
|
Container.get(OfficeRolesControllerNotary);
|
||||||
Container.get(FilesControllerCustomer);
|
Container.get(FilesControllerCustomer);
|
||||||
Container.get(DocumentsControllerCustomer);
|
Container.get(DocumentsControllerCustomer);
|
||||||
|
Container.get(OfficeFoldersController);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -6,10 +6,10 @@ export default async function ruleHandler(req: Request, response: Response, next
|
|||||||
const rules = req.body.user.rules;
|
const rules = req.body.user.rules;
|
||||||
const service = req.path && req.path.split("/")[4];
|
const service = req.path && req.path.split("/")[4];
|
||||||
|
|
||||||
if (!rules) {
|
// if (!rules) {
|
||||||
response.status(HttpCodes.UNAUTHORIZED).send("Missing rules in JWT");
|
// response.status(HttpCodes.UNAUTHORIZED).send("Missing rules in JWT");
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
const namespace = req.path && req.path.split("/")[3];
|
const namespace = req.path && req.path.split("/")[3];
|
||||||
const role = req.body.user.role;
|
const role = req.body.user.role;
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ enum PROVIDER_OPENID {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface ICustomerJwtPayload {
|
interface ICustomerJwtPayload {
|
||||||
customerId: string;
|
userId: string;
|
||||||
email: string;
|
email: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,7 +45,7 @@ export default class AuthService extends BaseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
customerId: contact.customers!.uid,
|
userId: contact.customers!.uid,
|
||||||
email: contact.email,
|
email: contact.email,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -80,7 +80,6 @@ export default class AuthService extends BaseService {
|
|||||||
rules: rules,
|
rules: rules,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public generateAccessToken(user: any): string {
|
public generateAccessToken(user: any): string {
|
||||||
return jwt.sign({ ...user }, this.variables.ACCESS_TOKEN_SECRET, { expiresIn: "1h" });
|
return jwt.sign({ ...user }, this.variables.ACCESS_TOKEN_SECRET, { expiresIn: "1h" });
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,29 @@
|
|||||||
|
import OfficeFoldersRepository from "@Repositories/OfficeFoldersRepository";
|
||||||
|
import BaseService from "@Services/BaseService";
|
||||||
|
import { Service } from "typedi";
|
||||||
|
import { Prisma } from "@prisma/client";
|
||||||
|
|
||||||
|
@Service()
|
||||||
|
export default class OfficeFoldersService extends BaseService {
|
||||||
|
constructor(
|
||||||
|
private officeFoldersRepository: OfficeFoldersRepository,
|
||||||
|
) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : Get all folders
|
||||||
|
* @throws {Error} If folders cannot be get
|
||||||
|
*/
|
||||||
|
public async get(query: Prisma.OfficeFoldersFindManyArgs) {
|
||||||
|
return this.officeFoldersRepository.findMany(query);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : Get a folder by uid
|
||||||
|
* @throws {Error} If folder cannot be get by uid
|
||||||
|
*/
|
||||||
|
public async getByUid(uid: string, query?: Prisma.OfficeFoldersInclude) {
|
||||||
|
return this.officeFoldersRepository.findOneByUid(uid, query);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user