Merge Dev in Staging
This commit is contained in:
commit
af61970f13
@ -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.88",
|
"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",
|
||||||
|
@ -12,6 +12,8 @@ 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 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>(
|
||||||
@ -37,6 +39,7 @@ export default class OfficeFoldersController extends ApiController {
|
|||||||
constructor(
|
constructor(
|
||||||
private secureService: SecureService,
|
private secureService: SecureService,
|
||||||
private officeFolderAnchorsRepository: OfficeFolderAnchorsRepository,
|
private officeFolderAnchorsRepository: OfficeFolderAnchorsRepository,
|
||||||
|
private officeFolderAnchorsService: OfficeFolderAnchorsService,
|
||||||
private officeFoldersService: OfficeFoldersService,
|
private officeFoldersService: OfficeFoldersService,
|
||||||
private notificationBuilder: NotificationBuilder,
|
private notificationBuilder: NotificationBuilder,
|
||||||
) {
|
) {
|
||||||
@ -163,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"];
|
||||||
|
|
||||||
@ -230,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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user