Customer office relation
This commit is contained in:
parent
2a1e542763
commit
359dd6a280
@ -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.137",
|
||||
"module-alias": "^2.2.2",
|
||||
"monocle-ts": "^2.3.13",
|
||||
"multer": "^1.4.5-lts.1",
|
||||
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- Added the required column `office_uid` to the `customers` table without a default value. This is not possible if the table is not empty.
|
||||
|
||||
*/
|
||||
-- AlterTable
|
||||
ALTER TABLE "customers" ADD COLUMN "office_uid" VARCHAR(255) NOT NULL;
|
||||
|
||||
-- Set the office_uid for existing rows based on the office with "idNot" = '0000'
|
||||
UPDATE customers
|
||||
SET office_uid = (
|
||||
SELECT uid
|
||||
FROM offices
|
||||
WHERE "idNot" = '0000'
|
||||
);
|
||||
|
||||
-- Alter the column to be NOT NULL
|
||||
ALTER TABLE customers
|
||||
ALTER COLUMN office_uid SET NOT NULL;
|
||||
|
||||
-- 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;
|
||||
|
||||
-- Add the foreign key constraint
|
||||
ALTER TABLE customers
|
||||
ADD CONSTRAINT fk_customers_office
|
||||
FOREIGN KEY (office_uid) REFERENCES offices(uid)
|
||||
ON DELETE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "customers" ADD CONSTRAINT "customers_office_uid_fkey" FOREIGN KEY ("office_uid") REFERENCES "offices"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
|
@ -0,0 +1,2 @@
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "customers" DROP CONSTRAINT "fk_customers_office";
|
@ -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_membership: offices[0],
|
||||
},
|
||||
{
|
||||
contact: contacts[5],
|
||||
created_at: new Date(),
|
||||
updated_at: new Date(),
|
||||
status: ECustomerStatus.PENDING,
|
||||
office_membership: offices[0],
|
||||
},
|
||||
{
|
||||
contact: contacts[6],
|
||||
created_at: new Date(),
|
||||
updated_at: new Date(),
|
||||
status: ECustomerStatus.PENDING,
|
||||
office_membership: offices[0],
|
||||
},
|
||||
{
|
||||
contact: contacts[7],
|
||||
created_at: new Date(),
|
||||
updated_at: new Date(),
|
||||
status: ECustomerStatus.PENDING,
|
||||
office_membership: offices[0],
|
||||
},
|
||||
{
|
||||
contact: contacts[8],
|
||||
created_at: new Date(),
|
||||
updated_at: new Date(),
|
||||
status: ECustomerStatus.PENDING,
|
||||
office_membership: offices[0],
|
||||
},
|
||||
{
|
||||
contact: contacts[9],
|
||||
created_at: new Date(),
|
||||
updated_at: new Date(),
|
||||
status: ECustomerStatus.PENDING,
|
||||
office_membership: offices[0],
|
||||
},
|
||||
{
|
||||
contact: contacts[10],
|
||||
created_at: new Date(),
|
||||
updated_at: new Date(),
|
||||
status: ECustomerStatus.PENDING,
|
||||
office_membership: offices[0],
|
||||
},
|
||||
{
|
||||
contact: contacts[11],
|
||||
created_at: new Date(),
|
||||
updated_at: new Date(),
|
||||
status: ECustomerStatus.PENDING,
|
||||
office_membership: offices[0],
|
||||
},
|
||||
{
|
||||
contact: contacts[12],
|
||||
created_at: new Date(),
|
||||
updated_at: new Date(),
|
||||
status: ECustomerStatus.PENDING,
|
||||
office_membership: offices[0],
|
||||
},
|
||||
{
|
||||
contact: contacts[13],
|
||||
created_at: new Date(),
|
||||
updated_at: new Date(),
|
||||
status: ECustomerStatus.PENDING,
|
||||
office_membership: offices[0],
|
||||
},
|
||||
{
|
||||
contact: contacts[14],
|
||||
created_at: new Date(),
|
||||
updated_at: new Date(),
|
||||
status: ECustomerStatus.PENDING,
|
||||
office_membership: offices[0],
|
||||
},
|
||||
{
|
||||
contact: contacts[15],
|
||||
created_at: new Date(),
|
||||
updated_at: new Date(),
|
||||
status: ECustomerStatus.PENDING,
|
||||
office_membership: offices[0],
|
||||
},
|
||||
{
|
||||
contact: contacts[16],
|
||||
created_at: new Date(),
|
||||
updated_at: new Date(),
|
||||
status: ECustomerStatus.PENDING,
|
||||
office_membership: offices[0],
|
||||
},
|
||||
{
|
||||
contact: contacts[17],
|
||||
created_at: new Date(),
|
||||
updated_at: new Date(),
|
||||
status: ECustomerStatus.PENDING,
|
||||
office_membership: offices[0],
|
||||
},
|
||||
{
|
||||
contact: contacts[18],
|
||||
created_at: new Date(),
|
||||
updated_at: new Date(),
|
||||
status: ECustomerStatus.PENDING,
|
||||
office_membership: offices[0],
|
||||
},
|
||||
{
|
||||
contact: contacts[19],
|
||||
created_at: new Date(),
|
||||
updated_at: new Date(),
|
||||
status: ECustomerStatus.PENDING,
|
||||
office_membership: 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_membership!.uid!,
|
||||
},
|
||||
},
|
||||
contact: {
|
||||
create: {
|
||||
first_name: customer.contact!.first_name,
|
||||
|
Loading…
x
Reference in New Issue
Block a user