UNPKG

json-api-nestjs

Version:
115 lines 3.73 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.pullAddress = pullAddress; exports.pullComment = pullComment; exports.pullNote = pullNote; exports.pullRole = pullRole; exports.pullUser = pullUser; exports.pullUserGroup = pullUserGroup; exports.pullAllData = pullAllData; const faker_1 = require("@faker-js/faker"); const entities_1 = require("../entities"); async function pullAddress() { const address = new entities_1.Addresses(); address.city = faker_1.faker.location.city(); address.country = faker_1.faker.location.country(); address.arrayField = [ faker_1.faker.string.alphanumeric(5), faker_1.faker.string.alphanumeric(5), ]; address.state = faker_1.faker.location.state(); return address; } async function pullComment() { const comment = new entities_1.Comments(); comment.text = faker_1.faker.lorem.paragraph(faker_1.faker.number.int(5)); comment.kind = entities_1.CommentKind.Comment; return comment; } async function pullNote() { const note = new entities_1.Notes(); note.text = faker_1.faker.lorem.paragraph(faker_1.faker.number.int(5)); return note; } async function pullRole() { const role = new entities_1.Roles(); role.key = faker_1.faker.string.alphanumeric(5); role.name = faker_1.faker.word.words(); return role; } async function pullUser() { const user = new entities_1.Users(); user.firstName = faker_1.faker.person.firstName(); user.lastName = faker_1.faker.person.lastName(); user.isActive = faker_1.faker.datatype.boolean(); user.login = faker_1.faker.internet.userName({ lastName: user.lastName, firstName: user.firstName, }); user.testReal = [faker_1.faker.number.float({ fractionDigits: 4 })]; user.testArrayNull = null; user.testDate = faker_1.faker.date.anytime(); return user; } async function pullUserGroup() { const userGroup = new entities_1.UserGroups(); userGroup.label = faker_1.faker.string.alphanumeric(5); return userGroup; } async function pullAllData(em) { const user = await pullUser(); const address1 = await pullAddress(); const address2 = await pullAddress(); const note1 = await pullNote(); const note2 = await pullNote(); const note3 = await pullNote(); const comment1 = await pullComment(); const comment2 = await pullComment(); const comment3 = await pullComment(); const comment4 = await pullComment(); const userGroup1 = await pullUserGroup(); const userGroup2 = await pullUserGroup(); const userGroup3 = await pullUserGroup(); const role1 = await pullRole(); const role2 = await pullRole(); const role3 = await pullRole(); const roleX1 = await pullRole(); const roleX2 = await pullRole(); const roleX3 = await pullRole(); const managerUser = await pullUser(); user.addresses = address1; address1.user = user; user.notes.add(note1, note2, note3); user.comments.add(comment1, comment2, comment3, comment4); user.userGroup = userGroup1; user.roles.add(roleX1, roleX2, roleX3); user.manager = managerUser; managerUser.addresses = address2; managerUser.userGroup = userGroup3; managerUser.roles.add(role1, role2); await em.persistAndFlush([ user, address1, address2, note1, note2, note3, comment1, comment2, comment3, comment4, userGroup1, userGroup2, userGroup3, role1, role2, role3, roleX1, roleX2, roleX3, managerUser, ]); await em.flush(); return user; } //# sourceMappingURL=pull-data.js.map