UNPKG

@sync-in/server

Version:

The secure, open-source platform for file storage, sharing, collaboration, and sync

92 lines (91 loc) 3.58 kB
/* * Copyright (C) 2012-2025 Johan Legrand <johan.legrand@sync-in.com> * This file is part of Sync-in | The open source file sync and share solution * See the LICENSE file for licensing details */ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "usersAndGroups", { enumerable: true, get: function() { return usersAndGroups; } }); const _faker = require("@faker-js/faker"); const _user = require("../../../../applications/users/constants/user"); const _groupsschema = require("../../../../applications/users/schemas/groups.schema"); const _usersgroupsschema = require("../../../../applications/users/schemas/users-groups.schema"); const _usersschema = require("../../../../applications/users/schemas/users.schema"); const _functions = require("../../../../common/functions"); const _db = require("../db"); const alreadyUsed = [ 'sync-in', 'support@sync-in.com' ]; const usersAndGroups = async ()=>{ const newUsers = [ { login: 'sync-in', email: 'support@sync-in.com', firstName: 'Sync-in', lastName: 'Admin', role: _user.USER_ROLE.ADMINISTRATOR, password: await (0, _functions.hashPassword)('password'), permissions: Object.values(_user.USER_PERMISSION).join(',') } ]; const newGroups = []; for(let i = 0; i < 10; i++){ let login = _faker.faker.person.firstName(); let email = _faker.faker.internet.email(); while(alreadyUsed.includes(login) || alreadyUsed.includes(email)){ login = _faker.faker.person.firstName(); email = _faker.faker.internet.email(); } alreadyUsed.push(login, email); newUsers.push({ login: login, email: email, firstName: _faker.faker.person.firstName(), lastName: _faker.faker.person.lastName(), password: await (0, _functions.hashPassword)('password'), permissions: _faker.faker.helpers.arrayElements(Object.values(_user.USER_PERMISSION)).join(',') }); } for(let i = 0; i < 5; i++){ let name = _faker.faker.commerce.department(); while(alreadyUsed.includes(name)){ name = _faker.faker.commerce.department(); } alreadyUsed.push(name); newGroups.push({ name: name, description: _faker.faker.company.buzzPhrase(), type: 0 }); } const db = await (0, _db.getDB)(); console.log('Seed start'); const usersInfo = (await db.insert(_usersschema.users).values(newUsers))[0]; console.log('users: ', usersInfo.info); const groupsInfo = (await db.insert(_groupsschema.groups).values(newGroups))[0]; console.log('groups: ', groupsInfo.info); const usersId = (await db.select({ id: _usersschema.users.id }).from(_usersschema.users)).map((r)=>r.id); const groupsId = (await db.select({ id: _groupsschema.groups.id }).from(_groupsschema.groups)).map((r)=>r.id); const newUsersGroups = usersId.map((uid)=>({ userId: uid, groupId: groupsId[Math.floor(Math.random() * groupsId.length)] })); const usersGroupsInfo = (await db.insert(_usersgroupsschema.usersGroups).values(newUsersGroups))[0]; console.log('users & groups: ', usersGroupsInfo.info); db.$client.end(); }; if (require.main === module) { usersAndGroups().then(()=>console.log('Seed done')); } //# sourceMappingURL=usersgroups.js.map