Merge Staging in Preprod
This commit is contained in:
commit
6aeeb3a1ac
@ -53,7 +53,7 @@
|
|||||||
"express": "^4.18.2",
|
"express": "^4.18.2",
|
||||||
"fp-ts": "^2.16.1",
|
"fp-ts": "^2.16.1",
|
||||||
"jsonwebtoken": "^9.0.0",
|
"jsonwebtoken": "^9.0.0",
|
||||||
"le-coffre-resources": "git@github.com:smart-chain-fr/leCoffre-resources.git#v2.86",
|
"le-coffre-resources": "git@github.com:smart-chain-fr/leCoffre-resources.git#v2.89",
|
||||||
"module-alias": "^2.2.2",
|
"module-alias": "^2.2.2",
|
||||||
"monocle-ts": "^2.3.13",
|
"monocle-ts": "^2.3.13",
|
||||||
"multer": "^1.4.5-lts.1",
|
"multer": "^1.4.5-lts.1",
|
||||||
|
@ -29,8 +29,7 @@ export default class CustomersController extends ApiController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const officeId: string = req.body.user.office_Id;
|
const officeId: string = req.body.user.office_Id;
|
||||||
if(query.where?.office_folders?.some?.office_uid) delete query.where.office_folders.some.office_uid;
|
if(query.where?.office_folders) delete query.where.office_folders;
|
||||||
if(query.where?.office_folders?.some?.office?.uid) delete query.where?.office_folders?.some?.office?.uid;
|
|
||||||
const customerWhereInput: Prisma.CustomersWhereInput = { ...query.where, office_folders: { some: { office_uid: officeId } }};
|
const customerWhereInput: Prisma.CustomersWhereInput = { ...query.where, office_folders: { some: { office_uid: officeId } }};
|
||||||
query.where = customerWhereInput;
|
query.where = customerWhereInput;
|
||||||
|
|
||||||
|
@ -11,6 +11,9 @@ import authHandler from "@App/middlewares/AuthHandler";
|
|||||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||||
import folderHandler from "@App/middlewares/OfficeMembershipHandlers/FolderHandler";
|
import folderHandler from "@App/middlewares/OfficeMembershipHandlers/FolderHandler";
|
||||||
import OfficeFolderAnchor from "le-coffre-resources/dist/Notary/OfficeFolderAnchor";
|
import OfficeFolderAnchor from "le-coffre-resources/dist/Notary/OfficeFolderAnchor";
|
||||||
|
import NotificationBuilder from "@Common/notifications/NotificationBuilder";
|
||||||
|
import { Prisma } from "@prisma/client";
|
||||||
|
import OfficeFolderAnchorsService from "@Services/notary/OfficeFolderAnchorsService/OfficeFolderAnchorsService";
|
||||||
|
|
||||||
const hydrateOfficeFolderAnchor = (data: any): OfficeFolderAnchor =>
|
const hydrateOfficeFolderAnchor = (data: any): OfficeFolderAnchor =>
|
||||||
OfficeFolderAnchor.hydrate<OfficeFolderAnchor>(
|
OfficeFolderAnchor.hydrate<OfficeFolderAnchor>(
|
||||||
@ -33,7 +36,13 @@ const hydrateOfficeFolderAnchor = (data: any): OfficeFolderAnchor =>
|
|||||||
@Controller()
|
@Controller()
|
||||||
@Service()
|
@Service()
|
||||||
export default class OfficeFoldersController extends ApiController {
|
export default class OfficeFoldersController extends ApiController {
|
||||||
constructor(private secureService: SecureService, private officeFolderAnchorsRepository: OfficeFolderAnchorsRepository, private officeFoldersService: OfficeFoldersService) {
|
constructor(
|
||||||
|
private secureService: SecureService,
|
||||||
|
private officeFolderAnchorsRepository: OfficeFolderAnchorsRepository,
|
||||||
|
private officeFolderAnchorsService: OfficeFolderAnchorsService,
|
||||||
|
private officeFoldersService: OfficeFoldersService,
|
||||||
|
private notificationBuilder: NotificationBuilder,
|
||||||
|
) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,7 +85,7 @@ export default class OfficeFoldersController extends ApiController {
|
|||||||
const sortedHashes = [...folderHashes].sort();
|
const sortedHashes = [...folderHashes].sort();
|
||||||
const buffer = await this.secureService.download(sortedHashes);
|
const buffer = await this.secureService.download(sortedHashes);
|
||||||
|
|
||||||
response.setHeader('Content-Type', 'application/pdf');
|
response.setHeader("Content-Type", "application/pdf");
|
||||||
this.httpSuccess(response, buffer);
|
this.httpSuccess(response, buffer);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.httpInternalError(response, error);
|
this.httpInternalError(response, error);
|
||||||
@ -139,9 +148,7 @@ export default class OfficeFoldersController extends ApiController {
|
|||||||
|
|
||||||
const officeFolderAnchor = hydrateOfficeFolderAnchor(data);
|
const officeFolderAnchor = hydrateOfficeFolderAnchor(data);
|
||||||
|
|
||||||
const newOfficeFolderAnchor = await this.officeFolderAnchorsRepository.create(
|
const newOfficeFolderAnchor = await this.officeFolderAnchorsRepository.create(officeFolderAnchor);
|
||||||
officeFolderAnchor
|
|
||||||
);
|
|
||||||
|
|
||||||
await this.officeFoldersService.update(
|
await this.officeFoldersService.update(
|
||||||
uid,
|
uid,
|
||||||
@ -159,7 +166,7 @@ export default class OfficeFoldersController extends ApiController {
|
|||||||
* @description Verify a folder anchor status
|
* @description Verify a folder anchor status
|
||||||
*/
|
*/
|
||||||
@Get("/api/v1/notary/anchors/:uid", [authHandler, ruleHandler, folderHandler])
|
@Get("/api/v1/notary/anchors/:uid", [authHandler, ruleHandler, folderHandler])
|
||||||
protected async get(req: Request, response: Response) {
|
protected async getOneByUid(req: Request, response: Response) {
|
||||||
try {
|
try {
|
||||||
const uid = req.params["uid"];
|
const uid = req.params["uid"];
|
||||||
|
|
||||||
@ -198,14 +205,14 @@ export default class OfficeFoldersController extends ApiController {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!officeFolderAnchorFound || !officeFolderAnchorFound.uid) {
|
if (!officeFolderAnchorFound || !officeFolderAnchorFound.uid) {
|
||||||
this.httpNotFoundRequest(response, {error: "Not anchored", hash_sources: sortedHashes});
|
this.httpNotFoundRequest(response, { error: "Not anchored", hash_sources: sortedHashes });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await this.secureService.verify(sortedHashes);
|
const data = await this.secureService.verify(sortedHashes);
|
||||||
|
|
||||||
if (data.errors || data.transactions.length === 0) {
|
if (data.errors || data.transactions.length === 0) {
|
||||||
this.httpNotFoundRequest(response, {error: "Not anchored", hash_sources: sortedHashes});
|
this.httpNotFoundRequest(response, { error: "Not anchored", hash_sources: sortedHashes });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,9 +220,12 @@ export default class OfficeFoldersController extends ApiController {
|
|||||||
|
|
||||||
const updatedOfficeFolderAnchor = await this.officeFolderAnchorsRepository.update(
|
const updatedOfficeFolderAnchor = await this.officeFolderAnchorsRepository.update(
|
||||||
officeFolderAnchorFound.uid,
|
officeFolderAnchorFound.uid,
|
||||||
officeFolderAnchor
|
officeFolderAnchor,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (officeFolderAnchorFound.status !== "VERIFIED_ON_CHAIN" && officeFolderAnchor.status === "VERIFIED_ON_CHAIN")
|
||||||
|
this.notificationBuilder.sendFolderAnchoredNotification(officeFolderFound);
|
||||||
|
|
||||||
this.httpSuccess(response, updatedOfficeFolderAnchor);
|
this.httpSuccess(response, updatedOfficeFolderAnchor);
|
||||||
return;
|
return;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -223,4 +233,38 @@ export default class OfficeFoldersController extends ApiController {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Get all folders
|
||||||
|
*/
|
||||||
|
@Get("/api/v1/notary/anchors", [authHandler, ruleHandler])
|
||||||
|
protected async get(req: Request, response: Response) {
|
||||||
|
try {
|
||||||
|
//get query
|
||||||
|
let query: Prisma.OfficeFolderAnchorsFindManyArgs = {};
|
||||||
|
if (req.query["q"]) {
|
||||||
|
query = JSON.parse(req.query["q"] as string);
|
||||||
|
}
|
||||||
|
|
||||||
|
query.where = {
|
||||||
|
...query.where,
|
||||||
|
folder: {
|
||||||
|
office_uid: req.body.user.office_Id as string,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
//call service to get prisma entity
|
||||||
|
const officeFolderAnchorsEntities: OfficeFolderAnchor[] = await this.officeFolderAnchorsService.get(query);
|
||||||
|
|
||||||
|
//Hydrate ressource with prisma entity
|
||||||
|
const officeFolderAnchors = OfficeFolderAnchor.hydrateArray<OfficeFolderAnchor>(officeFolderAnchorsEntities, {
|
||||||
|
strategy: "excludeAll",
|
||||||
|
});
|
||||||
|
//success
|
||||||
|
this.httpSuccess(response, officeFolderAnchors);
|
||||||
|
} catch (error) {
|
||||||
|
this.httpInternalError(response, error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,12 +43,10 @@ export default class OfficeFoldersController extends ApiController {
|
|||||||
{
|
{
|
||||||
customers: {
|
customers: {
|
||||||
some: {
|
some: {
|
||||||
contact: {
|
OR: [
|
||||||
OR: [
|
{contact: { first_name: { contains: filter, mode: "insensitive" } }},
|
||||||
{ first_name: { contains: filter, mode: "insensitive" } },
|
{contact: { last_name: { contains: filter, mode: "insensitive" } }},
|
||||||
{ last_name: { contains: filter, mode: "insensitive" } },
|
]
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -57,10 +55,11 @@ export default class OfficeFoldersController extends ApiController {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const officeId: string = req.body.user.office_Id;
|
const userId: string = req.body.user.userId;
|
||||||
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
|
if(query.where?.stakeholders) delete query.where.stakeholders;
|
||||||
if(!query.where) query.where = { office: officeWhereInput};
|
const officeFoldersWhereInput: Prisma.OfficeFoldersWhereInput = { ...query.where, stakeholders: {some: {uid: userId }}};
|
||||||
query.where.office = officeWhereInput;
|
query.where = officeFoldersWhereInput;
|
||||||
|
|
||||||
//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);
|
||||||
|
|
||||||
|
@ -1,77 +0,0 @@
|
|||||||
import { Response, Request } from "express";
|
|
||||||
import { Controller, Get } from "@ControllerPattern/index";
|
|
||||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
|
||||||
import AppointmentsService from "@Services/super-admin/AppointmentsService/AppointmentsService";
|
|
||||||
import { Service } from "typedi";
|
|
||||||
import { Appointment } from "le-coffre-resources/dist/SuperAdmin";
|
|
||||||
import authHandler from "@App/middlewares/AuthHandler";
|
|
||||||
import roleHandler from "@App/middlewares/RolesHandler";
|
|
||||||
|
|
||||||
@Controller()
|
|
||||||
@Service()
|
|
||||||
export default class AppointmentsController extends ApiController {
|
|
||||||
constructor(private appointmentsService: AppointmentsService) {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description Get all appointments
|
|
||||||
*/
|
|
||||||
@Get("/api/v1/super-admin/appointments", [authHandler, roleHandler])
|
|
||||||
protected async get(req: Request, response: Response) {
|
|
||||||
try {
|
|
||||||
//get query
|
|
||||||
let query;
|
|
||||||
if (req.query["q"]) {
|
|
||||||
query = JSON.parse(req.query["q"] as string);
|
|
||||||
}
|
|
||||||
|
|
||||||
//call service to get prisma entity
|
|
||||||
const appointmentsEntities = await this.appointmentsService.get(query);
|
|
||||||
|
|
||||||
//Hydrate ressource with prisma entity
|
|
||||||
const appointments = Appointment.hydrateArray<Appointment>(appointmentsEntities, { strategy: "excludeAll" });
|
|
||||||
|
|
||||||
//success
|
|
||||||
this.httpSuccess(response, appointments);
|
|
||||||
} catch (error) {
|
|
||||||
this.httpInternalError(response, error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description Get a specific appointment by uid
|
|
||||||
*/
|
|
||||||
@Get("/api/v1/super-admin/appointments/:uid", [authHandler, roleHandler])
|
|
||||||
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 appointmentEntity = await this.appointmentsService.getByUid(uid, query);
|
|
||||||
|
|
||||||
if (!appointmentEntity) {
|
|
||||||
this.httpNotFoundRequest(response, "appointment not found");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Hydrate ressource with prisma entity
|
|
||||||
const appointment = Appointment.hydrate<Appointment>(appointmentEntity, { strategy: "excludeAll" });
|
|
||||||
|
|
||||||
//success
|
|
||||||
this.httpSuccess(response, appointment);
|
|
||||||
} catch (error) {
|
|
||||||
this.httpInternalError(response, error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -2,12 +2,10 @@ import authHandler from "@App/middlewares/AuthHandler";
|
|||||||
import roleHandler from "@App/middlewares/RolesHandler";
|
import roleHandler from "@App/middlewares/RolesHandler";
|
||||||
import NotificationBuilder from "@Common/notifications/NotificationBuilder";
|
import NotificationBuilder from "@Common/notifications/NotificationBuilder";
|
||||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||||
import { Controller, Post } from "@ControllerPattern/index";
|
import { Controller, Delete, Post } from "@ControllerPattern/index";
|
||||||
import { EAppointmentStatus } from "@prisma/client";
|
import { EAppointmentStatus, Votes } from "@prisma/client";
|
||||||
import AppointmentService from "@Services/super-admin/AppointmentsService/AppointmentsService";
|
|
||||||
import LiveVoteService from "@Services/super-admin/LiveVoteService/LiveVoteService";
|
import LiveVoteService from "@Services/super-admin/LiveVoteService/LiveVoteService";
|
||||||
import UsersService from "@Services/super-admin/UsersService/UsersService";
|
import UsersService from "@Services/super-admin/UsersService/UsersService";
|
||||||
import VotesService from "@Services/super-admin/VotesService/VotesService";
|
|
||||||
import { validateOrReject } from "class-validator";
|
import { validateOrReject } from "class-validator";
|
||||||
import { Request, Response } from "express";
|
import { Request, Response } from "express";
|
||||||
import { Vote } from "le-coffre-resources/dist/SuperAdmin";
|
import { Vote } from "le-coffre-resources/dist/SuperAdmin";
|
||||||
@ -18,10 +16,8 @@ import { Service } from "typedi";
|
|||||||
export default class LiveVoteController extends ApiController {
|
export default class LiveVoteController extends ApiController {
|
||||||
constructor(
|
constructor(
|
||||||
private liveVoteService: LiveVoteService,
|
private liveVoteService: LiveVoteService,
|
||||||
private votesService: VotesService,
|
|
||||||
private usersService: UsersService,
|
private usersService: UsersService,
|
||||||
private appointmentService: AppointmentService,
|
private notificationBuilder: NotificationBuilder,
|
||||||
private notificationBuilder : NotificationBuilder,
|
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
@ -40,7 +36,7 @@ export default class LiveVoteController extends ApiController {
|
|||||||
|
|
||||||
let voteFound = [];
|
let voteFound = [];
|
||||||
if (voteEntity.appointment.uid) {
|
if (voteEntity.appointment.uid) {
|
||||||
const appointment = await this.appointmentService.getByUid(voteEntity.appointment.uid);
|
const appointment = await this.liveVoteService.getAppointmentByUid(voteEntity.appointment.uid);
|
||||||
if (!appointment) {
|
if (!appointment) {
|
||||||
this.httpNotFoundRequest(response, "Appointment not found");
|
this.httpNotFoundRequest(response, "Appointment not found");
|
||||||
return;
|
return;
|
||||||
@ -49,11 +45,11 @@ export default class LiveVoteController extends ApiController {
|
|||||||
this.httpBadRequest(response, "Appointment is closed");
|
this.httpBadRequest(response, "Appointment is closed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
voteFound = await this.votesService.get({
|
voteFound = await this.liveVoteService.getVotes({
|
||||||
where: { AND: [{ appointment: { uid: voteEntity.appointment.uid } }, { voter: { uid: userId } }] },
|
where: { AND: [{ appointment: { uid: voteEntity.appointment.uid } }, { voter: { uid: userId } }] },
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
voteFound = await this.votesService.get({
|
voteFound = await this.liveVoteService.getVotes({
|
||||||
where: {
|
where: {
|
||||||
AND: [
|
AND: [
|
||||||
{
|
{
|
||||||
@ -96,4 +92,50 @@ export default class LiveVoteController extends ApiController {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Delete a specific vote
|
||||||
|
*/
|
||||||
|
@Delete("/api/v1/super-admin/live-votes/:uid", [authHandler, roleHandler])
|
||||||
|
protected async deleteVote(req: Request, response: Response) {
|
||||||
|
try {
|
||||||
|
const uid = req.params["uid"];
|
||||||
|
if (!uid) {
|
||||||
|
this.httpBadRequest(response, "No uid provided");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const voteFound = await this.liveVoteService.getVoteByUid(uid, {
|
||||||
|
appointment: {
|
||||||
|
include: { votes: true },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!voteFound) {
|
||||||
|
this.httpNotFoundRequest(response, "vote not found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (voteFound.voter_uid !== req.body.user.userId) {
|
||||||
|
this.httpUnauthorized(response, "Can't delete a vote that's not yours");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const vote = Vote.hydrate<Vote>(voteFound, { strategy: "excludeAll" });
|
||||||
|
|
||||||
|
//call service to get prisma entity
|
||||||
|
const voteEntity: Votes = await this.liveVoteService.deleteVote(uid);
|
||||||
|
|
||||||
|
if (vote.appointment.uid && vote.appointment.votes && vote.appointment.votes.length === 1) {
|
||||||
|
await this.liveVoteService.deleteAppointment(vote.appointment.uid);
|
||||||
|
}
|
||||||
|
|
||||||
|
const voteToReturn = Vote.hydrate<Vote>(voteEntity, { strategy: "excludeAll" });
|
||||||
|
//success
|
||||||
|
this.httpSuccess(response, voteToReturn);
|
||||||
|
} catch (error) {
|
||||||
|
this.httpInternalError(response, error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,116 +0,0 @@
|
|||||||
import { Response, Request } from "express";
|
|
||||||
import { Controller, Delete, Get } from "@ControllerPattern/index";
|
|
||||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
|
||||||
import VotesService from "@Services/super-admin/VotesService/VotesService";
|
|
||||||
import { Service } from "typedi";
|
|
||||||
import { Vote } from "le-coffre-resources/dist/SuperAdmin";
|
|
||||||
import authHandler from "@App/middlewares/AuthHandler";
|
|
||||||
import { Votes } from "@prisma/client";
|
|
||||||
import roleHandler from "@App/middlewares/RolesHandler";
|
|
||||||
|
|
||||||
@Controller()
|
|
||||||
@Service()
|
|
||||||
export default class VotesController extends ApiController {
|
|
||||||
constructor(private votesService: VotesService) {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description Get all votes
|
|
||||||
*/
|
|
||||||
@Get("/api/v1/super-admin/votes", [authHandler, roleHandler])
|
|
||||||
protected async get(req: Request, response: Response) {
|
|
||||||
try {
|
|
||||||
//get query
|
|
||||||
let query;
|
|
||||||
if (req.query["q"]) {
|
|
||||||
query = JSON.parse(req.query["q"] as string);
|
|
||||||
}
|
|
||||||
|
|
||||||
//call service to get prisma entity
|
|
||||||
const votesEntities = await this.votesService.get(query);
|
|
||||||
|
|
||||||
//Hydrate ressource with prisma entity
|
|
||||||
const votes = Vote.hydrateArray<Vote>(votesEntities, { strategy: "excludeAll" });
|
|
||||||
|
|
||||||
//success
|
|
||||||
this.httpSuccess(response, votes);
|
|
||||||
} catch (error) {
|
|
||||||
this.httpInternalError(response, error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description Get a specific vote by uid
|
|
||||||
*/
|
|
||||||
@Get("/api/v1/super-admin/votes/:uid", [authHandler, roleHandler])
|
|
||||||
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 voteEntity = await this.votesService.getByUid(uid, query);
|
|
||||||
|
|
||||||
if (!voteEntity) {
|
|
||||||
this.httpNotFoundRequest(response, "vote not found");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Hydrate ressource with prisma entity
|
|
||||||
const vote = Vote.hydrate<Vote>(voteEntity, { strategy: "excludeAll" });
|
|
||||||
|
|
||||||
//success
|
|
||||||
this.httpSuccess(response, vote);
|
|
||||||
} catch (error) {
|
|
||||||
this.httpInternalError(response, error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description Delete a specific vote
|
|
||||||
*/
|
|
||||||
@Delete("/api/v1/super-admin/votes/:uid", [authHandler, roleHandler])
|
|
||||||
protected async delete(req: Request, response: Response) {
|
|
||||||
try {
|
|
||||||
const uid = req.params["uid"];
|
|
||||||
if (!uid) {
|
|
||||||
this.httpBadRequest(response, "No uid provided");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const voteFound = await this.votesService.getByUid(uid);
|
|
||||||
|
|
||||||
if (!voteFound) {
|
|
||||||
this.httpNotFoundRequest(response, "vote not found");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (voteFound.voter_uid !== req.body.user.userId) {
|
|
||||||
this.httpUnauthorized(response, "Can't delete a vote that's not yours");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//call service to get prisma entity
|
|
||||||
const votetEntity: Votes = await this.votesService.delete(uid);
|
|
||||||
|
|
||||||
//Hydrate ressource with prisma entity
|
|
||||||
const vote = Vote.hydrate<Vote>(votetEntity, { strategy: "excludeAll" });
|
|
||||||
|
|
||||||
//success
|
|
||||||
this.httpSuccess(response, vote);
|
|
||||||
} catch (error) {
|
|
||||||
this.httpInternalError(response, error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -42,8 +42,6 @@ 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 OfficeFoldersController from "./api/customer/OfficeFoldersController";
|
||||||
import OfficeFolderAnchorsController from "./api/notary/OfficeFolderAnchorsController";
|
import OfficeFolderAnchorsController from "./api/notary/OfficeFolderAnchorsController";
|
||||||
import AppointmentsController from "./api/super-admin/AppointmentsController";
|
|
||||||
import VotesController from "./api/super-admin/VotesController";
|
|
||||||
import LiveVoteController from "./api/super-admin/LiveVoteController";
|
import LiveVoteController from "./api/super-admin/LiveVoteController";
|
||||||
import DocumentControllerId360 from "./api/id360/DocumentController";
|
import DocumentControllerId360 from "./api/id360/DocumentController";
|
||||||
import CustomerControllerId360 from "./api/id360/CustomerController";
|
import CustomerControllerId360 from "./api/id360/CustomerController";
|
||||||
@ -54,7 +52,6 @@ import UserNotificationController from "./api/notary/UserNotificationController"
|
|||||||
* @description This allow to declare all controllers used in the application
|
* @description This allow to declare all controllers used in the application
|
||||||
*/
|
*/
|
||||||
export default {
|
export default {
|
||||||
|
|
||||||
start: () => {
|
start: () => {
|
||||||
Container.get(HomeController);
|
Container.get(HomeController);
|
||||||
Container.get(UsersControllerSuperAdmin);
|
Container.get(UsersControllerSuperAdmin);
|
||||||
@ -65,8 +62,6 @@ export default {
|
|||||||
Container.get(DeedTypesControllerSuperAdmin);
|
Container.get(DeedTypesControllerSuperAdmin);
|
||||||
Container.get(DocumentsControllerSuperAdmin);
|
Container.get(DocumentsControllerSuperAdmin);
|
||||||
Container.get(DocumentTypesControllerSuperAdmin);
|
Container.get(DocumentTypesControllerSuperAdmin);
|
||||||
Container.get(AppointmentsController);
|
|
||||||
Container.get(VotesController);
|
|
||||||
Container.get(LiveVoteController);
|
Container.get(LiveVoteController);
|
||||||
Container.get(IdNotUserController);
|
Container.get(IdNotUserController);
|
||||||
Container.get(FranceConnectCustomerController);
|
Container.get(FranceConnectCustomerController);
|
||||||
|
@ -49,10 +49,18 @@ export default async function documentHandler(req: Request, response: Response,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (document.folder.office.uid != officeId) {
|
const officeFolderService = Container.get(OfficeFoldersService);
|
||||||
|
const folder = await officeFolderService.getByUidWithStakeholders(document?.folder_uid!);
|
||||||
|
|
||||||
|
if (document.folder.office_uid != officeId) {
|
||||||
response.sendStatus(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
|
response.sendStatus(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!folder?.stakeholders.find(stakeholder => stakeholder.uid === req.body.user.userId)) {
|
||||||
|
response.sendStatus(HttpCodes.UNAUTHORIZED).send("Unauthorized with this user");
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
next();
|
next();
|
||||||
|
@ -7,11 +7,12 @@ import DeedTypesService from "@Services/super-admin/DeedTypesService/DeedTypesSe
|
|||||||
export default async function folderHandler(req: Request, response: Response, next: NextFunction) {
|
export default async function folderHandler(req: Request, response: Response, next: NextFunction) {
|
||||||
try {
|
try {
|
||||||
const officeId = req.body.user.office_Id;
|
const officeId = req.body.user.office_Id;
|
||||||
const uid = req.path && req.path.split("/")[-1];
|
const userId = req.body.user.userId;
|
||||||
|
let uid = req.path && req.path.split("/")[5];
|
||||||
const office = req.body.office;
|
const office = req.body.office;
|
||||||
const officeFolderNumber = req.body.folder_number;
|
const officeFolderNumber = req.body.folder_number;
|
||||||
const deed = req.body.deed;
|
const deed = req.body.deed;
|
||||||
|
|
||||||
if (office && office.uid != officeId) {
|
if (office && office.uid != officeId) {
|
||||||
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
|
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
|
||||||
return;
|
return;
|
||||||
@ -43,17 +44,25 @@ export default async function folderHandler(req: Request, response: Response, ne
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (uid) {
|
if (uid) {
|
||||||
const officeFolder = await officeFolderService.getByUidWithOffice(uid!);
|
if(uid === "download") {
|
||||||
|
uid = req.path && req.path.split("/")[6];
|
||||||
|
}
|
||||||
|
const officeFolder = await officeFolderService.getByUidWithStakeholders(uid!);
|
||||||
|
|
||||||
if (!officeFolder) {
|
if (!officeFolder) {
|
||||||
response.status(HttpCodes.NOT_FOUND).send("Office folder 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.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
|
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!officeFolder.stakeholders.find(stakeholder => stakeholder.uid === userId)) {
|
||||||
|
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this user");
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
next();
|
next();
|
||||||
|
@ -243,8 +243,8 @@ export default async function main() {
|
|||||||
{
|
{
|
||||||
address: addresses[6],
|
address: addresses[6],
|
||||||
first_name: "Jean",
|
first_name: "Jean",
|
||||||
last_name: "Dubigot",
|
last_name: "Dubignot",
|
||||||
email: "jean.dubigot@gmail.com",
|
email: "jean.dubignot@gmail.com",
|
||||||
phone_number: "06 78 90 12 34",
|
phone_number: "06 78 90 12 34",
|
||||||
cell_phone_number: "06 78 90 12 34",
|
cell_phone_number: "06 78 90 12 34",
|
||||||
birthdate: null,
|
birthdate: null,
|
||||||
@ -664,10 +664,10 @@ export default async function main() {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "DELETE documents",
|
name: "DELETE documents",
|
||||||
label: "Supprimer un document",
|
label: "Supprimer un document demandé",
|
||||||
created_at: new Date(),
|
created_at: new Date(),
|
||||||
updated_at: new Date(),
|
updated_at: new Date(),
|
||||||
namespace: "super-admin",
|
namespace: "notary",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "POST customers",
|
name: "POST customers",
|
||||||
@ -1540,6 +1540,15 @@ export default async function main() {
|
|||||||
created_at: new Date(),
|
created_at: new Date(),
|
||||||
updated_at: new Date(),
|
updated_at: new Date(),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "Autres documents",
|
||||||
|
archived_at: null,
|
||||||
|
public_description: "Autres documents",
|
||||||
|
private_description: "Autres documents",
|
||||||
|
office: offices[0],
|
||||||
|
created_at: new Date(),
|
||||||
|
updated_at: new Date(),
|
||||||
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
const deedTypes: DeedType[] = [
|
const deedTypes: DeedType[] = [
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
import DocumentsService from "@Services/super-admin/DocumentsService/DocumentsService";
|
import DocumentsService from "@Services/super-admin/DocumentsService/DocumentsService";
|
||||||
import { Documents } from "@prisma/client";
|
import { Documents } from "@prisma/client";
|
||||||
import { Document } from "le-coffre-resources/dist/SuperAdmin";
|
import User, { Document } from "le-coffre-resources/dist/SuperAdmin";
|
||||||
import { Service } from "typedi";
|
import { Service } from "typedi";
|
||||||
import { ETemplates } from "./Templates/EmailTemplates";
|
import { ETemplates } from "./Templates/EmailTemplates";
|
||||||
import MailchimpService from "@Services/common/MailchimpService/MailchimpService";
|
import MailchimpService from "@Services/common/MailchimpService/MailchimpService";
|
||||||
@ -48,14 +48,14 @@ export default class EmailBuilder {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async sendRecapEmails(usersToEmail: [{email: string, civility: string, last_name: string}]){
|
public async sendRecapEmails(usersToEmail: User[]){
|
||||||
usersToEmail.forEach(user => {
|
usersToEmail.forEach(user => {
|
||||||
const to = user.email;
|
const to = user.contact!.email;
|
||||||
const civility = this.getCivility(user.civility);
|
const civility = this.getCivility(user.contact!.civility);
|
||||||
|
|
||||||
const templateVariables = {
|
const templateVariables = {
|
||||||
civility: civility,
|
civility: civility,
|
||||||
last_name: user.last_name,
|
last_name: user.contact!.last_name,
|
||||||
link: this.variables.APP_HOST
|
link: this.variables.APP_HOST
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -65,4 +65,24 @@ export default class OfficeFolderAnchorsRepository extends BaseRepository {
|
|||||||
...updateArgs,
|
...updateArgs,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : Find one office folder
|
||||||
|
*/
|
||||||
|
public async findOneByUid(uid: string, query?: Prisma.OfficeFolderAnchorsInclude) {
|
||||||
|
return this.model.findUnique({
|
||||||
|
where: {
|
||||||
|
uid: uid,
|
||||||
|
},
|
||||||
|
include: query,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : Find many office folders
|
||||||
|
*/
|
||||||
|
public async findMany(query: Prisma.OfficeFolderAnchorsFindManyArgs) {
|
||||||
|
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
|
||||||
|
return this.model.findMany(query);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -137,6 +137,18 @@ export default class OfficeFoldersRepository extends BaseRepository {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : Find one office folder
|
||||||
|
*/
|
||||||
|
public async findOneByUidWithStakeholders(uid: string) {
|
||||||
|
return this.model.findUnique({
|
||||||
|
where: {
|
||||||
|
uid: uid,
|
||||||
|
},
|
||||||
|
include: { stakeholders: true },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description : Delete a folder
|
* @description : Delete a folder
|
||||||
*/
|
*/
|
||||||
|
@ -24,7 +24,7 @@ const storage = multer.memoryStorage();
|
|||||||
rootUrl,
|
rootUrl,
|
||||||
middlwares: [
|
middlwares: [
|
||||||
cors({ origin: "*" }),
|
cors({ origin: "*" }),
|
||||||
multer({ storage: storage }).single("file"),
|
multer({ storage: storage, limits: { fileSize: 32000000 } }).single("file"), //32 MB maximum
|
||||||
bodyParser.urlencoded({ extended: true }),
|
bodyParser.urlencoded({ extended: true }),
|
||||||
bodyParser.json(),
|
bodyParser.json(),
|
||||||
],
|
],
|
||||||
|
@ -80,7 +80,7 @@ export default class CronService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async checkDocumentsExpiration() {
|
public async checkDocumentsExpiration() {
|
||||||
const cronJob = new CronJob("*/10 * * * * *", async () => {
|
const cronJob = new CronJob("0 20 * * *", async () => {
|
||||||
// Once a day at midnight
|
// Once a day at midnight
|
||||||
try {
|
try {
|
||||||
const prisma = new PrismaClient();
|
const prisma = new PrismaClient();
|
||||||
|
@ -1,17 +1,22 @@
|
|||||||
import EmailRepository from "@Repositories/EmailRepository";
|
import EmailRepository from "@Repositories/EmailRepository";
|
||||||
import BaseService from "@Services/BaseService";
|
import BaseService from "@Services/BaseService";
|
||||||
import { Emails, PrismaClient } from "@prisma/client";
|
import { Emails } from "@prisma/client";
|
||||||
import { Service } from "typedi";
|
import { Service } from "typedi";
|
||||||
import MailchimpClient from "@mailchimp/mailchimp_transactional";
|
import MailchimpClient from "@mailchimp/mailchimp_transactional";
|
||||||
import { BackendVariables } from "@Common/config/variables/Variables";
|
import { BackendVariables } from "@Common/config/variables/Variables";
|
||||||
|
import UsersService from "@Services/super-admin/UsersService/UsersService";
|
||||||
import EmailBuilder from "@Common/emails/EmailBuilder";
|
import EmailBuilder from "@Common/emails/EmailBuilder";
|
||||||
// import DocumentsService from "@Services/super-admin/DocumentsService/DocumentsService";
|
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class MailchimpService extends BaseService {
|
export default class MailchimpService extends BaseService {
|
||||||
private static readonly from = "vincent.alamelle@smart-chain.fr";
|
private static readonly from = "vincent.alamelle@smart-chain.fr";
|
||||||
|
|
||||||
constructor(private emailRepository: EmailRepository, protected variables: BackendVariables, private emailBuilder: EmailBuilder) {
|
constructor(
|
||||||
|
private emailRepository: EmailRepository,
|
||||||
|
protected variables: BackendVariables,
|
||||||
|
private usersService: UsersService,
|
||||||
|
private emailBuilder: EmailBuilder,
|
||||||
|
) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,7 +57,7 @@ export default class MailchimpService extends BaseService {
|
|||||||
* @description : Function called by cron to send emails
|
* @description : Function called by cron to send emails
|
||||||
* @throws {Error} If email cannot be sent
|
* @throws {Error} If email cannot be sent
|
||||||
*/
|
*/
|
||||||
public async sendEmails() {
|
public async sendEmails() {
|
||||||
const emailsToSend = await this.get({ where: { sentAt: null } });
|
const emailsToSend = await this.get({ where: { sentAt: null } });
|
||||||
const currentDate = new Date();
|
const currentDate = new Date();
|
||||||
let nextTrySendDate = null;
|
let nextTrySendDate = null;
|
||||||
@ -85,8 +90,8 @@ export default class MailchimpService extends BaseService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async sendEmail(email: Emails) {
|
private async sendEmail(email: Emails) {
|
||||||
const apiKey = this.variables.MAILCHIMP_API_KEY;
|
const apiKey = this.variables.MAILCHIMP_API_KEY;
|
||||||
const mailchimpApiClient = MailchimpClient(apiKey!);
|
const mailchimpApiClient = MailchimpClient(apiKey!);
|
||||||
|
|
||||||
await mailchimpApiClient.messages.sendTemplate({
|
await mailchimpApiClient.messages.sendTemplate({
|
||||||
@ -117,15 +122,8 @@ export default class MailchimpService extends BaseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async sendRecapEmails() {
|
public async sendRecapEmails() {
|
||||||
const prisma = new PrismaClient();
|
const usersToEmail = await this.usersService.get({ where: { office_folders: { some:{ documents: { some: { document_status: "DEPOSITED" } } }} }, distinct: ["uid"], include: { contact: true } });
|
||||||
const usersToEmail: [{email: string, civility: string, last_name: string}] = await prisma.$queryRaw
|
|
||||||
`SELECT DISTINCT c.email, c.civility, c.last_name
|
|
||||||
FROM Contacts c
|
|
||||||
JOIN Users u ON c.uid = u.contact_uid
|
|
||||||
JOIN office_folders of ON u.office_uid = of.office_uid
|
|
||||||
JOIN Documents d ON of.uid = d.folder_uid
|
|
||||||
WHERE d.document_status = 'DEPOSITED';`
|
|
||||||
|
|
||||||
await this.emailBuilder.sendRecapEmails(usersToEmail);
|
await this.emailBuilder.sendRecapEmails(usersToEmail);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ export default class DocumentsService extends BaseService {
|
|||||||
if (!documentEntity) throw new Error("document not found");
|
if (!documentEntity) throw new Error("document not found");
|
||||||
const document = Document.hydrate<Document>(documentEntity, { strategy: "excludeAll" });
|
const document = Document.hydrate<Document>(documentEntity, { strategy: "excludeAll" });
|
||||||
|
|
||||||
if (document.files && document.files.length !== 0) {
|
if (document.files && document.files.length !== 0 && document.document_status !== "REFUSED") {
|
||||||
throw new Error("Can't delete a document with file");
|
throw new Error("Can't delete a document with file");
|
||||||
}
|
}
|
||||||
return this.documentsRepository.delete(uid);
|
return this.documentsRepository.delete(uid);
|
||||||
|
@ -0,0 +1,27 @@
|
|||||||
|
import BaseService from "@Services/BaseService";
|
||||||
|
import { Service } from "typedi";
|
||||||
|
import { Prisma } from "@prisma/client";
|
||||||
|
import OfficeFolderAnchorsRepository from "@Repositories/OfficeFolderAnchorsRepository";
|
||||||
|
|
||||||
|
@Service()
|
||||||
|
export default class OfficeFolderAnchorsService extends BaseService {
|
||||||
|
constructor(private officeFolderAnchorsRepository: OfficeFolderAnchorsRepository) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : Get all folders
|
||||||
|
* @throws {Error} If folders cannot be get
|
||||||
|
*/
|
||||||
|
public async get(query: Prisma.OfficeFolderAnchorsFindManyArgs) {
|
||||||
|
return this.officeFolderAnchorsRepository.findMany(query);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : Get a folder by uid
|
||||||
|
* @throws {Error} If folder cannot be get by uid
|
||||||
|
*/
|
||||||
|
public async getByUid(uid: string, query?: Prisma.OfficeFolderAnchorsInclude) {
|
||||||
|
return this.officeFolderAnchorsRepository.findOneByUid(uid, query);
|
||||||
|
}
|
||||||
|
}
|
@ -1,53 +0,0 @@
|
|||||||
import BaseService from "@Services/BaseService";
|
|
||||||
import { Service } from "typedi";
|
|
||||||
import AppointmentsRepository from "@Repositories/AppointmentsRepository";
|
|
||||||
import { Prisma, Appointments, EAppointmentStatus } from "@prisma/client";
|
|
||||||
|
|
||||||
@Service()
|
|
||||||
export default class AppointmentService extends BaseService {
|
|
||||||
constructor(private appointmentRepository: AppointmentsRepository) {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description : Get all appointments
|
|
||||||
* @throws {Error} If appointments cannot be get
|
|
||||||
*/
|
|
||||||
public get(query: Prisma.AppointmentsFindManyArgs) {
|
|
||||||
return this.appointmentRepository.findMany(query);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description : Modify a appointment
|
|
||||||
* @throws {Error} If appointment cannot be modified
|
|
||||||
*/
|
|
||||||
public async update(uid: string, status: EAppointmentStatus): Promise<Appointments> {
|
|
||||||
return this.appointmentRepository.update(uid, status);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description : Get a appointment by uid
|
|
||||||
* @throws {Error} If appointment cannot be get by uid
|
|
||||||
*/
|
|
||||||
public getByUid(uid: string, query?: Prisma.AppointmentsInclude): Promise<Appointments | null> {
|
|
||||||
return this.appointmentRepository.findOneByUid(uid, query);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description : Get a appointment by uid
|
|
||||||
* @throws {Error} If appointment cannot be get by uid
|
|
||||||
*/
|
|
||||||
public getByUidWithVotes(uid: string) {
|
|
||||||
return this.appointmentRepository.findOneByUidWithVotes(uid);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description : delete a appointment by uid
|
|
||||||
* @throws {Error} If appointment cannot be get by uid
|
|
||||||
*/
|
|
||||||
public delete(uid: string) {
|
|
||||||
return this.appointmentRepository.delete(uid);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -2,16 +2,16 @@ import BaseService from "@Services/BaseService";
|
|||||||
import { Service } from "typedi";
|
import { Service } from "typedi";
|
||||||
import User, { Appointment, Role, Vote } from "le-coffre-resources/dist/SuperAdmin";
|
import User, { Appointment, Role, Vote } from "le-coffre-resources/dist/SuperAdmin";
|
||||||
import VotesRepository from "@Repositories/VotesRepository";
|
import VotesRepository from "@Repositories/VotesRepository";
|
||||||
import { Appointments, EAppointmentStatus, EVote, Votes } from "@prisma/client";
|
import { Appointments, EAppointmentStatus, EVote, Prisma, Votes } from "@prisma/client";
|
||||||
import AppointmentService from "../AppointmentsService/AppointmentsService";
|
|
||||||
import UsersService from "../UsersService/UsersService";
|
import UsersService from "../UsersService/UsersService";
|
||||||
import RolesService from "../RolesService/RolesService";
|
import RolesService from "../RolesService/RolesService";
|
||||||
|
import AppointmentsRepository from "@Repositories/AppointmentsRepository";
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class LiveVoteService extends BaseService {
|
export default class LiveVoteService extends BaseService {
|
||||||
constructor(
|
constructor(
|
||||||
private voteRepository: VotesRepository,
|
private voteRepository: VotesRepository,
|
||||||
private appointmentService: AppointmentService,
|
private appointmentRepository: AppointmentsRepository,
|
||||||
private userService: UsersService,
|
private userService: UsersService,
|
||||||
private roleService: RolesService,
|
private roleService: RolesService,
|
||||||
) {
|
) {
|
||||||
@ -29,11 +29,47 @@ export default class LiveVoteService extends BaseService {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getVotes(query: Prisma.VotesFindManyArgs) {
|
||||||
|
return this.voteRepository.findMany(query);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : Get a vote by uid
|
||||||
|
* @throws {Error} If vote cannot be get by uid
|
||||||
|
*/
|
||||||
|
public getVoteByUid(uid: string, query?: Prisma.VotesInclude) {
|
||||||
|
return this.voteRepository.findOneByUid(uid, query);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : delete a vote by uid
|
||||||
|
* @throws {Error} If vote cannot be get by uid
|
||||||
|
*/
|
||||||
|
public deleteVote(uid: string) {
|
||||||
|
return this.voteRepository.delete(uid);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : delete an appointment by uid
|
||||||
|
* @throws {Error} If appointment cannot be get by uid
|
||||||
|
*/
|
||||||
|
public deleteAppointment(uid: string) {
|
||||||
|
return this.appointmentRepository.delete(uid);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : Get a appointment by uid
|
||||||
|
* @throws {Error} If appointment cannot be get by uid
|
||||||
|
*/
|
||||||
|
public getAppointmentByUid(uid: string, query?: Prisma.AppointmentsInclude): Promise<Appointments | null> {
|
||||||
|
return this.appointmentRepository.findOneByUid(uid, query);
|
||||||
|
}
|
||||||
|
|
||||||
public async getAppointmentWithVotes(vote: Vote): Promise<Appointments | null> {
|
public async getAppointmentWithVotes(vote: Vote): Promise<Appointments | null> {
|
||||||
if (vote.appointment.uid) {
|
if (vote.appointment.uid) {
|
||||||
return this.appointmentService.getByUidWithVotes(vote.appointment.uid);
|
return this.appointmentRepository.findOneByUid(vote.appointment.uid);
|
||||||
}
|
}
|
||||||
const appointmentByUser = await this.appointmentService.get({
|
const appointmentByUser = await this.appointmentRepository.findMany({
|
||||||
where: {
|
where: {
|
||||||
AND: [
|
AND: [
|
||||||
{ user_uid: vote.appointment.targeted_user.uid },
|
{ user_uid: vote.appointment.targeted_user.uid },
|
||||||
@ -44,13 +80,13 @@ export default class LiveVoteService extends BaseService {
|
|||||||
include: { votes: true },
|
include: { votes: true },
|
||||||
});
|
});
|
||||||
if (appointmentByUser.length >= 1) {
|
if (appointmentByUser.length >= 1) {
|
||||||
return this.appointmentService.getByUidWithVotes(appointmentByUser[0]!.uid);
|
return this.appointmentRepository.findOneByUidWithVotes(appointmentByUser[0]!.uid);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async closeVote(appointment: Appointments, vote: Votes) {
|
private async closeVote(appointment: Appointments, vote: Votes) {
|
||||||
await this.appointmentService.update(vote.appointment_uid, EAppointmentStatus.CLOSED);
|
await this.appointmentRepository.update(vote.appointment_uid, EAppointmentStatus.CLOSED);
|
||||||
const user = await this.userService.getByUid(appointment.user_uid, { role: true });
|
const user = await this.userService.getByUid(appointment.user_uid, { role: true });
|
||||||
const userEntity = User.hydrate<User>(user!, { strategy: "excludeAll" });
|
const userEntity = User.hydrate<User>(user!, { strategy: "excludeAll" });
|
||||||
|
|
||||||
@ -90,7 +126,7 @@ export default class LiveVoteService extends BaseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const approvedChoice = await this.verifyVoterChoice(vote);
|
const approvedChoice = await this.verifyVoterChoice(vote);
|
||||||
if(!approvedChoice) return null;
|
if (!approvedChoice) return null;
|
||||||
|
|
||||||
return this.voteRepository.create(vote);
|
return this.voteRepository.create(vote);
|
||||||
}
|
}
|
||||||
|
@ -62,6 +62,14 @@ export default class OfficeFoldersService extends BaseService {
|
|||||||
return this.officeFoldersRepository.findOneByUidWithOffice(uid);
|
return this.officeFoldersRepository.findOneByUidWithOffice(uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : Get a folder by uid
|
||||||
|
* @throws {Error} If folder cannot be get by uid
|
||||||
|
*/
|
||||||
|
public async getByUidWithStakeholders(uid: string) {
|
||||||
|
return this.officeFoldersRepository.findOneByUidWithStakeholders(uid);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description : Delete a folder
|
* @description : Delete a folder
|
||||||
* @throws {Error} If document cannot be deleted
|
* @throws {Error} If document cannot be deleted
|
||||||
|
@ -1,35 +0,0 @@
|
|||||||
import BaseService from "@Services/BaseService";
|
|
||||||
import { Service } from "typedi";
|
|
||||||
import VotesRepository from "@Repositories/VotesRepository";
|
|
||||||
import { Prisma } from "@prisma/client";
|
|
||||||
|
|
||||||
@Service()
|
|
||||||
export default class VoteService extends BaseService {
|
|
||||||
constructor(private voteRepository: VotesRepository) {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description : Get all votes
|
|
||||||
* @throws {Error} If votes cannot be get
|
|
||||||
*/
|
|
||||||
public get(query: Prisma.VotesFindManyArgs) {
|
|
||||||
return this.voteRepository.findMany(query);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description : Get a vote by uid
|
|
||||||
* @throws {Error} If vote cannot be get by uid
|
|
||||||
*/
|
|
||||||
public getByUid(uid: string, query?: Prisma.VotesInclude) {
|
|
||||||
return this.voteRepository.findOneByUid(uid, query);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description : delete a vote by uid
|
|
||||||
* @throws {Error} If vote cannot be get by uid
|
|
||||||
*/
|
|
||||||
public delete(uid: string) {
|
|
||||||
return this.voteRepository.delete(uid);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user