const db = require('../models'); const Users = db.users; const Cases = db.cases; const ClientUsers = db.client_users; const MenuPrivileges = db.menu_privileges; const Clients = db.clients; const CasesData = [ { case_number: 'C-001', // type code here for "relation_one" field case_title: 'Breach of Contract', case_type: 'Civil', status: 'Closed', priority: 'Low', court: 'Supreme Court', opposite_party: 'XYZ Ltd.', filing_date: new Date('2023-01-15T00:00:00Z'), next_hearing_date: new Date('2023-02-20T00:00:00Z'), claim_amount: 50000, interest_claimed: 5000, last_hearing_date: new Date('2023-01-30T00:00:00Z'), purpose_of_next_hearing: 'Evidence Submission', firm_deliveries: 'Documents prepared', client_deliveries: 'Review documents', case_description: 'Case regarding breach of contract with XYZ Ltd.', // type code here for "files" field // type code here for "relation_one" field }, { case_number: 'C-002', // type code here for "relation_one" field case_title: 'Patent Infringement', case_type: 'Intellectual Property', status: 'Dismissed', priority: 'Low', court: 'High Court', opposite_party: 'ABC Corp.', filing_date: new Date('2023-02-01T00:00:00Z'), next_hearing_date: new Date('2023-03-15T00:00:00Z'), claim_amount: 100000, interest_claimed: 10000, last_hearing_date: new Date('2023-02-25T00:00:00Z'), purpose_of_next_hearing: 'Witness Testimony', firm_deliveries: 'Prepare witness', client_deliveries: 'Provide evidence', case_description: 'Patent infringement case against ABC Corp.', // type code here for "files" field // type code here for "relation_one" field }, { case_number: 'C-003', // type code here for "relation_one" field case_title: 'Employment Dispute', case_type: 'Labor', status: 'Closed', priority: 'Low', court: 'District Court', opposite_party: 'John Smith', filing_date: new Date('2023-03-10T00:00:00Z'), next_hearing_date: new Date('2023-04-05T00:00:00Z'), claim_amount: 20000, interest_claimed: 2000, last_hearing_date: new Date('2023-03-20T00:00:00Z'), purpose_of_next_hearing: 'Settlement Discussion', firm_deliveries: 'Draft settlement', client_deliveries: 'Review settlement', case_description: 'Dispute regarding employment termination with John Smith.', // type code here for "files" field // type code here for "relation_one" field }, ]; const ClientUsersData = [ { first_name: 'Alice', last_name: 'Williams', email: 'alice.williams@acme.com', mobile: '4455667788', password: 'password123', // type code here for "images" field // type code here for "relation_one" field // type code here for "relation_one" field }, { first_name: 'Bob', last_name: 'Taylor', email: 'bob.taylor@globaltech.com', mobile: '5566778899', password: 'password123', // type code here for "images" field // type code here for "relation_one" field // type code here for "relation_one" field }, { first_name: 'Charlie', last_name: 'Anderson', email: 'charlie.anderson@innovate.com', mobile: '6677889900', password: 'password123', // type code here for "images" field // type code here for "relation_one" field // type code here for "relation_one" field }, ]; const MenuPrivilegesData = [ { // type code here for "relation_one" field menu_name: 'Dashboard', read_access: true, write_access: true, // type code here for "relation_one" field }, { // type code here for "relation_one" field menu_name: 'Client Management', read_access: true, write_access: false, // type code here for "relation_one" field }, { // type code here for "relation_one" field menu_name: 'Case Management', read_access: true, write_access: true, // type code here for "relation_one" field }, ]; const ClientsData = [ { name: 'Sheldon Glashow', }, { name: 'Ernst Mayr', }, { name: 'Jean Baptiste Lamarck', }, ]; // Similar logic for "relation_many" async function associateUserWithClient() { const relatedClient0 = await Clients.findOne({ offset: Math.floor(Math.random() * (await Clients.count())), }); const User0 = await Users.findOne({ order: [['id', 'ASC']], offset: 0, }); if (User0?.setClient) { await User0.setClient(relatedClient0); } const relatedClient1 = await Clients.findOne({ offset: Math.floor(Math.random() * (await Clients.count())), }); const User1 = await Users.findOne({ order: [['id', 'ASC']], offset: 1, }); if (User1?.setClient) { await User1.setClient(relatedClient1); } const relatedClient2 = await Clients.findOne({ offset: Math.floor(Math.random() * (await Clients.count())), }); const User2 = await Users.findOne({ order: [['id', 'ASC']], offset: 2, }); if (User2?.setClient) { await User2.setClient(relatedClient2); } } async function associateCaseWithClient() { const relatedClient0 = await Clients.findOne({ offset: Math.floor(Math.random() * (await Clients.count())), }); const Case0 = await Cases.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Case0?.setClient) { await Case0.setClient(relatedClient0); } const relatedClient1 = await Clients.findOne({ offset: Math.floor(Math.random() * (await Clients.count())), }); const Case1 = await Cases.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Case1?.setClient) { await Case1.setClient(relatedClient1); } const relatedClient2 = await Clients.findOne({ offset: Math.floor(Math.random() * (await Clients.count())), }); const Case2 = await Cases.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Case2?.setClient) { await Case2.setClient(relatedClient2); } } async function associateCaseWithClient() { const relatedClient0 = await Clients.findOne({ offset: Math.floor(Math.random() * (await Clients.count())), }); const Case0 = await Cases.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Case0?.setClient) { await Case0.setClient(relatedClient0); } const relatedClient1 = await Clients.findOne({ offset: Math.floor(Math.random() * (await Clients.count())), }); const Case1 = await Cases.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Case1?.setClient) { await Case1.setClient(relatedClient1); } const relatedClient2 = await Clients.findOne({ offset: Math.floor(Math.random() * (await Clients.count())), }); const Case2 = await Cases.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Case2?.setClient) { await Case2.setClient(relatedClient2); } } async function associateClientUserWithClient() { const relatedClient0 = await Clients.findOne({ offset: Math.floor(Math.random() * (await Clients.count())), }); const ClientUser0 = await ClientUsers.findOne({ order: [['id', 'ASC']], offset: 0, }); if (ClientUser0?.setClient) { await ClientUser0.setClient(relatedClient0); } const relatedClient1 = await Clients.findOne({ offset: Math.floor(Math.random() * (await Clients.count())), }); const ClientUser1 = await ClientUsers.findOne({ order: [['id', 'ASC']], offset: 1, }); if (ClientUser1?.setClient) { await ClientUser1.setClient(relatedClient1); } const relatedClient2 = await Clients.findOne({ offset: Math.floor(Math.random() * (await Clients.count())), }); const ClientUser2 = await ClientUsers.findOne({ order: [['id', 'ASC']], offset: 2, }); if (ClientUser2?.setClient) { await ClientUser2.setClient(relatedClient2); } } async function associateClientUserWithClient() { const relatedClient0 = await Clients.findOne({ offset: Math.floor(Math.random() * (await Clients.count())), }); const ClientUser0 = await ClientUsers.findOne({ order: [['id', 'ASC']], offset: 0, }); if (ClientUser0?.setClient) { await ClientUser0.setClient(relatedClient0); } const relatedClient1 = await Clients.findOne({ offset: Math.floor(Math.random() * (await Clients.count())), }); const ClientUser1 = await ClientUsers.findOne({ order: [['id', 'ASC']], offset: 1, }); if (ClientUser1?.setClient) { await ClientUser1.setClient(relatedClient1); } const relatedClient2 = await Clients.findOne({ offset: Math.floor(Math.random() * (await Clients.count())), }); const ClientUser2 = await ClientUsers.findOne({ order: [['id', 'ASC']], offset: 2, }); if (ClientUser2?.setClient) { await ClientUser2.setClient(relatedClient2); } } async function associateMenuPrivilegeWithUser() { const relatedUser0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const MenuPrivilege0 = await MenuPrivileges.findOne({ order: [['id', 'ASC']], offset: 0, }); if (MenuPrivilege0?.setUser) { await MenuPrivilege0.setUser(relatedUser0); } const relatedUser1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const MenuPrivilege1 = await MenuPrivileges.findOne({ order: [['id', 'ASC']], offset: 1, }); if (MenuPrivilege1?.setUser) { await MenuPrivilege1.setUser(relatedUser1); } const relatedUser2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const MenuPrivilege2 = await MenuPrivileges.findOne({ order: [['id', 'ASC']], offset: 2, }); if (MenuPrivilege2?.setUser) { await MenuPrivilege2.setUser(relatedUser2); } } async function associateMenuPrivilegeWithClient() { const relatedClient0 = await Clients.findOne({ offset: Math.floor(Math.random() * (await Clients.count())), }); const MenuPrivilege0 = await MenuPrivileges.findOne({ order: [['id', 'ASC']], offset: 0, }); if (MenuPrivilege0?.setClient) { await MenuPrivilege0.setClient(relatedClient0); } const relatedClient1 = await Clients.findOne({ offset: Math.floor(Math.random() * (await Clients.count())), }); const MenuPrivilege1 = await MenuPrivileges.findOne({ order: [['id', 'ASC']], offset: 1, }); if (MenuPrivilege1?.setClient) { await MenuPrivilege1.setClient(relatedClient1); } const relatedClient2 = await Clients.findOne({ offset: Math.floor(Math.random() * (await Clients.count())), }); const MenuPrivilege2 = await MenuPrivileges.findOne({ order: [['id', 'ASC']], offset: 2, }); if (MenuPrivilege2?.setClient) { await MenuPrivilege2.setClient(relatedClient2); } } module.exports = { up: async (queryInterface, Sequelize) => { await Cases.bulkCreate(CasesData); await ClientUsers.bulkCreate(ClientUsersData); await MenuPrivileges.bulkCreate(MenuPrivilegesData); await Clients.bulkCreate(ClientsData); await Promise.all([ // Similar logic for "relation_many" await associateUserWithClient(), await associateCaseWithClient(), await associateCaseWithClient(), await associateClientUserWithClient(), await associateClientUserWithClient(), await associateMenuPrivilegeWithUser(), await associateMenuPrivilegeWithClient(), ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('cases', null, {}); await queryInterface.bulkDelete('client_users', null, {}); await queryInterface.bulkDelete('menu_privileges', null, {}); await queryInterface.bulkDelete('clients', null, {}); }, };