Merge Staging in Preprod

This commit is contained in:
Arnaud D. Natali 2023-10-03 18:10:24 +02:00 committed by GitHub
commit 6aeeb3a1ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 283 additions and 358 deletions

View File

@ -53,7 +53,7 @@
"express": "^4.18.2",
"fp-ts": "^2.16.1",
"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",
"monocle-ts": "^2.3.13",
"multer": "^1.4.5-lts.1",

View File

@ -29,8 +29,7 @@ export default class CustomersController extends ApiController {
}
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?.some?.office?.uid) delete query.where?.office_folders?.some?.office?.uid;
if(query.where?.office_folders) delete query.where.office_folders;
const customerWhereInput: Prisma.CustomersWhereInput = { ...query.where, office_folders: { some: { office_uid: officeId } }};
query.where = customerWhereInput;

View File

@ -11,6 +11,9 @@ import authHandler from "@App/middlewares/AuthHandler";
import ruleHandler from "@App/middlewares/RulesHandler";
import folderHandler from "@App/middlewares/OfficeMembershipHandlers/FolderHandler";
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 =>
OfficeFolderAnchor.hydrate<OfficeFolderAnchor>(
@ -33,7 +36,13 @@ const hydrateOfficeFolderAnchor = (data: any): OfficeFolderAnchor =>
@Controller()
@Service()
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();
}
@ -76,7 +85,7 @@ export default class OfficeFoldersController extends ApiController {
const sortedHashes = [...folderHashes].sort();
const buffer = await this.secureService.download(sortedHashes);
response.setHeader('Content-Type', 'application/pdf');
response.setHeader("Content-Type", "application/pdf");
this.httpSuccess(response, buffer);
} catch (error) {
this.httpInternalError(response, error);
@ -139,9 +148,7 @@ export default class OfficeFoldersController extends ApiController {
const officeFolderAnchor = hydrateOfficeFolderAnchor(data);
const newOfficeFolderAnchor = await this.officeFolderAnchorsRepository.create(
officeFolderAnchor
);
const newOfficeFolderAnchor = await this.officeFolderAnchorsRepository.create(officeFolderAnchor);
await this.officeFoldersService.update(
uid,
@ -159,7 +166,7 @@ export default class OfficeFoldersController extends ApiController {
* @description Verify a folder anchor status
*/
@Get("/api/v1/notary/anchors/:uid", [authHandler, ruleHandler, folderHandler])
protected async get(req: Request, response: Response) {
protected async getOneByUid(req: Request, response: Response) {
try {
const uid = req.params["uid"];
@ -213,9 +220,12 @@ export default class OfficeFoldersController extends ApiController {
const updatedOfficeFolderAnchor = await this.officeFolderAnchorsRepository.update(
officeFolderAnchorFound.uid,
officeFolderAnchor
officeFolderAnchor,
);
if (officeFolderAnchorFound.status !== "VERIFIED_ON_CHAIN" && officeFolderAnchor.status === "VERIFIED_ON_CHAIN")
this.notificationBuilder.sendFolderAnchoredNotification(officeFolderFound);
this.httpSuccess(response, updatedOfficeFolderAnchor);
return;
} catch (error) {
@ -223,4 +233,38 @@ export default class OfficeFoldersController extends ApiController {
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;
}
}
}

View File

@ -43,12 +43,10 @@ export default class OfficeFoldersController extends ApiController {
{
customers: {
some: {
contact: {
OR: [
{ first_name: { contains: filter, mode: "insensitive" } },
{ last_name: { contains: filter, mode: "insensitive" } },
],
},
{contact: { first_name: { contains: filter, mode: "insensitive" } }},
{contact: { 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 officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
if(!query.where) query.where = { office: officeWhereInput};
query.where.office = officeWhereInput;
const userId: string = req.body.user.userId;
if(query.where?.stakeholders) delete query.where.stakeholders;
const officeFoldersWhereInput: Prisma.OfficeFoldersWhereInput = { ...query.where, stakeholders: {some: {uid: userId }}};
query.where = officeFoldersWhereInput;
//call service to get prisma entity
const officeFolderEntities: OfficeFolders[] = await this.officeFoldersService.get(query);

View File

@ -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;
}
}
}

View File

@ -2,12 +2,10 @@ import authHandler from "@App/middlewares/AuthHandler";
import roleHandler from "@App/middlewares/RolesHandler";
import NotificationBuilder from "@Common/notifications/NotificationBuilder";
import ApiController from "@Common/system/controller-pattern/ApiController";
import { Controller, Post } from "@ControllerPattern/index";
import { EAppointmentStatus } from "@prisma/client";
import AppointmentService from "@Services/super-admin/AppointmentsService/AppointmentsService";
import { Controller, Delete, Post } from "@ControllerPattern/index";
import { EAppointmentStatus, Votes } from "@prisma/client";
import LiveVoteService from "@Services/super-admin/LiveVoteService/LiveVoteService";
import UsersService from "@Services/super-admin/UsersService/UsersService";
import VotesService from "@Services/super-admin/VotesService/VotesService";
import { validateOrReject } from "class-validator";
import { Request, Response } from "express";
import { Vote } from "le-coffre-resources/dist/SuperAdmin";
@ -18,9 +16,7 @@ import { Service } from "typedi";
export default class LiveVoteController extends ApiController {
constructor(
private liveVoteService: LiveVoteService,
private votesService: VotesService,
private usersService: UsersService,
private appointmentService: AppointmentService,
private notificationBuilder: NotificationBuilder,
) {
super();
@ -40,7 +36,7 @@ export default class LiveVoteController extends ApiController {
let voteFound = [];
if (voteEntity.appointment.uid) {
const appointment = await this.appointmentService.getByUid(voteEntity.appointment.uid);
const appointment = await this.liveVoteService.getAppointmentByUid(voteEntity.appointment.uid);
if (!appointment) {
this.httpNotFoundRequest(response, "Appointment not found");
return;
@ -49,11 +45,11 @@ export default class LiveVoteController extends ApiController {
this.httpBadRequest(response, "Appointment is closed");
return;
}
voteFound = await this.votesService.get({
voteFound = await this.liveVoteService.getVotes({
where: { AND: [{ appointment: { uid: voteEntity.appointment.uid } }, { voter: { uid: userId } }] },
});
} else {
voteFound = await this.votesService.get({
voteFound = await this.liveVoteService.getVotes({
where: {
AND: [
{
@ -96,4 +92,50 @@ export default class LiveVoteController extends ApiController {
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;
}
}
}

View File

@ -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;
}
}
}

View File

@ -42,8 +42,6 @@ import FilesControllerCustomer from "./api/customer/FilesController";
import DocumentsControllerCustomer from "./api/customer/DocumentsController";
import OfficeFoldersController from "./api/customer/OfficeFoldersController";
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 DocumentControllerId360 from "./api/id360/DocumentController";
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
*/
export default {
start: () => {
Container.get(HomeController);
Container.get(UsersControllerSuperAdmin);
@ -65,8 +62,6 @@ export default {
Container.get(DeedTypesControllerSuperAdmin);
Container.get(DocumentsControllerSuperAdmin);
Container.get(DocumentTypesControllerSuperAdmin);
Container.get(AppointmentsController);
Container.get(VotesController);
Container.get(LiveVoteController);
Container.get(IdNotUserController);
Container.get(FranceConnectCustomerController);

View File

@ -49,10 +49,18 @@ export default async function documentHandler(req: Request, response: Response,
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");
return;
}
if(!folder?.stakeholders.find(stakeholder => stakeholder.uid === req.body.user.userId)) {
response.sendStatus(HttpCodes.UNAUTHORIZED).send("Unauthorized with this user");
return;
}
}
next();

View File

@ -7,7 +7,8 @@ import DeedTypesService from "@Services/super-admin/DeedTypesService/DeedTypesSe
export default async function folderHandler(req: Request, response: Response, next: NextFunction) {
try {
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 officeFolderNumber = req.body.folder_number;
const deed = req.body.deed;
@ -43,17 +44,25 @@ export default async function folderHandler(req: Request, response: Response, ne
}
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) {
response.status(HttpCodes.NOT_FOUND).send("Office folder not found");
return;
}
if (officeFolder.office.uid != officeId) {
if (officeFolder.office_uid != officeId) {
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
return;
}
if(!officeFolder.stakeholders.find(stakeholder => stakeholder.uid === userId)) {
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this user");
return;
}
}
next();

View File

@ -243,8 +243,8 @@ export default async function main() {
{
address: addresses[6],
first_name: "Jean",
last_name: "Dubigot",
email: "jean.dubigot@gmail.com",
last_name: "Dubignot",
email: "jean.dubignot@gmail.com",
phone_number: "06 78 90 12 34",
cell_phone_number: "06 78 90 12 34",
birthdate: null,
@ -664,10 +664,10 @@ export default async function main() {
},
{
name: "DELETE documents",
label: "Supprimer un document",
label: "Supprimer un document demandé",
created_at: new Date(),
updated_at: new Date(),
namespace: "super-admin",
namespace: "notary",
},
{
name: "POST customers",
@ -1540,6 +1540,15 @@ export default async function main() {
created_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[] = [

View File

@ -1,7 +1,7 @@
import DocumentsService from "@Services/super-admin/DocumentsService/DocumentsService";
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 { ETemplates } from "./Templates/EmailTemplates";
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 => {
const to = user.email;
const civility = this.getCivility(user.civility);
const to = user.contact!.email;
const civility = this.getCivility(user.contact!.civility);
const templateVariables = {
civility: civility,
last_name: user.last_name,
last_name: user.contact!.last_name,
link: this.variables.APP_HOST
};

View File

@ -65,4 +65,24 @@ export default class OfficeFolderAnchorsRepository extends BaseRepository {
...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);
}
}

View File

@ -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
*/

View File

@ -24,7 +24,7 @@ const storage = multer.memoryStorage();
rootUrl,
middlwares: [
cors({ origin: "*" }),
multer({ storage: storage }).single("file"),
multer({ storage: storage, limits: { fileSize: 32000000 } }).single("file"), //32 MB maximum
bodyParser.urlencoded({ extended: true }),
bodyParser.json(),
],

View File

@ -80,7 +80,7 @@ export default class CronService {
}
public async checkDocumentsExpiration() {
const cronJob = new CronJob("*/10 * * * * *", async () => {
const cronJob = new CronJob("0 20 * * *", async () => {
// Once a day at midnight
try {
const prisma = new PrismaClient();

View File

@ -1,17 +1,22 @@
import EmailRepository from "@Repositories/EmailRepository";
import BaseService from "@Services/BaseService";
import { Emails, PrismaClient } from "@prisma/client";
import { Emails } from "@prisma/client";
import { Service } from "typedi";
import MailchimpClient from "@mailchimp/mailchimp_transactional";
import { BackendVariables } from "@Common/config/variables/Variables";
import UsersService from "@Services/super-admin/UsersService/UsersService";
import EmailBuilder from "@Common/emails/EmailBuilder";
// import DocumentsService from "@Services/super-admin/DocumentsService/DocumentsService";
@Service()
export default class MailchimpService extends BaseService {
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();
}
@ -117,14 +122,7 @@ export default class MailchimpService extends BaseService {
}
public async sendRecapEmails() {
const prisma = new PrismaClient();
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';`
const usersToEmail = await this.usersService.get({ where: { office_folders: { some:{ documents: { some: { document_status: "DEPOSITED" } } }} }, distinct: ["uid"], include: { contact: true } });
await this.emailBuilder.sendRecapEmails(usersToEmail);
}

View File

@ -51,7 +51,7 @@ export default class DocumentsService extends BaseService {
if (!documentEntity) throw new Error("document not found");
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");
}
return this.documentsRepository.delete(uid);

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -2,16 +2,16 @@ import BaseService from "@Services/BaseService";
import { Service } from "typedi";
import User, { Appointment, Role, Vote } from "le-coffre-resources/dist/SuperAdmin";
import VotesRepository from "@Repositories/VotesRepository";
import { Appointments, EAppointmentStatus, EVote, Votes } from "@prisma/client";
import AppointmentService from "../AppointmentsService/AppointmentsService";
import { Appointments, EAppointmentStatus, EVote, Prisma, Votes } from "@prisma/client";
import UsersService from "../UsersService/UsersService";
import RolesService from "../RolesService/RolesService";
import AppointmentsRepository from "@Repositories/AppointmentsRepository";
@Service()
export default class LiveVoteService extends BaseService {
constructor(
private voteRepository: VotesRepository,
private appointmentService: AppointmentService,
private appointmentRepository: AppointmentsRepository,
private userService: UsersService,
private roleService: RolesService,
) {
@ -29,11 +29,47 @@ export default class LiveVoteService extends BaseService {
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> {
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: {
AND: [
{ user_uid: vote.appointment.targeted_user.uid },
@ -44,13 +80,13 @@ export default class LiveVoteService extends BaseService {
include: { votes: true },
});
if (appointmentByUser.length >= 1) {
return this.appointmentService.getByUidWithVotes(appointmentByUser[0]!.uid);
return this.appointmentRepository.findOneByUidWithVotes(appointmentByUser[0]!.uid);
}
return null;
}
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 userEntity = User.hydrate<User>(user!, { strategy: "excludeAll" });

View File

@ -62,6 +62,14 @@ export default class OfficeFoldersService extends BaseService {
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
* @throws {Error} If document cannot be deleted

View File

@ -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);
}
}