import { createManagingCompany } from '../../controllers/managingCompany' import { createUser } from '../../controllers/user' import { User } from 'nexus-plugin-prisma/client' import * as ProjectController from '../../controllers/project' import { prismaClient as prisma } from '../../prismaClient' const seedDatabase = async () => { console.log('Starting seed') const managingCompany = await createManagingCompany({ data: { shortName: 'Walter test company' }, }) const managerUsers: User[] = await prisma.user.findMany({ where: { AND: [{ role: { equals: 'MANAGER' } }, { managingCompany: { id: managingCompany.id } }], }, }) const createdProject = await ProjectController.createProject({ data: { managingCompany: { connect: { id: managingCompany.id } }, managers: { connect: { id: managerUsers[0].id } }, name: 'Walter project test', nameInitials: 'TP', numberOfProperties: 100, additionalInfo: 'additional info', isCondoProject: true, isRentalProject: true, hasSecurityAgent: true, hasGuessRegistration: true, hasFobAccess: true, hasRestaurant: true, hasGym: true, hasShowerInGym: true, hasLockerChangingRoom: true, hasGuessRoom: true, hasPartyRoom: true, allowDog: true, needDogInArmInCommonArea: true, hasValet: true, hasAccessForDog: true, accessForDogInfo: 'dog info', hasParkingForWorker: true, parkingForWorkerInfo: 'worker info', hasParkingForGuess: true, parkingForGuessInfo: 'guest info', hasCarWash: true, carWashInfo: 'car wash info', newOwnersNeedApproval: false, residentCanCreateTask: true, residentCanEditFirstName: true, residentCanEditLastName: true, residentCanEditEmail: true, residentCanEditPhoneNumber: true, tools: { set: [ 'NOTIFICATION', 'CALENDAR', 'CONTACT', 'RULE', 'AMENITY', 'MAIL', 'CHAT', 'FILE', 'SALE', 'WORK_ORDER', 'CAMERA', 'DOOR_ACCESS', ], }, servicesAvailable: { set: [ 'TRAINER', 'TAILOR', 'CLEANING', 'MASSAGE', 'FLOWER', 'DOG', 'TICKET', 'CAR_WASH', 'HANDYMAN', 'GROCERY', 'PHARMACY', 'JUICE', 'CATERING', 'MEALBOX', 'DISINFECTION', 'MEDICAL', 'COFFEE', 'LOCAL_GROCERY', 'SELF_CARE', ], }, }, managingCompanyId: managingCompany.id, }) const project = await prisma.project.findOne({ where: { id: createdProject.id } }) const property = await prisma.property.create({ data: { address: { create: { address1: 'address 1', zip: 'A1B 2C3', city: 'Montreal', state: null, country: null, apartmentNumber: 'test unit', }, }, floor: '20', type: 'Test unit type', squareFeet: 50000, squareFeetBalcony: 400, proportionateShare: 15, rooms: '5', note: 'note', monthlyCondoFeeAmount: 555, intercomCode: 'q3a5g4', buzzCode: 'q34g', wifiPassword: 'aw345eg', hasAlarmSystem: true, }, }) const building = await prisma.building.create({ data: { project: { connect: { id: project.id } }, address: { create: { address1: 'address 1', zip: 'A1B 2C3', city: 'Montreal', state: 'QC', country: 'CA', apartmentNumber: 'test unit', }, }, projects: { connect: [ { id: project.id, }, ], }, properties: { connect: [{ id: property.id }], }, }, }) const unitRoom = await prisma.unitRoom.create({ data: { title: 'Test unit room', project: { connect: { id: project.id } }, description: 'description of test unit room', }, }) const locker = await prisma.locker.create({ data: { number: '1212', cadastreNumber: '2222', properties: { connect: [ { id: property.id, }, ], }, project: { connect: { id: project.id, }, }, }, }) const parking = await prisma.parking.create({ data: { number: '1212', cadastreNumber: '2222', properties: { connect: [ { id: property.id, }, ], }, project: { connect: { id: project.id, }, }, proportionateShare: 10, }, }) const accessKey = await prisma.accessKey.create({ data: { number: '1212', property: { connect: { id: property.id, }, }, project: { connect: { id: project.id, }, }, }, }) const remote = await prisma.remote.create({ data: { number: '1212', property: { connect: { id: property.id, }, }, project: { connect: { id: project.id, }, }, }, }) await prisma.project.update({ where: { id: project.id }, data: { building: { connect: { id: building.id } }, buildings: { connect: [{ id: building.id }] }, unitRooms: { connect: { id: unitRoom.id } }, }, }) const resident = await createUser({ isResident: true, firstName: 'resident1', lastName: 'resident1', title: 'resident title', email: 'test+resident1@usewalter.com', preferedLanguage: 'en', emergencyContact: 'emergency contact', note: 'note', property: { connect: { id: property.id, }, }, properties: { connect: [ { id: property.id, }, ], }, hasAppNotificationEnable: true, hasEmailNotificationEnable: true, hasSMSNotificationEnable: false, projectsTenants: { connect: [ { id: project.id, }, ], }, role: 'RESIDENT', currentProject: { connect: { id: project.id, }, }, projects: { connect: [ { id: project.id, }, ], }, }) await createBigProjectForManagingCompany(managingCompany.id) console.log( `Your manager user is: ${managerUsers[0].email} (password: 12345678).\n Run the manager-web frontend and go to /auth/login to login with your manager user.\n\nYour resident user is: ${resident.email}. Run the resident-web frontend and go to auth/register to set your password and be able to log into the resident-web application. The login page for the resident web is at auth/login.` ) } const NUMBER_OF_RESIDENTS = 1000 async function createBigProjectForManagingCompany(managingCompanyId) { console.log('Creating another project with many properties and residents') const bigProject = await ProjectController.createProject({ managingCompanyId: managingCompanyId, data: { name: 'Big project', building: { create: { address: { create: { address1: '123 test', }, }, }, }, }, }) const buildingOfBigProject = await prisma.project .findOne({ where: { id: bigProject.id } }) .building() await Promise.all( new Array(NUMBER_OF_RESIDENTS).fill(1).map((_, index) => prisma.user.create({ data: { projects: { connect: [{ id: bigProject.id }] }, email: `${index}3129381@test.com`, property: { create: { building: { connect: { id: buildingOfBigProject.id, }, }, address: { create: { apartmentNumber: `Unit #${index}`, }, }, }, }, }, }) ) ) console.log('Created another project with many properties and residents') } seedDatabase() .catch((err) => { console.error(`An error occured: ${err}`) }) .finally(async () => { await prisma.disconnect() process.exit() })