Merge branch 'refacto/live-vote-controller' into dev
This commit is contained in:
commit
7675c98da6
@ -58,8 +58,8 @@ export default class OfficeFoldersController extends ApiController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const officeId: string = req.body.user.office_Id;
|
const officeId: string = req.body.user.office_Id;
|
||||||
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
|
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId };
|
||||||
if(!query.where) query.where = { office: officeWhereInput};
|
if (!query.where) query.where = { office: officeWhereInput };
|
||||||
query.where.office = officeWhereInput;
|
query.where.office = officeWhereInput;
|
||||||
//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,7 @@ 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 CustomersController from "./api/customer/CustomersController";
|
||||||
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 +53,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 +63,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);
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -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