Merge branch 'dev' into staging

This commit is contained in:
Vins 2024-05-27 16:56:00 +02:00
commit 3ce9c20f2b
13 changed files with 4557 additions and 2252 deletions

View File

@ -59,7 +59,7 @@
"file-type-checker": "^1.0.8",
"fp-ts": "^2.16.1",
"jsonwebtoken": "^9.0.0",
"le-coffre-resources": "git@github.com:smart-chain-fr/leCoffre-resources.git#v2.136",
"le-coffre-resources": "git@github.com:smart-chain-fr/leCoffre-resources.git#v2.139",
"module-alias": "^2.2.2",
"monocle-ts": "^2.3.13",
"multer": "^1.4.5-lts.1",

View File

@ -139,7 +139,7 @@ export default class AuthController extends ApiController {
return;
}
const passwordRegex = new RegExp(/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[A-Za-z\d@$!%*?&]{8,}$/);
const passwordRegex = new RegExp(/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[A-Za-z\d@$!%*?&_\\-]{8,}$/);
if (!passwordRegex.test(password)) {
this.httpBadRequest(response, "Password must contain at least 8 characters, 1 uppercase, 1 lowercase and 1 number");
return;

View File

@ -33,6 +33,7 @@ export default class UserNotificationController extends ApiController {
const userId: string = req.body.user.userId;
if(query.where?.user_uid) delete query.where.user_uid;
if(query.where?.user?.uid) delete query.where.user.uid;
query.orderBy = { notification : { created_at: "asc" }};
const notificationWhereInput: Prisma.UserNotificationsWhereInput = { ...query.where, user_uid: userId };
query.where = notificationWhereInput;

View File

@ -0,0 +1,78 @@
-- -- Add the office_uid column
-- ALTER TABLE customers
-- ADD COLUMN office_uid VARCHAR(255);
-- -- Set the office_uid for existing rows
-- UPDATE customers
-- SET office_uid = (
-- SELECT uid
-- FROM offices
-- WHERE "idNot" = '0000'
-- );
-- -- Create a temporary table to store the mapping
-- CREATE TEMPORARY TABLE customer_office_update AS
-- SELECT c.uid AS customer_uid, of.office_uid
-- FROM customers c
-- JOIN "_OfficeFolderHasCustomers" ofhc ON c.uid = ofhc."A"
-- JOIN office_folders of ON ofhc."B" = of.uid;
-- -- Update customers with the corresponding office_uid
-- UPDATE customers
-- SET office_uid = (
-- SELECT office_uid
-- FROM customer_office_update
-- WHERE customer_office_update.customer_uid = customers.uid
-- );
-- -- Drop the temporary table
-- DROP TABLE customer_office_update;
-- -- Alter the column to be NOT NULL
-- ALTER TABLE customers
-- ALTER COLUMN office_uid SET NOT NULL;
-- -- Add the foreign key constraint
-- ALTER TABLE customers
-- ADD CONSTRAINT customers_office_uid_fkey
-- FOREIGN KEY (office_uid) REFERENCES offices(uid)
-- ON DELETE CASCADE;
-- Add the office_uid column to the customers table
ALTER TABLE customers
ADD COLUMN office_uid VARCHAR(255);
-- Create a temporary table to store the mapping
CREATE TEMPORARY TABLE customer_office_update AS
SELECT c.uid AS customer_uid, of.office_uid
FROM customers c
JOIN "_OfficeFolderHasCustomers" ofhc ON c.uid = ofhc."A"
JOIN office_folders of ON ofhc."B" = of.uid;
-- Update customers with the corresponding office_uid where a mapping exists
UPDATE customers
SET office_uid = customer_office_update.office_uid
FROM customer_office_update
WHERE customers.uid = customer_office_update.customer_uid;
-- Drop the temporary table
DROP TABLE customer_office_update;
-- Set the office_uid for customers not linked to any office_folder based on the office with "idNot" = '0000'
UPDATE customers
SET office_uid = (
SELECT uid
FROM offices
WHERE "idNot" = '0000'
)
WHERE office_uid IS NULL;
-- Alter the column to be NOT NULL
ALTER TABLE customers
ALTER COLUMN office_uid SET NOT NULL;
-- Add the foreign key constraint
ALTER TABLE customers
ADD CONSTRAINT customers_office_uid_fkey
FOREIGN KEY (office_uid) REFERENCES offices(uid)
ON DELETE CASCADE;

View File

@ -0,0 +1,5 @@
-- DropForeignKey
ALTER TABLE "customers" DROP CONSTRAINT "customers_office_uid_fkey";
-- AddForeignKey
ALTER TABLE "customers" ADD CONSTRAINT "customers_office_uid_fkey" FOREIGN KEY ("office_uid") REFERENCES "offices"("uid") ON DELETE CASCADE ON UPDATE CASCADE;

View File

@ -110,6 +110,7 @@ model Offices {
document_types DocumentTypes[]
office_roles OfficeRoles[]
subscriptions Subscriptions[]
customers Customers[]
@@map("offices")
}
@ -125,6 +126,8 @@ model Customers {
documents Documents[]
password String? @db.VarChar(255)
totpCodes TotpCodes[]
office Offices @relation(fields: [office_uid], references: [uid], onDelete: Cascade)
office_uid String @db.VarChar(255)
@@map("customers")
}

File diff suppressed because it is too large Load Diff

View File

@ -422,105 +422,6 @@ export default async function main() {
},
];
const customers: Customer[] = [
{
contact: contacts[0],
created_at: new Date(),
updated_at: new Date(),
status: ECustomerStatus.PENDING,
},
{
contact: contacts[5],
created_at: new Date(),
updated_at: new Date(),
status: ECustomerStatus.PENDING,
},
{
contact: contacts[6],
created_at: new Date(),
updated_at: new Date(),
status: ECustomerStatus.PENDING,
},
{
contact: contacts[7],
created_at: new Date(),
updated_at: new Date(),
status: ECustomerStatus.PENDING,
},
{
contact: contacts[8],
created_at: new Date(),
updated_at: new Date(),
status: ECustomerStatus.PENDING,
},
{
contact: contacts[9],
created_at: new Date(),
updated_at: new Date(),
status: ECustomerStatus.PENDING,
},
{
contact: contacts[10],
created_at: new Date(),
updated_at: new Date(),
status: ECustomerStatus.PENDING,
},
{
contact: contacts[11],
created_at: new Date(),
updated_at: new Date(),
status: ECustomerStatus.PENDING,
},
{
contact: contacts[12],
created_at: new Date(),
updated_at: new Date(),
status: ECustomerStatus.PENDING,
},
{
contact: contacts[13],
created_at: new Date(),
updated_at: new Date(),
status: ECustomerStatus.PENDING,
},
{
contact: contacts[14],
created_at: new Date(),
updated_at: new Date(),
status: ECustomerStatus.PENDING,
},
{
contact: contacts[15],
created_at: new Date(),
updated_at: new Date(),
status: ECustomerStatus.PENDING,
},
{
contact: contacts[16],
created_at: new Date(),
updated_at: new Date(),
status: ECustomerStatus.PENDING,
},
{
contact: contacts[17],
created_at: new Date(),
updated_at: new Date(),
status: ECustomerStatus.PENDING,
},
{
contact: contacts[18],
created_at: new Date(),
updated_at: new Date(),
status: ECustomerStatus.PENDING,
},
{
contact: contacts[19],
created_at: new Date(),
updated_at: new Date(),
status: ECustomerStatus.PENDING,
},
];
const rules: Rule[] = [
{
name: "GET users",
@ -1916,6 +1817,121 @@ export default async function main() {
},
];
const customers: Customer[] = [
{
contact: contacts[0],
created_at: new Date(),
updated_at: new Date(),
status: ECustomerStatus.PENDING,
office: offices[0],
},
{
contact: contacts[5],
created_at: new Date(),
updated_at: new Date(),
status: ECustomerStatus.PENDING,
office: offices[0],
},
{
contact: contacts[6],
created_at: new Date(),
updated_at: new Date(),
status: ECustomerStatus.PENDING,
office: offices[0],
},
{
contact: contacts[7],
created_at: new Date(),
updated_at: new Date(),
status: ECustomerStatus.PENDING,
office: offices[0],
},
{
contact: contacts[8],
created_at: new Date(),
updated_at: new Date(),
status: ECustomerStatus.PENDING,
office: offices[0],
},
{
contact: contacts[9],
created_at: new Date(),
updated_at: new Date(),
status: ECustomerStatus.PENDING,
office: offices[0],
},
{
contact: contacts[10],
created_at: new Date(),
updated_at: new Date(),
status: ECustomerStatus.PENDING,
office: offices[0],
},
{
contact: contacts[11],
created_at: new Date(),
updated_at: new Date(),
status: ECustomerStatus.PENDING,
office: offices[0],
},
{
contact: contacts[12],
created_at: new Date(),
updated_at: new Date(),
status: ECustomerStatus.PENDING,
office: offices[0],
},
{
contact: contacts[13],
created_at: new Date(),
updated_at: new Date(),
status: ECustomerStatus.PENDING,
office: offices[0],
},
{
contact: contacts[14],
created_at: new Date(),
updated_at: new Date(),
status: ECustomerStatus.PENDING,
office: offices[0],
},
{
contact: contacts[15],
created_at: new Date(),
updated_at: new Date(),
status: ECustomerStatus.PENDING,
office: offices[0],
},
{
contact: contacts[16],
created_at: new Date(),
updated_at: new Date(),
status: ECustomerStatus.PENDING,
office: offices[0],
},
{
contact: contacts[17],
created_at: new Date(),
updated_at: new Date(),
status: ECustomerStatus.PENDING,
office: offices[0],
},
{
contact: contacts[18],
created_at: new Date(),
updated_at: new Date(),
status: ECustomerStatus.PENDING,
office: offices[0],
},
{
contact: contacts[19],
created_at: new Date(),
updated_at: new Date(),
status: ECustomerStatus.PENDING,
office: offices[0],
},
];
for (const office of offices) {
const officeCreated = await prisma.offices.create({
data: {
@ -2056,6 +2072,11 @@ export default async function main() {
const createArgs: Prisma.CustomersCreateArgs = {
data: {
status: ECustomerStatus.PENDING,
office: {
connect: {
uid: customer.office!.uid!,
},
},
contact: {
create: {
first_name: customer.contact!.first_name,

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +1,12 @@
import DocumentsService from "@Services/super-admin/DocumentsService/DocumentsService";
import { Documents } from "@prisma/client";
import User, { Document } from "le-coffre-resources/dist/SuperAdmin";
import { Document } from "le-coffre-resources/dist/SuperAdmin";
import { Service } from "typedi";
import { ETemplates } from "./Templates/EmailTemplates";
import MailchimpService from "@Services/common/MailchimpService/MailchimpService";
import { BackendVariables } from "@Common/config/variables/Variables";
import UsersService from "@Services/super-admin/UsersService/UsersService";
import User from "le-coffre-resources/dist/SuperAdmin";
@Service()
export default class EmailBuilder {

View File

@ -44,6 +44,11 @@ export default class CustomersRepository extends BaseRepository {
const createArgs: Prisma.CustomersCreateArgs = {
data: {
status: ECustomerStatus.PENDING,
office: {
connect: {
uid: customer.office!.uid,
},
},
contact: {
create: {
first_name: customer.contact!.first_name,

View File

@ -20,7 +20,6 @@ export default class UserNotificationRepository extends BaseRepository {
* @description : Find many user notifications
*/
public async findMany(query: Prisma.UserNotificationsFindManyArgs) {
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
return this.model.findMany(query);
}

View File

@ -70,6 +70,11 @@ export const initCustomers = (customer: Customer): Promise<Customers> => {
return prisma.customers.create({
data: {
status: ECustomerStatus.PENDING,
office: {
connect: {
uid: customer.office?.uid,
},
},
contact: {
create: {
first_name: customer.contact!.first_name,