From 5207fd3159df345458a616cccb6b2c1118e0a2b7 Mon Sep 17 00:00:00 2001 From: OxSaitama Date: Mon, 19 Jun 2023 18:12:35 +0200 Subject: [PATCH] update seeder with roles --- src/common/databases/seeders/seeder.ts | 5 + src/common/databases/seeders/seeder2.ts | 8 ++ src/test/config/Init.ts | 157 +++++++++++++++--------- 3 files changed, 110 insertions(+), 60 deletions(-) diff --git a/src/common/databases/seeders/seeder.ts b/src/common/databases/seeders/seeder.ts index 881e081f..3210ca98 100644 --- a/src/common/databases/seeders/seeder.ts +++ b/src/common/databases/seeders/seeder.ts @@ -49,6 +49,9 @@ import { const uidUser1: string = randomString(); const uidUser2: string = randomString(); + const uidRole1: string = randomString(); + const uidRole2: string = randomString(); + const uidOfficeFolder1: string = randomString(); const uidOfficeFolder2: string = randomString(); const uidOfficeFolder3: string = randomString(); @@ -231,6 +234,7 @@ import { idNot: randomString(), contact_uid: uidContact1, office_uid: uidOffice1, + roles_uid: uidRole1, }, { uid: uidUser2, @@ -239,6 +243,7 @@ import { idNot: randomString(), contact_uid: uidContact2, office_uid: uidOffice2, + roles_uid: uidRole2, }, ]; diff --git a/src/common/databases/seeders/seeder2.ts b/src/common/databases/seeders/seeder2.ts index 7a3c82fe..248f04f7 100644 --- a/src/common/databases/seeders/seeder2.ts +++ b/src/common/databases/seeders/seeder2.ts @@ -100,6 +100,9 @@ import { const uidUser4: string = randomString(); const uidUser5: string = randomString(); + const uidRole1: string = randomString(); + const uidRole2: string = randomString(); + const uidOfficeFolder1: string = randomString(); const uidOfficeFolder2: string = randomString(); const uidOfficeFolder3: string = randomString(); @@ -793,6 +796,7 @@ import { idNot: randomString(), contact_uid: uidContact16, office_uid: uidOffice1, + roles_uid: uidRole1, }, { uid: uidUser2, @@ -801,6 +805,7 @@ import { idNot: randomString(), contact_uid: uidContact17, office_uid: uidOffice1, + roles_uid: uidRole2, }, { uid: uidUser3, @@ -809,6 +814,7 @@ import { idNot: randomString(), contact_uid: uidContact18, office_uid: uidOffice1, + roles_uid: uidRole1, }, { uid: uidUser4, @@ -817,6 +823,7 @@ import { idNot: randomString(), contact_uid: uidContact19, office_uid: uidOffice1, + roles_uid: uidRole2, }, { uid: uidUser5, @@ -825,6 +832,7 @@ import { idNot: randomString(), contact_uid: uidContact20, office_uid: uidOffice1, + roles_uid: uidRole1, }, ]; diff --git a/src/test/config/Init.ts b/src/test/config/Init.ts index 033fc8f1..a488d9a0 100644 --- a/src/test/config/Init.ts +++ b/src/test/config/Init.ts @@ -1,5 +1,16 @@ -import { Customers, DeedTypes, DocumentTypes, ECivility, ECustomerStatus, Offices, PrismaClient, Users } from "@prisma/client"; -import User, { Customer, DeedType, DocumentType, Office } from "le-coffre-resources/dist/SuperAdmin"; +import { + Customers, + DeedTypes, + DocumentTypes, + ECivility, + ECustomerStatus, + Offices, + PrismaClient, + Roles, + Rules, + Users, +} from "@prisma/client"; +import User, { Customer, DeedType, DocumentType, Office, Role, Rule } from "le-coffre-resources/dist/SuperAdmin"; const prisma = new PrismaClient(); @@ -54,68 +65,94 @@ export const initDeedType = (deedType: DeedType, office: Office, documentTypes?: export const initCustomers = (customer: Customer): Promise => { return prisma.customers.create({ data: { - status: ECustomerStatus.PENDING, - contact: { - create: { - first_name: customer.contact!.first_name, - last_name: customer.contact!.last_name, - email: customer.contact!.email, - phone_number: customer.contact!.phone_number, - cell_phone_number: customer.contact!?.cell_phone_number, - civility: ECivility[customer.contact!.civility as keyof typeof ECivility], - address: { - create: { - address: customer.contact!.address!.address, - zip_code: customer.contact!.address!.zip_code, - city: customer.contact!.address!.city, - }, - }, - }, - }, - }, + status: ECustomerStatus.PENDING, + contact: { + create: { + first_name: customer.contact!.first_name, + last_name: customer.contact!.last_name, + email: customer.contact!.email, + phone_number: customer.contact!.phone_number, + cell_phone_number: customer.contact!?.cell_phone_number, + civility: ECivility[customer.contact!.civility as keyof typeof ECivility], + address: { + create: { + address: customer.contact!.address!.address, + zip_code: customer.contact!.address!.zip_code, + city: customer.contact!.address!.city, + }, + }, + }, + }, + }, + }); +}; + +export const initRules = (rule: Rule): Promise => { + return prisma.rules.create({ + data: { + name: rule.name, + }, + }); +}; + +export const initRoles = (role: Role): Promise => { + return prisma.roles.create({ + data: { + name: role.name, + }, }); }; export const initUsers = (user: User): Promise => { return prisma.users.create({ data: { - idNot: user.idNot, - office_membership: { - connectOrCreate: { - where: { - idNot: user.office_membership!.idNot, - }, - create: { - idNot: user.office_membership!.idNot, - name: user.office_membership!.name, - crpcen: user.office_membership!.crpcen, - address: { - create: { - address: user.office_membership!.address!.address, - zip_code: user.office_membership!.address!.zip_code, - city: user.office_membership!.address!.city, - }, - }, - }, - }, - }, - contact: { - create: { - first_name: user.contact!.first_name, - last_name: user.contact!.last_name, - email: user.contact!.email, - phone_number: user.contact!.phone_number, - cell_phone_number: user.contact!.cell_phone_number, - civility: ECivility[user.contact!.civility as keyof typeof ECivility], - address: { - create: { - address: user.contact!.address!.address, - zip_code: user.contact!.address!.zip_code, - city: user.contact!.address!.city, - }, - }, - }, - }, - }, - }); + idNot: user.idNot, + office_membership: { + connectOrCreate: { + where: { + idNot: user.office_membership!.idNot, + }, + create: { + idNot: user.office_membership!.idNot, + name: user.office_membership!.name, + crpcen: user.office_membership!.crpcen, + address: { + create: { + address: user.office_membership!.address!.address, + zip_code: user.office_membership!.address!.zip_code, + city: user.office_membership!.address!.city, + }, + }, + }, + }, + }, + contact: { + create: { + first_name: user.contact!.first_name, + last_name: user.contact!.last_name, + email: user.contact!.email, + phone_number: user.contact!.phone_number, + cell_phone_number: user.contact!.cell_phone_number, + civility: ECivility[user.contact!.civility as keyof typeof ECivility], + address: { + create: { + address: user.contact!.address!.address, + zip_code: user.contact!.address!.zip_code, + city: user.contact!.address!.city, + }, + }, + }, + }, + role: { + connectOrCreate: { + where: { + uid: user.role!.uid, + }, + create: { + name: user.role!.name, + }, + }, + }, + }, + }); };