import * as fs from 'fs' import GeneralUtils from '../../utils/general' import config from '../../config' import { prismaClient as prisma } from '../../prismaClient' const NUMBER_OF_ITEM_TO_PROCESS_AT_SAME_TIME = 50 const NUMBER_OF_MULTIPLE_CONNECTIONS_ITEM_TO_PROCESS_AT_SAME_TIME = 200 function readJson(path: string) { return JSON.parse(fs.readFileSync(require.resolve(path)).toString()) } // Stuff to not process // Condo manager true const usersProcess = true const commentsProcess = true const offenseProcess = true const serviceRequestProcess = true const serviceRequestPriorityProcess = true const serviceRequestCategoProcess = true const managingCompaProcess = true const managingCompanyRProcess = true const jsonTaskCategoProcess = true const jsonCustomFProcess = true const jsonProcess = true const jsonTaskActiProcess = true const TaskStatusProcess = true const OffenseCategoryProcess = true const ContactPersonProcess = true const UnitRoomProcess = true const RoomModelProcess = true const ChosenModelProcess = true const IssueProcess = true const PropertyProcess = true const CarProcess = true const LockerProcess = true const RemoteProcess = true const AccessKeyProcess = true const ParkingProcess = true const PaymentMethodProcess = true const CreditCardProcess = true const PhoneProcess = true const BuildingProcess = true const ProjectProcess = true const PictureProcess = true const ServiceProcess = true const faqItemProcess = true const InvoiceProcess = true const ServiceProjectProcess = true const SegmentProcess = true const ConditionProcess = true const SegmentFieldProcess = true const BusinessHoursProcess = true const EventProcess = true const ReminderProcess = true const ReservationProcess = true const MeetingParticipantProcess = true const MeetingParticipantUnitProcess = true const MeetingActivityProcess = true const MeetingProcess = true const OrderProcess = true const OrderSubscriptionProcess = true const ReviewProcess = true const AdditionalServiceProcess = true const PromoCodeProcess = true const BookingProcess = true const ShippingLineProcess = true const TaxProcess = true const LineItemProcess = true const PaymentProcess = true const ManagerStoreOrderProcess = true const ManagerStoreOrderLineItemProcess = true const ManagerStoreItemProcess = true const AmenityProcess = true const AmenityBookingOptionsProcess = true const AmenityPaymentOptionProcess = true const PackageProcess = true const ContactProcess = true const RuleProcess = true const OptionProcess = true const AddonProcess = true const AddonItemProcess = true const OptionCategoryProcess = true const AdProcess = true const AddressProcess = true const PostProcess = true const ProxyProcess = true const PollProcess = true const PollQuestionProcess = true const PollQuestionAnswerProcess = true const NoteProcess = true const NoteCommentProcess = true const FileProcess = true const FolderProcess = true const ThirdPartyVersionProcess = true const MappedServiceProcess = true const MappingProcess = true const SyncStatusProcess = true const MappedServiceSettingsProcess = true const NotificationProcess = true const AccountStatementProcess = false const condoManagerComptesProcess = false // const UPDATE_FREQUENTLY = [ // 'User', // 'CondoManagerCompte', // 'Comment', // 'Offense', // 'ManagingCompany', // 'ManagingCompanyRole', // 'TaskCategory', // 'Task', // 'TaskActivity', // 'TaskStatus', // 'Notification', // 'Property', // 'Locker', // 'Remote', // 'AccessKey', // 'Parking', // 'PaymentMethod', // 'CreditCard', // 'Phone', // 'Picture', // 'Project', // 'Building', // 'Service', // 'ServiceProject', // 'Segment', // 'Condition', // 'SegmentField', // 'BusinessHours', // 'Event', // 'Reminder', // 'Reservation', // 'Order', // 'OrderSubscription', // 'Review', // 'AdditionalService', // 'PromoCode', // 'Booking', // 'LineItem', // 'Payment', // 'Amenity', // 'AmenityBookingOptions', // 'AmenityPaymentOption', // 'Package', // 'Contact', // 'Rule', // 'Option', // 'Ad', // 'Address', // 'Post', // 'File', // 'Folder', // 'SyncStatus', // 'MappedServiceSettings,' // ] // This processes all the items and tries to find and connect the good connected item for each // Single and multiple connections. Ex: For Ad, we have project, phone, owner and images that // are relations fields async function processItems(items, model, connections) { // For testing if all import works items = items.slice(0, 50) // items = items.filter(({id}) => id === 'cjkw02glcmpsc0977lw9s08kk') // const needToUpdateAll = UPDATE_FREQUENTLY.some(m => model === m) console.log(`Processing ${items.length} ${model}`) model = GeneralUtils.firstLetterToLowerCase(model) const singleConnections = connections.filter( ({ isMultiple, isScalar }) => !isMultiple && !isScalar ) const multipleConnections = connections.filter(({ isMultiple }) => isMultiple) const scalars = connections.filter(({ isScalar }) => isScalar) await GeneralUtils.loopChunksPromise( items, NUMBER_OF_ITEM_TO_PROCESS_AT_SAME_TIME, async (item) => { try { const finalObj = { ...item } await scalars.reduce(async (promise, field) => { await promise finalObj[field.path] = { set: item[field.path] } }, Promise.resolve) const existingInclude = multipleConnections.reduce( (final, obj) => ({ ...final, [obj.path]: { select: { id: true } } }), {} ) let existingItem try { existingItem = await prisma[model].findOne({ where: { id: item.id }, ...(multipleConnections.length > 0 && { include: existingInclude }), }) } catch (error) { console.log('existingInclude', existingInclude) throw error } await singleConnections.reduce(async (promise, field) => { await promise try { const id = item[field.path]?.id // Delete because anyway we can't send data like building: { id: ... } delete finalObj[field.path] if (id) { const model = GeneralUtils.firstLetterToLowerCase(field.table || field.path) // Example if existing item already created and already have the single connection // Don't add the connection if (existingItem && existingItem[`${field.path}Id`]) { return } const existingConnectedItemTo = await prisma[model] // Instead of notification ... // Need to for protection because sometimes we passed Notification example .findOne({ where: { id }, select: { id: true }, }) console.log("Can't find single connection item for", field.path, id) if (existingConnectedItemTo) { finalObj[field.path] = { connect: { id: existingConnectedItemTo.id }, } } } } catch (error) { console.log(error) } }, Promise.resolve) await multipleConnections.reduce(async (promise, field) => { await promise if (item[field.path]?.length > 0) { // console.log(`Processing ${item[field.path]?.length} multiple connections`) // initialize finalObj[field.path] = { connect: [] } // Loop 500 because a user can have 16k notifications and it's lonnng await GeneralUtils.loopChunksPromise( item[field.path], NUMBER_OF_MULTIPLE_CONNECTIONS_ITEM_TO_PROCESS_AT_SAME_TIME, async (itemConnectedTo) => { // for testing if bugs const modelName = GeneralUtils.firstLetterToLowerCase(field.table || field.path) if ( existingItem && existingItem[field.path]?.find(({ id }) => id === itemConnectedTo.id) ) { return } try { const existingValue = await prisma[modelName].findOne({ where: { id: itemConnectedTo.id }, select: { id: true }, }) if (existingValue) { finalObj[field.path] = { connect: [...(finalObj[field.path]?.connect || []), { id: existingValue.id }], } } } catch (error) { console.log('modelName', modelName) console.log('error', error) } } ) // We haven't found any item to connect... so delete it if (finalObj[field.path].connect.length === 0) { delete finalObj[field.path] } } else { delete finalObj[field.path] } }, Promise.resolve) const diff = GeneralUtils.difference(finalObj, existingItem) // FIX if (model === 'post' && !finalObj.type) { finalObj.type = 'NORMAL' } if (Object.prototype.hasOwnProperty.call(finalObj, 'HeroImageOfService')) { delete finalObj.HeroImageOfService } if (Object.prototype.hasOwnProperty.call(finalObj, 'eventsLinked')) { delete finalObj.eventsLinked } if (Object.prototype.hasOwnProperty.call(finalObj, 'subscription')) { delete finalObj.subscription } if (Object.prototype.hasOwnProperty.call(finalObj, 'subscriptionOrders')) { delete finalObj.subscriptionOrders } if (Object.prototype.hasOwnProperty.call(finalObj, 'subscriptionRootOrder')) { delete finalObj.subscriptionRootOrder } if (Object.keys(diff).some((key) => key !== 'createdAt' && key !== 'updatedAt')) { // console.log('update or create item. Diff:', diff) // eslint-disable-next-line no-unused-vars const { id, ...updateObj } = finalObj await prisma[model].upsert({ create: finalObj, update: updateObj, where: { id: item.id }, }) } else { // console.log('Dont update because no diff', diff) // console.log('existingItem', existingItem) // console.log('finalObj', finalObj) } // console.log(`Created or updated ${model}`) } catch (error) { console.log('model', model) console.log('item', item) console.error(error) throw new Error('STOP') } return true }, () => console.log(`Finish processing ${NUMBER_OF_ITEM_TO_PROCESS_AT_SAME_TIME} ${model}`) ) console.log(`Done processing ${items.length} ${model}`) } async function start() { console.log('Start importing data') // If table is not specified it's because it's same as path name // Ex: here path 'phone' is the same as table 'Phone' // But 'owner' is using table 'User' const UserConnections = [ { path: 'managerNotificationTypes', isScalar: true }, { path: 'orderNotificationTypes', isScalar: true }, { path: 'chatNotificationTypes', isScalar: true }, { path: 'expoNotificationTokens', isScalar: true }, { path: 'phone', table: 'Phone' }, { path: 'officePhone', table: 'Phone' }, { path: 'homePhone', table: 'Phone' }, { path: 'avatar', table: 'Picture' }, { path: 'createdBy', table: 'User' }, { path: 'notifications', table: 'Notification', isMultiple: true }, { path: 'notificationPreferences', table: 'NotificationPreference', isMultiple: true }, { path: 'managingCompanyRole', table: 'ManagingCompanyRole' }, { path: 'managingCompany', table: 'ManagingCompany' }, { path: 'createdTasks', table: 'Task', isMultiple: true }, { path: 'assignedTasks', table: 'Task', isMultiple: true }, { path: 'mentionedComments', table: 'Comment', isMultiple: true }, { path: 'createdComments', table: 'Comment', isMultiple: true }, { path: 'projectsManaging', table: 'Project', isMultiple: true }, { path: 'serviceProvider', table: 'Service' }, { path: 'associatedTasks', table: 'Task', isMultiple: true }, { path: 'property', table: 'Property' }, { path: 'properties', table: 'Property', isMultiple: true }, { path: 'paymentMethods', table: 'PaymentMethod', isMultiple: true }, { path: 'packages', table: 'Package', isMultiple: true }, { path: 'offenses', table: 'Offense', isMultiple: true }, { path: 'projects', table: 'Project', isMultiple: true }, { path: 'previousProjects', table: 'Project', isMultiple: true }, { path: 'currentProject', table: 'Project' }, { path: 'orders', table: 'Order', isMultiple: true }, { path: 'projectsBoardMember', table: 'Project', isMultiple: true }, { path: 'serviceRequests', table: 'ServiceRequest', isMultiple: true }, { path: 'filesSeen', table: 'File', isMultiple: true }, { path: 'goingEvents', table: 'Event', isMultiple: true }, { path: 'interestedEvents', table: 'Event', isMultiple: true }, { path: 'cantGoEvents', table: 'Event', isMultiple: true }, { path: 'postsSeen', table: 'Post', isMultiple: true }, { path: 'eventsSeen', table: 'Event', isMultiple: true }, { path: 'packagesSeen', table: 'Package', isMultiple: true }, { path: 'receivedOffenses', table: 'Offense', isMultiple: true }, { path: 'signedProxies', table: 'Proxy', isMultiple: true }, // RESIDENT FIELDS THAT APPLIES FOR MULTIPLE PROJECT { path: 'projectsActive', table: 'Project', isMultiple: true }, { path: 'projectsTenants', table: 'Project', isMultiple: true }, // NOT USED? DOT NO DELETE { path: 'notes', table: 'Note', isMultiple: true }, { path: 'service', table: 'Service' }, { path: 'address', table: 'Address' }, { path: 'cars', table: 'Car', isMultiple: true }, { path: 'car', table: 'Car' }, { path: 'lockers', table: 'Locker', isMultiple: true }, { path: 'parkings', table: 'Parking', isMultiple: true }, { path: 'remotes', table: 'Remote', isMultiple: true }, { path: 'accessKeys', table: 'AccessKey', isMultiple: true }, // CONDO MANAGER { path: 'condoManagerNomComptes', table: 'CondoManagerCompte', isMultiple: true }, // THIRD PARTY SYNCHRONIZATION { path: 'firstNameSyncStatuses', table: 'SyncStatus', isMultiple: true }, { path: 'lastNameSyncStatuses', table: 'SyncStatus', isMultiple: true }, { path: 'emailSyncStatuses', table: 'SyncStatus', isMultiple: true }, { path: 'condoManagerNoCompteReelSyncStatuses', table: 'SyncStatus', isMultiple: true }, { path: 'condoManagerCompteUserNumberSyncStatuses', table: 'SyncStatus', isMultiple: true }, // NOT USED ANYMORE { path: 'isResidentSyncStatuses', table: 'SyncStatus', isMultiple: true }, // PAYSAFE { path: 'paysafeAccounts', table: 'PaysafeAccount', isMultiple: true }, ] if (usersProcess) { let usersJson = readJson(`${config.root}/export/users.json`) await processItems(usersJson, 'user', UserConnections) usersJson = [] } const CommentConnections = [ { path: 'mentionedUsers', table: 'User', isMultiple: true }, { path: 'createdBy', table: 'User' }, { path: 'serviceRequestAssociatedTo', table: 'ServiceRequest' }, { path: 'task', table: 'Task' }, ] if (commentsProcess) { let commentsJson = readJson(`${config.root}/export/comments.json`) await processItems(commentsJson, 'comment', CommentConnections) commentsJson = [] } const OffenseConnections = [ { path: 'rule', table: 'Rule' }, { path: 'property', table: 'Property' }, { path: 'project', table: 'Project' }, { path: 'picture', table: 'Picture' }, { path: 'pictures', table: 'Picture', isMultiple: true }, { path: 'createdBy', table: 'User' }, ] if (offenseProcess) { let offenseJson = readJson(`${config.root}/export/offenses.json`) await processItems(offenseJson, 'offense', OffenseConnections) offenseJson = [] } const ServiceRequestConnections = [ { path: 'priority', table: 'ServiceRequestPriority' }, { path: 'createdBy', table: 'User' }, { path: 'associatedTo', table: 'User' }, { path: 'assignedTo', table: 'User' }, { path: 'property', table: 'Property' }, { path: 'pictures', table: 'Picture', isMultiple: true }, { path: 'project', table: 'Project' }, { path: 'seenBy', table: 'User', isMultiple: true }, { path: 'comments', table: 'Comment', isMultiple: true }, ] if (serviceRequestProcess) { let serviceRequestJson = readJson(`${config.root}/export/serviceRequests.json`) await processItems(serviceRequestJson, 'serviceRequest', ServiceRequestConnections) serviceRequestJson = [] } const ServiceRequestPriorityConnections = [] if (serviceRequestPriorityProcess) { let serviceRequestPriorityJson = readJson(`${config.root}/export/serviceRequestPriorities.json`) await processItems( serviceRequestPriorityJson, 'serviceRequestPriority', ServiceRequestPriorityConnections ) serviceRequestPriorityJson = [] } const ServiceRequestCategoryConnections = [] if (serviceRequestCategoProcess) { let serviceRequestCategories = readJson(`${config.root}/export/serviceRequestCategories.json`) await processItems( serviceRequestCategories, 'serviceRequestCategory', ServiceRequestCategoryConnections ) serviceRequestCategories = [] } const ManagingCompanyConnections = [ { path: 'serviceRequestCategories', isScalar: true }, { path: 'logo', table: 'Picture' }, { path: 'logoAvatar', table: 'Picture' }, { path: 'phone', table: 'Phone' }, { path: 'emergencyPhone', table: 'Phone' }, { path: 'roles', table: 'ManagingCompanyRole', isMultiple: true }, { path: 'address', table: 'Address' }, { path: 'offenseCategories', table: 'OffenseCategory', isMultiple: true }, { path: 'users', table: 'User', isMultiple: true }, { path: 'projects', table: 'Project', isMultiple: true }, { path: 'serviceRequestPriorities', table: 'ServiceRequestPriority', isMultiple: true }, { path: 'emailHeaderImage', table: 'Picture' }, { path: 'businessHours', table: 'BusinessHour', isMultiple: true }, { path: 'specialDates', table: 'BusinessHour', isMultiple: true }, { path: 'tasksStatuses', table: 'TaskStatus', isMultiple: true }, { path: 'tasksCategories', table: 'TaskCategory', isMultiple: true }, ] if (managingCompaProcess) { let managingCompanies = readJson(`${config.root}/export/managingCompanies.json`) await processItems(managingCompanies, 'managingCompany', ManagingCompanyConnections) managingCompanies = [] } const ManagingCompanyRoleConnections = [ { path: 'permissions', isScalar: true }, { path: 'projects', table: 'Project', isMultiple: true }, { path: 'managingCompany', table: 'ManagingCompany' }, ] if (managingCompanyRProcess) { let managingCompanyRoles = readJson(`${config.root}/export/managingCompanyRoles.json`) await processItems(managingCompanyRoles, 'managingCompanyRole', ManagingCompanyRoleConnections) managingCompanyRoles = [] } const TaskCategoryConnections = [{ path: 'managingCompany', table: 'ManagingCompany' }] if (jsonTaskCategoProcess) { let jsonTaskCategories = readJson(`${config.root}/export/taskCategories.json`) await processItems(jsonTaskCategories, 'TaskCategory', TaskCategoryConnections) jsonTaskCategories = [] } const CustomFieldConnections = [] if (jsonCustomFProcess) { let jsonCustomField = readJson(`${config.root}/export/customFields.json`) await processItems(jsonCustomField, 'CustomField', CustomFieldConnections) jsonCustomField = [] } const TaskConnections = [ { path: 'category', table: 'TaskCategory' }, { path: 'attachments', table: 'File', isMultiple: true }, { path: 'pictures', table: 'Picture', isMultiple: true }, { path: 'associatedProperty', table: 'Property' }, { path: 'associatedProject', table: 'Project' }, { path: 'status', table: 'TaskStatus' }, { path: 'createdBy', table: 'User' }, { path: 'associatedResident', table: 'User' }, { path: 'assignedTo', table: 'User' }, { path: 'collaborators', table: 'User', isMultiple: true }, { path: 'customFields', table: 'CustomField', isMultiple: true }, { path: 'comments', table: 'Comment', isMultiple: true }, { path: 'activities', table: 'TaskActivity', isMultiple: true }, ] if (jsonProcess) { let jsonTask = readJson(`${config.root}/export/tasks.json`) await processItems(jsonTask, 'Task', TaskConnections) jsonTask = [] } const TaskActivityConnections = [ { path: 'createdBy', table: 'User' }, { path: 'task', table: 'Task' }, ] if (jsonTaskActiProcess) { let jsonTaskActivity = readJson(`${config.root}/export/taskActivities.json`) await processItems(jsonTaskActivity, 'TaskActivity', TaskActivityConnections) jsonTaskActivity = [] } const TaskStatusConnections = [ { path: 'tasks', table: 'Task', isMultiple: true }, { path: 'managingCompany', table: 'ManagingCompany' }, ] if (TaskStatusProcess) { let TaskStatusJson = readJson(`${config.root}/export/taskStatuses.json`) await processItems(TaskStatusJson, 'TaskStatus', TaskStatusConnections) TaskStatusJson = [] } const OffenseCategoryConnections = [] if (OffenseCategoryProcess) { let OffenseCategoryJson = readJson(`${config.root}/export/offenseCategories.json`) await processItems(OffenseCategoryJson, 'OffenseCategory', OffenseCategoryConnections) OffenseCategoryJson = [] } const ContactPersonConnections = [{ path: 'phone', table: 'Phone' }] if (ContactPersonProcess) { let ContactPersonJson = readJson(`${config.root}/export/contactPersons.json`) await processItems(ContactPersonJson, 'ContactPerson', ContactPersonConnections) ContactPersonJson = [] } const UnitRoomConnections = [ { path: 'roomModels', table: 'RoomModel', isMultiple: true }, { path: 'project', table: 'Project' }, ] if (UnitRoomProcess) { let UnitRoomJson = readJson(`${config.root}/export/unitRooms.json`) await processItems(UnitRoomJson, 'UnitRoom', UnitRoomConnections) UnitRoomJson = [] } const RoomModelConnections = [ { path: 'images', table: 'Picture', isMultiple: true }, { path: 'unitRoom', table: 'UnitRoom' }, ] if (RoomModelProcess) { let RoomModelJson = readJson(`${config.root}/export/roomModels.json`) await processItems(RoomModelJson, 'RoomModel', RoomModelConnections) RoomModelJson = [] } const ChosenModelConnections = [ { path: 'model', table: 'RoomModel' }, { path: 'room', table: 'UnitRoom' }, ] if (ChosenModelProcess) { let ChosenModelJson = readJson(`${config.root}/export/chosenModels.json`) await processItems(ChosenModelJson, 'ChosenModel', ChosenModelConnections) ChosenModelJson = [] } const IssueConnections = [{ path: 'assignee', table: 'User' }] if (IssueProcess) { let IssueJson = readJson(`${config.root}/export/issues.json`) await processItems(IssueJson, 'Issue', IssueConnections) IssueJson = [] } const PropertyConnections = [ { path: 'issues', table: 'Issue', isMultiple: true }, { path: 'chosenModels', table: 'ChosenModel', isMultiple: true }, { path: 'annexes', table: 'File', isMultiple: true }, { path: 'referenceProperty', table: 'File' }, { path: 'accountStatements', table: 'AccountStatement', isMultiple: true }, { path: 'cars', table: 'Car', isMultiple: true }, { path: 'remotes', table: 'Remote', isMultiple: true }, { path: 'accessKeys', table: 'AccessKey', isMultiple: true }, { path: 'lease', table: 'Picture' }, { path: 'parkings', table: 'Parking', isMultiple: true }, { path: 'lockers', table: 'Locker', isMultiple: true }, { path: 'plan', table: 'Picture' }, { path: 'address', table: 'Address' }, { path: 'building', table: 'Building' }, { path: 'users', table: 'User', isMultiple: true }, { path: 'owners', table: 'User', isMultiple: true }, { path: 'tenants', table: 'User', isMultiple: true }, { path: 'previousOwners', table: 'User', isMultiple: true }, { path: 'previousUsers', table: 'User', isMultiple: true }, { path: 'notes', table: 'Note', isMultiple: true }, { path: 'receivedOffenses', table: 'Offense', isMultiple: true }, // PAYSAFE { path: 'EFTPayments', table: 'PaySafePayment', isMultiple: true }, // not sure what link strategy we want here. should be 1-user-to-many-payments { path: 'EFTRefunds', table: 'PaySafeRefund', isMultiple: true }, // THIRD PARTY SYNCHRONIZATION ] if (PropertyProcess) { let PropertyJson = readJson(`${config.root}/export/properties.json`) await processItems(PropertyJson, 'Property', PropertyConnections) PropertyJson = [] } // const CarConnections = [ // { path: 'owner', table: 'User' }, // { path: 'oldOwner', table: 'User' }, // { path: 'associatedProperty', table: 'Property' }, // ] // if (CarProcess) { // let CarJson = readJson(`${config.root}/export/cars.json`) // await processItems(CarJson, 'Car', CarConnections) // CarJson = [] // } const LockerConnections = [ { path: 'project', table: 'Project' }, { path: 'properties', table: 'Property', isMultiple: true }, { path: 'owners', table: 'User', isMultiple: true }, ] if (LockerProcess) { let LockerJson = readJson(`${config.root}/export/lockers.json`) await processItems(LockerJson, 'Locker', LockerConnections) LockerJson = [] } const RemoteConnections = [ { path: 'project', table: 'Project' }, { path: 'property', table: 'Property' }, { path: 'owners', table: 'User', isMultiple: true }, ] if (RemoteProcess) { let RemoteJson = readJson(`${config.root}/export/remotes.json`) await processItems(RemoteJson, 'Remote', RemoteConnections) RemoteJson = [] } const AccessKeyConnections = [ { path: 'project', table: 'Project' }, { path: 'property', table: 'Property' }, { path: 'owners', table: 'User', isMultiple: true }, ] if (AccessKeyProcess) { let AccessKeyJson = readJson(`${config.root}/export/accessKeys.json`) await processItems(AccessKeyJson, 'AccessKey', AccessKeyConnections) AccessKeyJson = [] } const ParkingConnections = [ { path: 'project', table: 'Project' }, { path: 'properties', table: 'Property', isMultiple: true }, { path: 'owners', table: 'User', isMultiple: true }, ] if (ParkingProcess) { let ParkingJson = readJson(`${config.root}/export/parkings.json`) await processItems(ParkingJson, 'Parking', ParkingConnections) ParkingJson = [] } const PaymentMethodConnections = [ { path: 'owner', table: 'User' }, { path: 'creditCard', table: 'CreditCard' }, ] if (PaymentMethodProcess) { let PaymentMethodJson = readJson(`${config.root}/export/paymentMethods.json`) await processItems(PaymentMethodJson, 'PaymentMethod', PaymentMethodConnections) PaymentMethodJson = [] } const CreditCardConnections = [ { path: 'address', table: 'Address' }, { path: 'paymentMethod', table: 'PaymentMethod' }, ] if (CreditCardProcess) { let CreditCardJson = readJson(`${config.root}/export/creditCards.json`) await processItems(CreditCardJson, 'CreditCard', CreditCardConnections) CreditCardJson = [] } const PhoneConnections = [ // THIRD PARTY SYNCHRONIZATION { path: 'phoneSyncStatuses', table: 'SyncStatus', isMultiple: true }, { path: 'extensionSyncStatuses', table: 'SyncStatus', isMultiple: true }, { path: 'countryCodeSyncStatuses', table: 'SyncStatus', isMultiple: true }, { path: 'nationalFormatSyncStatuses', table: 'SyncStatus', isMultiple: true }, ] if (PhoneProcess) { let PhoneJson = readJson(`${config.root}/export/phones.json`) await processItems(PhoneJson, 'Phone', PhoneConnections) PhoneJson = [] } const ProjectConnections = [ { path: 'tools', isScalar: true }, { path: 'servicesAvailable', isScalar: true }, { path: 'logo', table: 'Picture' }, { path: 'squareLogo', table: 'Picture' }, { path: 'coOwnershipDeclaration', table: 'File' }, { path: 'appInviteEmailHeaderImage', table: 'Picture' }, { path: 'ads', table: 'Ad', isMultiple: true }, { path: 'managingCompany', table: 'ManagingCompany' }, { path: 'users', table: 'User', isMultiple: true }, { path: 'boardMembers', table: 'User', isMultiple: true }, { path: 'notifications', table: 'Notification', isMultiple: true }, { path: 'building', table: 'Building' }, { path: 'buildings', table: 'Building', isMultiple: true }, { path: 'events', table: 'Event', isMultiple: true }, { path: 'posts', table: 'Post', isMultiple: true }, { path: 'rules', table: 'Rule', isMultiple: true }, { path: 'packages', table: 'Package', isMultiple: true }, { path: 'amenities', table: 'Amenity', isMultiple: true }, { path: 'sharedAmenities', table: 'Amenity', isMultiple: true }, { path: 'contacts', table: 'Contact', isMultiple: true }, { path: 'reservations', table: 'Reservation', isMultiple: true }, { path: 'serviceProjects', table: 'ServiceProject', isMultiple: true }, { path: 'contactPersons', table: 'ContactPerson', isMultiple: true }, { path: 'lockers', table: 'Locker', isMultiple: true }, { path: 'segments', table: 'Segment', isMultiple: true }, { path: 'remotes', table: 'Remote', isMultiple: true }, { path: 'accessKeys', table: 'AccessKey', isMultiple: true }, { path: 'parkings', table: 'Parking', isMultiple: true }, { path: 'notes', table: 'Note', isMultiple: true }, { path: 'unitRooms', table: 'UnitRoom', isMultiple: true }, { path: 'serviceRequests', table: 'ServiceRequest', isMultiple: true }, { path: 'folders', table: 'Folder', isMultiple: true }, { path: 'currentUsers', table: 'User', isMultiple: true }, { path: 'tasks', table: 'Task', isMultiple: true }, { path: 'managers', table: 'User', isMultiple: true }, // PAYSAFE // THIRD PARTY SYNCHRONIZATION { path: 'thirdPartyServices', table: 'MappedService', isMultiple: true }, { path: 'thirdPartyServiceSettings', table: 'MappedServiceSetting', isMultiple: true }, ] if (ProjectProcess) { let ProjectJson = readJson(`${config.root}/export/projects.json`) await processItems(ProjectJson, 'Project', ProjectConnections) ProjectJson = [] } const BuildingConnections = [ { path: 'address', table: 'Address' }, { path: 'properties', table: 'Property', isMultiple: true }, { path: 'project', table: 'Project' }, ] if (BuildingProcess) { let BuildingJson = readJson(`${config.root}/export/buildings.json`) await processItems(BuildingJson, 'Building', BuildingConnections) BuildingJson = [] } const PictureConnections = [ { path: 'iconOfService', table: 'Service' }, // { path: 'HeroImageOfService', table: 'Service' }, { path: 'roomModel', table: 'RoomModel' }, { path: 'projectAppInviteEmailHeader', table: 'Project' }, { path: 'packageOfImage', table: 'Package' }, { path: 'packageOfSignatureImage', table: 'Package' }, ] if (PictureProcess) { let PictureJson = readJson(`${config.root}/export/pictures.json`) await processItems(PictureJson, 'Picture', PictureConnections) PictureJson = [] } const ServiceConnections = [ { path: 'address', table: 'Address' }, { path: 'phone', table: 'Phone' }, { path: 'businessHours', table: 'BusinessHour', isMultiple: true }, { path: 'specialDates', table: 'BusinessHour', isMultiple: true }, { path: 'bannerLogo', table: 'Picture' }, { path: 'squareLogo', table: 'Picture' }, { path: 'serviceProjects', table: 'ServiceProject', isMultiple: true }, { path: 'taxLines', table: 'Tax', isMultiple: true }, { path: 'shippingLines', table: 'ShippingLine', isMultiple: true }, { path: 'invoices', table: 'Invoice', isMultiple: true }, { path: 'options', table: 'Option', isMultiple: true }, { path: 'users', table: 'User', isMultiple: true }, { path: 'pickupHours', table: 'BusinessHour', isMultiple: true }, { path: 'categories', table: 'OptionCategory', isMultiple: true }, // NOT USED { path: 'contactPersons', table: 'ContactPerson', isMultiple: true }, { path: 'frequentlyAskedQuestions', table: 'faqItem', isMultiple: true }, { path: 'owner', table: 'User' }, ] if (ServiceProcess) { let ServiceJson = readJson(`${config.root}/export/services.json`) await processItems(ServiceJson, 'Service', ServiceConnections) ServiceJson = [] } const faqItemConnections = [] if (faqItemProcess) { let faqItemJson = readJson(`${config.root}/export/faqItems.json`) await processItems(faqItemJson, 'faqItem', faqItemConnections) faqItemJson = [] } const InvoiceConnections = [{ path: 'service', table: 'Service' }] if (InvoiceProcess) { let InvoiceJson = readJson(`${config.root}/export/invoices.json`) await processItems(InvoiceJson, 'Invoice', InvoiceConnections) InvoiceJson = [] } const ServiceProjectConnections = [ { path: 'businessHours', table: 'BusinessHour', isMultiple: true }, { path: 'specialDates', table: 'BusinessHour', isMultiple: true }, { path: 'project', table: 'Project' }, { path: 'options', table: 'Option', isMultiple: true }, { path: 'orders', table: 'Order', isMultiple: true }, { path: 'service', table: 'Service' }, { path: 'notifications', table: 'Notification', isMultiple: true }, ] if (ServiceProjectProcess) { let ServiceProjectJson = readJson(`${config.root}/export/serviceProjects.json`) await processItems(ServiceProjectJson, 'ServiceProject', ServiceProjectConnections) ServiceProjectJson = [] } const SegmentConnections = [ { path: 'users', table: 'User', isMultiple: true }, // Will delete { path: 'properties', table: 'Property', isMultiple: true }, // Will delete { path: 'parkings', table: 'Parking', isMultiple: true }, // Will delete { path: 'lockers', table: 'Locker', isMultiple: true }, // Will delete { path: 'project', table: 'Project' }, { path: 'conditions', table: 'Condition', isMultiple: true }, { path: 'segmentFields', table: 'SegmentField', isMultiple: true }, ] if (SegmentProcess) { let SegmentJson = readJson(`${config.root}/export/segments.json`) await processItems(SegmentJson, 'Segment', SegmentConnections) SegmentJson = [] } const ConditionConnections = [] if (ConditionProcess) { let ConditionJson = readJson(`${config.root}/export/conditions.json`) await processItems(ConditionJson, 'Condition', ConditionConnections) ConditionJson = [] } const SegmentFieldConnections = [] if (SegmentFieldProcess) { let SegmentFieldJson = readJson(`${config.root}/export/segmentFields.json`) await processItems(SegmentFieldJson, 'SegmentField', SegmentFieldConnections) SegmentFieldJson = [] } const BusinessHoursConnections = [ { path: 'serviceProjectBusinessHours', table: 'ServiceProject' }, { path: 'serviceProjectSpecialDate', table: 'ServiceProject' }, ] if (BusinessHoursProcess) { let BusinessHoursJson = readJson(`${config.root}/export/businessHourses.json`) await processItems(BusinessHoursJson, 'BusinessHour', BusinessHoursConnections) BusinessHoursJson = [] } // MISSING EVENTS const EventConnections = [ { path: 'project', table: 'Project' }, // { path: 'eventsLinked', table: 'Event', isMultiple: true }, { path: 'goingUsers', table: 'User', isMultiple: true }, { path: 'interestedUsers', table: 'User', isMultiple: true }, { path: 'cantGoUsers', table: 'User', isMultiple: true }, { path: 'coverImage', table: 'Picture' }, { path: 'address', table: 'Address' }, { path: 'segments', table: 'Segment', isMultiple: true }, { path: 'seenBy', table: 'User', isMultiple: true }, { path: 'notifications', table: 'Notification', isMultiple: true }, ] if (EventProcess) { let EventJson = readJson(`${config.root}/export/events.json`) await processItems(EventJson, 'Event', EventConnections) EventJson = [] } const ReminderConnections = [] if (ReminderProcess) { let ReminderJson = readJson(`${config.root}/export/reminders.json`) await processItems(ReminderJson, 'Reminder', ReminderConnections) ReminderJson = [] } const ReservationConnections = [ { path: 'address', table: 'Address' }, { path: 'customer', table: 'User' }, { path: 'payments', table: 'Payment', isMultiple: true }, { path: 'project', table: 'Project' }, { path: 'amenity', table: 'Amenity' }, ] if (ReservationProcess) { let ReservationJson = readJson(`${config.root}/export/reservations.json`) await processItems(ReservationJson, 'Reservation', ReservationConnections) ReservationJson = [] } const MeetingParticipantConnections = [ { path: 'isRepresentedBy', table: 'User' }, { path: 'representedByMeetingParticipant', table: 'MeetingParticipant' }, { path: 'meetingParticipantsRepresenting', table: 'MeetingParticipant', isMultiple: true }, { path: 'isRepresentedByProperty', table: 'Property' }, { path: 'proxy', table: 'Proxy' }, { path: 'proxyFile', table: 'File' }, { path: 'user', table: 'User' }, { path: 'users', table: 'User', isMultiple: true }, { path: 'property', table: 'Property' }, { path: 'activities', table: 'MeetingActivity', isMultiple: true }, { path: 'meeting', table: 'Meeting' }, // NOT USED // NEW { path: 'properties', table: 'Property', isMultiple: true }, ] if (MeetingParticipantProcess) { let MeetingParticipantJson = readJson(`${config.root}/export/meetingParticipants.json`) await processItems(MeetingParticipantJson, 'MeetingParticipant', MeetingParticipantConnections) MeetingParticipantJson = [] } const MeetingParticipantUnitConnections = [ { path: 'participants', table: 'MeetingParticipant', isMultiple: true }, { path: 'meeting', table: 'Meeting' }, { path: 'property', table: 'Property' }, ] if (MeetingParticipantUnitProcess) { let MeetingParticipantUnitJson = readJson(`${config.root}/export/meetingParticipantUnits.json`) await processItems( MeetingParticipantUnitJson, 'MeetingParticipantUnit', MeetingParticipantUnitConnections ) MeetingParticipantUnitJson = [] } const MeetingActivityConnections = [] if (MeetingActivityProcess) { let MeetingActivityJson = readJson(`${config.root}/export/meetingActivities.json`) await processItems(MeetingActivityJson, 'MeetingActivity', MeetingActivityConnections) MeetingActivityJson = [] } const MeetingConnections = [ { path: 'participants', table: 'MeetingParticipant', isMultiple: true }, { path: 'participantsUnits', table: 'MeetingParticipantUnit', isMultiple: true }, { path: 'project', table: 'Project' }, { path: 'invitationAttachments', table: 'File', isMultiple: true }, { path: 'polls', table: 'Poll', isMultiple: true }, ] if (MeetingProcess) { let MeetingJson = readJson(`${config.root}/export/meetings.json`) await processItems(MeetingJson, 'Meeting', MeetingConnections) MeetingJson = [] } // TODO: Fix subscriptionOrders with Order_B_OrderSubscriptionsOfOrder and ... const OrderConnections = [ { path: 'deliveryAddress', table: 'Address' }, { path: 'serviceProject', table: 'ServiceProject' }, { path: 'booking', table: 'Booking' }, { path: 'lineItems', table: 'LineItem', isMultiple: true }, { path: 'customer', table: 'User' }, { path: 'promoCodes', table: 'PromoCode', isMultiple: true }, { path: 'additionalServices', table: 'AdditionalService', isMultiple: true }, { path: 'employeeMobilePhone', table: 'Phone' }, { path: 'review', table: 'Review' }, // { path: 'subscription', table: 'OrderSubscription' }, // { path: 'subscriptionOrders', table: 'Order', isMultiple: true }, // { path: 'subscriptionRootOrder', table: 'Order' }, ] if (OrderProcess) { let OrderJson = readJson(`${config.root}/export/orders.json`) await processItems(OrderJson, 'Order', OrderConnections) OrderJson = [] } const OrderSubscriptionConnections = [] if (OrderSubscriptionProcess) { let OrderSubscriptionJson = readJson(`${config.root}/export/orderSubscriptions.json`) await processItems(OrderSubscriptionJson, 'OrderSubscription', OrderSubscriptionConnections) OrderSubscriptionJson = [] } const ReviewConnections = [ { path: 'order', table: 'Order' }, { path: 'serviceProject', table: 'ServiceProject' }, ] if (ReviewProcess) { let ReviewJson = readJson(`${config.root}/export/reviews.json`) await processItems(ReviewJson, 'Review', ReviewConnections) ReviewJson = [] } const AdditionalServiceConnections = [ { path: 'creator', table: 'User' }, { path: 'order', table: 'Order' }, ] if (AdditionalServiceProcess) { let AdditionalServiceJson = readJson(`${config.root}/export/additionalServices.json`) await processItems(AdditionalServiceJson, 'AdditionalService', AdditionalServiceConnections) AdditionalServiceJson = [] } const PromoCodeConnections = [{ path: 'order', table: 'Order' }] if (PromoCodeProcess) { let PromoCodeJson = readJson(`${config.root}/export/promoCodes.json`) await processItems(PromoCodeJson, 'PromoCode', PromoCodeConnections) PromoCodeJson = [] } const BookingConnections = [ { path: 'address', table: 'Address' }, // for now in the app we're only using the 'date' field... ] if (BookingProcess) { let BookingJson = readJson(`${config.root}/export/bookings.json`) await processItems(BookingJson, 'Booking', BookingConnections) BookingJson = [] } const ShippingLineConnections = [{ path: 'taxLines', table: 'Tax', isMultiple: true }] if (ShippingLineProcess) { let ShippingLineJson = readJson(`${config.root}/export/shippingLines.json`) await processItems(ShippingLineJson, 'ShippingLine', ShippingLineConnections) ShippingLineJson = [] } const TaxConnections = [] if (TaxProcess) { let TaxJson = readJson(`${config.root}/export/taxes.json`) await processItems(TaxJson, 'Tax', TaxConnections) TaxJson = [] } const LineItemConnections = [ { path: 'order', table: 'Order' }, { path: 'option', table: 'Option' }, // { path: 'optionJson', table: 'Json' } ] if (LineItemProcess) { let LineItemJson = readJson(`${config.root}/export/lineItems.json`) await processItems(LineItemJson, 'LineItem', LineItemConnections) LineItemJson = [] } const PaymentConnections = [ { path: 'customer', table: 'User' }, { path: 'createdBy', table: 'User' }, { path: 'paymentMethod', table: 'PaymentMethod' }, ] if (PaymentProcess) { let PaymentJson = readJson(`${config.root}/export/payments.json`) await processItems(PaymentJson, 'Payment', PaymentConnections) PaymentJson = [] } const ManagerStoreOrderConnections = [ { path: 'deliveryAddress', table: 'Address' }, { path: 'project', table: 'Project' }, { path: 'lineItems', table: 'ManagerStoreOrderLineItem', isMultiple: true }, { path: 'customer', table: 'User' }, ] if (ManagerStoreOrderProcess) { let ManagerStoreOrderJson = readJson(`${config.root}/export/managerStoreOrders.json`) await processItems(ManagerStoreOrderJson, 'ManagerStoreOrder', ManagerStoreOrderConnections) ManagerStoreOrderJson = [] } const ManagerStoreOrderLineItemConnections = [ { path: 'order', table: 'ManagerStoreOrder' }, { path: 'item', table: 'ManagerStoreItem' }, ] if (ManagerStoreOrderLineItemProcess) { let ManagerStoreOrderLineItemJson = readJson( `${config.root}/export/managerStoreOrderLineItems.json` ) await processItems( ManagerStoreOrderLineItemJson, 'ManagerStoreOrderLineItem', ManagerStoreOrderLineItemConnections ) ManagerStoreOrderLineItemJson = [] } const ManagerStoreItemConnections = [ { path: 'projects', table: 'Project', isMultiple: true }, { path: 'images', table: 'Picture', isMultiple: true }, ] if (ManagerStoreItemProcess) { let ManagerStoreItemJson = readJson(`${config.root}/export/managerStoreItems.json`) await processItems(ManagerStoreItemJson, 'ManagerStoreItem', ManagerStoreItemConnections) ManagerStoreItemJson = [] } const AmenityConnections = [ { path: 'blockedDates', isScalar: true }, { path: 'image', table: 'Picture' }, { path: 'images', table: 'Picture', isMultiple: true }, { path: 'bookingOptions', table: 'AmenityBookingOption', isMultiple: true }, { path: 'termsFile', table: 'File' }, { path: 'disclaimerFile', table: 'File' }, { path: 'reservations', table: 'Reservation', isMultiple: true }, { path: 'seenBy', table: 'User', isMultiple: true }, { path: 'project', table: 'Project' }, { path: 'sharedWithProjects', table: 'Project', isMultiple: true }, // NOT USED ] if (AmenityProcess) { let AmenityJson = readJson(`${config.root}/export/amenities.json`) await processItems(AmenityJson, 'Amenity', AmenityConnections) AmenityJson = [] } const AmenityBookingOptionsConnections = [ { path: 'usageDurationSeconds', isScalar: true }, { path: 'usageDurationMS', isScalar: true }, { path: 'segments', table: 'Segment', isMultiple: true }, { path: 'paymentOptions', table: 'AmenityPaymentOption', isMultiple: true }, { path: 'businessHours', table: 'BusinessHour', isMultiple: true }, { path: 'project', table: 'Project' }, // NOT USED ] if (AmenityBookingOptionsProcess) { let AmenityBookingOptionsJson = readJson(`${config.root}/export/amenityBookingOptionses.json`) await processItems( AmenityBookingOptionsJson, 'AmenityBookingOption', AmenityBookingOptionsConnections ) AmenityBookingOptionsJson = [] } // const AmenityPaymentOptionConnections = [{ path: 'acceptedPaymentMethods', isScalar: true }] // if (AmenityPaymentOptionProcess) { // let AmenityPaymentOptionJson = readJson(`${config.root}/export/amenityPaymentOptions.json`) // await processItems( // AmenityPaymentOptionJson, // 'AmenityPaymentOption', // AmenityPaymentOptionConnections // ) // AmenityPaymentOptionJson = [] // } const PackageConnections = [ { path: 'image', table: 'Picture' }, { path: 'project', table: 'Project' }, { path: 'client', table: 'User' }, { path: 'seenBy', table: 'User', isMultiple: true }, { path: 'signatureImage', table: 'Picture' }, ] if (PackageProcess) { let PackageJson = readJson(`${config.root}/export/packages.json`) await processItems(PackageJson, 'Package', PackageConnections) PackageJson = [] } const ContactConnections = [ { path: 'avatar', table: 'Picture' }, { path: 'phone', table: 'Phone' }, { path: 'seenBy', table: 'User', isMultiple: true }, { path: 'project', table: 'Project' }, { path: 'projects', table: 'Project', isMultiple: true }, ] if (ContactProcess) { let ContactJson = readJson(`${config.root}/export/contacts.json`) await processItems(ContactJson, 'Contact', ContactConnections) ContactJson = [] } const RuleConnections = [ { path: 'seenBy', table: 'User', isMultiple: true }, { path: 'attachments', table: 'File', isMultiple: true }, { path: 'project', table: 'Project' }, { path: 'projects', table: 'Project', isMultiple: true }, ] if (RuleProcess) { let RuleJson = readJson(`${config.root}/export/rules.json`) await processItems(RuleJson, 'Rule', RuleConnections) RuleJson = [] } const OptionConnections = [ { path: 'image', table: 'Picture' }, { path: 'service', table: 'Service' }, { path: 'serviceProject', table: 'ServiceProject' }, { path: 'recurring', table: 'RECURRING_TYPE' }, { path: 'recurringType', table: 'RECURRING_TYPE' }, { path: 'categories', table: 'OptionCategory', isMultiple: true }, { path: 'addons', table: 'Addon', isMultiple: true }, ] if (OptionProcess) { let OptionJson = readJson(`${config.root}/export/options.json`) await processItems(OptionJson, 'Option', OptionConnections) OptionJson = [] } const AddonConnections = [{ path: 'addonsItems', table: 'AddonItem', isMultiple: true }] if (AddonProcess) { let AddonJson = readJson(`${config.root}/export/addons.json`) await processItems(AddonJson, 'Addon', AddonConnections) AddonJson = [] } const AddonItemConnections = [] if (AddonItemProcess) { let AddonItemJson = readJson(`${config.root}/export/addonItems.json`) await processItems(AddonItemJson, 'AddonItem', AddonItemConnections) AddonItemJson = [] } const OptionCategoryConnections = [ { path: 'options', table: 'Option', isMultiple: true }, { path: 'service', table: 'Service' }, ] if (OptionCategoryProcess) { let OptionCategoryJson = readJson(`${config.root}/export/optionCategories.json`) await processItems(OptionCategoryJson, 'OptionCategory', OptionCategoryConnections) OptionCategoryJson = [] } const AdConnections = [ { path: 'owner', table: 'User' }, { path: 'images', table: 'Picture', isMultiple: true }, { path: 'phone', table: 'Phone' }, { path: 'project', table: 'Project' }, ] if (AdProcess) { let AdJson = readJson(`${config.root}/export/ads.json`) await processItems(AdJson, 'Ad', AdConnections) AdJson = [] } const AddressConnections = [ // THIRD PARTY SYNCHRONIZATION { path: 'address1SyncStatuses', table: 'SyncStatus', isMultiple: true }, { path: 'apartmentNumberSyncStatuses', table: 'SyncStatus', isMultiple: true }, { path: 'zipSyncStatuses', table: 'SyncStatus', isMultiple: true }, { path: 'citySyncStatuses', table: 'SyncStatus', isMultiple: true }, { path: 'stateSyncStatuses', table: 'SyncStatus', isMultiple: true }, { path: 'countrySyncStatuses', table: 'SyncStatus', isMultiple: true }, { path: 'countryCodeSyncStatuses', table: 'SyncStatus', isMultiple: true }, { path: 'provinceCodeSyncStatuses', table: 'SyncStatus', isMultiple: true }, ] if (AddressProcess) { let AddressJson = readJson(`${config.root}/export/addresses.json`) await processItems(AddressJson, 'Address', AddressConnections) AddressJson = [] } const PostConnections = [ { path: 'coverImage', table: 'Picture' }, { path: 'audience', table: 'User', isMultiple: true }, { path: 'seenBy', table: 'User', isMultiple: true }, { path: 'attachments', table: 'File', isMultiple: true }, { path: 'poll', table: 'Poll' }, { path: 'signedProxies', table: 'Proxy', isMultiple: true }, { path: 'project', table: 'Project' }, { path: 'notifications', table: 'Notification', isMultiple: true }, { path: 'segments', table: 'Segment', isMultiple: true }, // TMP for proxy ] if (PostProcess) { let PostJson = readJson(`${config.root}/export/posts.json`) await processItems(PostJson, 'Post', PostConnections) PostJson = [] } const ProxyConnections = [ { path: 'signee', table: 'User' }, { path: 'property', table: 'Property' }, { path: 'pdf', table: 'File' }, ] if (ProxyProcess) { let ProxyJson = readJson(`${config.root}/export/proxies.json`) await processItems(ProxyJson, 'Proxy', ProxyConnections) ProxyJson = [] } const PollConnections = [ { path: 'questions', table: 'PollQuestion', isMultiple: true }, { path: 'completedByUsers', table: 'User', isMultiple: true }, { path: 'completedByParticipants', table: 'MeetingParticipant', isMultiple: true }, // NOT USING ANYMORE BUT NEEDED TO PUT HERE TO FIX SOMETHING WITH PRISMA ] if (PollProcess) { let PollJson = readJson(`${config.root}/export/polls.json`) await processItems(PollJson, 'Poll', PollConnections) PollJson = [] } const PollQuestionConnections = [ { path: 'answers', table: 'PollQuestionAnswer', isMultiple: true }, { path: 'winningAnswer', table: 'PollQuestionAnswer' }, ] if (PollQuestionProcess) { let PollQuestionJson = readJson(`${config.root}/export/pollQuestions.json`) await processItems(PollQuestionJson, 'PollQuestion', PollQuestionConnections) PollQuestionJson = [] } const PollQuestionAnswerConnections = [ { path: 'answeredBy', table: 'User', isMultiple: true }, { path: 'answeredByMeetingParticipants', table: 'MeetingParticipant', isMultiple: true }, ] if (PollQuestionAnswerProcess) { let PollQuestionAnswerJson = readJson(`${config.root}/export/pollQuestionAnswers.json`) await processItems(PollQuestionAnswerJson, 'PollQuestionAnswer', PollQuestionAnswerConnections) PollQuestionAnswerJson = [] } const NoteConnections = [ { path: 'status', table: 'NOTE_STATUS' }, { path: 'users', table: 'User', isMultiple: true }, { path: 'properties', table: 'Property', isMultiple: true }, { path: 'comments', table: 'NoteComment', isMultiple: true }, { path: 'project', table: 'Project' }, ] if (NoteProcess) { let NoteJson = readJson(`${config.root}/export/notes.json`) await processItems(NoteJson, 'Note', NoteConnections) NoteJson = [] } const NoteCommentConnections = [{ path: 'createdBy', table: 'User' }] if (NoteCommentProcess) { let NoteCommentJson = readJson(`${config.root}/export/noteComments.json`) await processItems(NoteCommentJson, 'NoteComment', NoteCommentConnections) NoteCommentJson = [] } const FileConnections = [{ path: 'seenBy', table: 'User', isMultiple: true }] if (FileProcess) { let FileJson = readJson(`${config.root}/export/files.json`) await processItems(FileJson, 'File', FileConnections) FileJson = [] } const FolderConnections = [ { path: 'files', table: 'File', isMultiple: true }, { path: 'folderParent', table: 'Folder' }, { path: 'segments', table: 'Segment', isMultiple: true }, { path: 'project', table: 'Project' }, ] if (FolderProcess) { let FolderJson = readJson(`${config.root}/export/folders.json`) await processItems(FolderJson, 'Folder', FolderConnections) FolderJson = [] } const AccountStatementConnections = [{ path: 'property', table: 'Property' }] if (AccountStatementProcess) { let AccountStatementJson = readJson(`${config.root}/export/accountStatements.json`) await processItems(AccountStatementJson, 'AccountStatement', AccountStatementConnections) AccountStatementJson = [] } const ThirdPartyVersionConnections = [] if (ThirdPartyVersionProcess) { let ThirdPartyVersionJson = readJson(`${config.root}/export/thirdPartyVersions.json`) await processItems(ThirdPartyVersionJson, 'ThirdPartyVersion', ThirdPartyVersionConnections) ThirdPartyVersionJson = [] } const MappedServiceConnections = [{ path: 'mappings', table: 'Mapping', isMultiple: true }] if (MappedServiceProcess) { let MappedServiceJson = readJson(`${config.root}/export/mappedServices.json`) await processItems(MappedServiceJson, 'MappedService', MappedServiceConnections) MappedServiceJson = [] } const MappingConnections = [{ path: 'mappedService', table: 'MappedService' }] if (MappingProcess) { let MappingJson = readJson(`${config.root}/export/mappings.json`) await processItems(MappingJson, 'Mapping', MappingConnections) MappingJson = [] } const SyncStatusConnections = [ { path: 'mapping', table: 'Mapping' }, { path: 'project', table: 'Project' }, ] if (SyncStatusProcess) { let SyncStatusJson = readJson(`${config.root}/export/syncStatuses.json`) await processItems(SyncStatusJson, 'SyncStatus', SyncStatusConnections) SyncStatusJson = [] } const MappedServiceSettingsConnections = [{ path: 'mappedService', table: 'MappedService' }] if (MappedServiceSettingsProcess) { let MappedServiceSettingsJson = readJson(`${config.root}/export/mappedServiceSettingses.json`) await processItems( MappedServiceSettingsJson, 'MappedServiceSetting', MappedServiceSettingsConnections ) MappedServiceSettingsJson = [] } // const CondoManagerCompteConnections = [{ path: 'project', table: 'Project' }] // if (condoManagerComptesProcess) { // let condoManagerComptesJson = readJson(`${config.root}/export/condoManagerComptes.json`) // await processItems(condoManagerComptesJson, 'condoManagerCompte', CondoManagerCompteConnections) // condoManagerComptesJson = [] // } const NotificationConnections = [ { path: 'user', table: 'User' }, { path: 'project', table: 'Project' }, { path: 'serviceProject', table: 'ServiceProject' }, { path: 'post', table: 'Post' }, { path: 'event', table: 'Event' }, // { path: 'data', table: 'Json' } ] if (NotificationProcess) { let NotificationJson1 = readJson(`${config.root}/export/notification1.json`) await processItems(NotificationJson1, 'Notification', NotificationConnections) NotificationJson1 = null let NotificationJson2 = readJson(`${config.root}/export/notification2.json`) await processItems(NotificationJson2, 'Notification', NotificationConnections) NotificationJson2 = null let NotificationJson3 = readJson(`${config.root}/export/notification3.json`) await processItems(NotificationJson3, 'Notification', NotificationConnections) NotificationJson3 = null let NotificationJson4 = readJson(`${config.root}/export/notification4.json`) await processItems(NotificationJson4, 'Notification', NotificationConnections) NotificationJson4 = null let NotificationJson5 = readJson(`${config.root}/export/notification5.json`) await processItems(NotificationJson5, 'Notification', NotificationConnections) NotificationJson5 = null let NotificationJson6 = readJson(`${config.root}/export/notification6.json`) await processItems(NotificationJson6, 'Notification', NotificationConnections) NotificationJson6 = null let NotificationJson7 = readJson(`${config.root}/export/notification7.json`) await processItems(NotificationJson7, 'Notification', NotificationConnections) NotificationJson7 = null let NotificationJson8 = readJson(`${config.root}/export/notification8.json`) await processItems(NotificationJson8, 'Notification', NotificationConnections) NotificationJson8 = null let NotificationJson9 = readJson(`${config.root}/export/notification9.json`) await processItems(NotificationJson9, 'Notification', NotificationConnections) NotificationJson9 = null let NotificationJson10 = readJson(`${config.root}/export/notification10.json`) await processItems(NotificationJson10, 'Notification', NotificationConnections) NotificationJson10 = null let NotificationJson11 = readJson(`${config.root}/export/notification11.json`) await processItems(NotificationJson11, 'Notification', NotificationConnections) NotificationJson11 = null let NotificationJson12 = readJson(`${config.root}/export/notification12.json`) await processItems(NotificationJson12, 'Notification', NotificationConnections) NotificationJson12 = null let NotificationJson13 = readJson(`${config.root}/export/notification13.json`) await processItems(NotificationJson13, 'Notification', NotificationConnections) NotificationJson13 = null let NotificationJson14 = readJson(`${config.root}/export/notification14.json`) await processItems(NotificationJson14, 'Notification', NotificationConnections) NotificationJson14 = null let NotificationJson15 = readJson(`${config.root}/export/notification15.json`) await processItems(NotificationJson15, 'Notification', NotificationConnections) NotificationJson15 = null let NotificationJson16 = readJson(`${config.root}/export/notification16.json`) await processItems(NotificationJson16, 'Notification', NotificationConnections) NotificationJson16 = null let NotificationJson17 = readJson(`${config.root}/export/notification17.json`) await processItems(NotificationJson17, 'Notification', NotificationConnections) NotificationJson17 = null let NotificationJson18 = readJson(`${config.root}/export/notification18.json`) await processItems(NotificationJson18, 'Notification', NotificationConnections) NotificationJson18 = null let NotificationJson19 = readJson(`${config.root}/export/notification19.json`) await processItems(NotificationJson19, 'Notification', NotificationConnections) NotificationJson19 = null } } // Just for testing... // function tellMeHowManyItemsIHave(model) { // prisma[model].findMany().then(items => { // console.log(`We have ${items.length} ${model}s`) // }) // } // tellMeHowManyItemsIHave('phone') start() // .then(() => start())