Merge branch 'staging' into preprod
This commit is contained in:
commit
6f1b0b3a5e
@ -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",
|
||||
|
@ -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;
|
||||
|
@ -5,6 +5,7 @@ import OfficeFoldersService from "@Services/customer/OfficeFoldersService/Office
|
||||
import { Service } from "typedi";
|
||||
import { OfficeFolders, Prisma } from "@prisma/client";
|
||||
import { OfficeFolder } from "le-coffre-resources/dist/Customer";
|
||||
import { OfficeFolder as OfficeFolderNotary } from "le-coffre-resources/dist/Notary";
|
||||
import officeFolderHandler from "@App/middlewares/CustomerHandler/FolderHandler";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
|
||||
@ -94,7 +95,7 @@ export default class OfficeFoldersController extends ApiController {
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const officeFolder = OfficeFolder.hydrate<OfficeFolder>(officeFolderEntity, { strategy: "excludeAll" });
|
||||
const officeFolder = OfficeFolderNotary.hydrate<OfficeFolderNotary>(officeFolderEntity, { strategy: "excludeAll" });
|
||||
|
||||
if(officeFolder.customers) {
|
||||
officeFolder.customers = officeFolder.customers!.filter((customer) => customer.contact?.email === email);
|
||||
|
@ -34,8 +34,8 @@ export default class CustomersController extends ApiController {
|
||||
}
|
||||
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
if (query.where?.office_folders) delete query.where.office_folders;
|
||||
const customerWhereInput: Prisma.CustomersWhereInput = { ...query.where, office_folders: { some: { office_uid: officeId } } };
|
||||
if (query.where?.office) delete query.where.office;
|
||||
const customerWhereInput: Prisma.CustomersWhereInput = { ...query.where, office: { uid: officeId } };
|
||||
query.where = customerWhereInput;
|
||||
|
||||
//call service to get prisma entity
|
||||
@ -60,6 +60,8 @@ export default class CustomersController extends ApiController {
|
||||
try {
|
||||
//init IUser resource with request body values
|
||||
const customerEntity = Customer.hydrate<Customer>(req.body);
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
customerEntity.office = { uid: officeId } as any;
|
||||
//validate user
|
||||
try {
|
||||
await validateOrReject(customerEntity, { groups: ["createCustomer"], forbidUnknownValues: false });
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
@ -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;
|
@ -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")
|
||||
}
|
||||
|
||||
|
2187
src/common/databases/seeders/oldSeeder.ts
Normal file
2187
src/common/databases/seeders/oldSeeder.ts
Normal file
File diff suppressed because it is too large
Load Diff
@ -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
@ -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 {
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user