Skip to content

Commit

Permalink
Merge branch 'develop' into feat/#806-adding-OKR-module
Browse files Browse the repository at this point in the history
  • Loading branch information
abinandh15 committed Aug 1, 2020
2 parents 4780f27 + a35966a commit 8a205c1
Show file tree
Hide file tree
Showing 130 changed files with 2,023 additions and 1,244 deletions.
1 change: 1 addition & 0 deletions apps/api/package.json
Expand Up @@ -15,6 +15,7 @@
"build": "yarn ng build api",
"build:prod": "yarn ng build api --prod",
"seed": "yarn ts-node -r tsconfig-paths/register --project tsconfig.app.json src/app/core/seeds/index.ts",
"seed:all": "yarn ts-node -r tsconfig-paths/register --project tsconfig.app.json src/app/core/seeds/seedAll.ts",
"seed:prod": "yarn ng run api:seed -c=production"
},
"dependencies": {
Expand Down
11 changes: 7 additions & 4 deletions apps/api/src/app/core/seeds/SeedDataService.ts
Expand Up @@ -156,7 +156,7 @@ import {
import { Equipment } from '../../equipment/equipment.entity';
import { Contact } from '../../contact/contact.entity';

import { createRandomTimesheet } from '../../timesheet/timesheet/timesheet.seed';
import { createDefaultTimeSheet, createRandomTimesheet } from '../../timesheet/timesheet/timesheet.seed';
import { createRandomTask } from '../../tasks/task.seed';
import {
createDefaultOrganizationProjects,
Expand Down Expand Up @@ -212,9 +212,9 @@ import {
createRandomEquipments
} from '../../equipment/equipment.seed';
import { createRandomEquipmentSharing } from '../../equipment-sharing/equipment-sharing.seed';
import { createRandomProposals } from '../../proposal/proposal.seed';
import { createDefaultProposals, createRandomProposals } from '../../proposal/proposal.seed';
import { createRandomInvoiceItem } from '../../invoice-item/invoice-item.seed';
import { createRandomInvoice } from '../../invoice/invoice.seed';
import { createDefaultInvoice, createRandomInvoice } from '../../invoice/invoice.seed';
import {
createCandidateSkills,
createRandomCandidateSkills
Expand Down Expand Up @@ -731,6 +731,9 @@ export class SeedDataService {
await this.tryExecute(
createDefaultIntegrations(this.connection, integrationTypes)
);
await this.tryExecute(createDefaultTimeSheet(this.connection,this.defaultEmployees,this.defaultProjects,5));
await this.tryExecute(createDefaultProposals(this.connection,this.defaultEmployees,this.organizations,10));
await this.tryExecute(createDefaultInvoice(this.connection,this.organizations,10));
}

/**
Expand Down Expand Up @@ -1032,7 +1035,7 @@ export class SeedDataService {
createRandomTask(this.connection, this.defaultProjects)
);
await this.tryExecute(
createRandomTimesheet(this.connection, this.defaultProjects)
createRandomTimesheet(this.connection, this.defaultProjects,20)
);

await this.tryExecute(
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/app/core/seeds/index.ts
Expand Up @@ -14,6 +14,6 @@ import { SeedDataService } from './SeedDataService';
* */
(async () => {
const seedDataService = new SeedDataService();
await seedDataService.run(false);
await seedDataService.run(true);
process.exit(0);
})();
19 changes: 19 additions & 0 deletions apps/api/src/app/core/seeds/seedAll.ts
@@ -0,0 +1,19 @@
// Code from https://github.com/alexitaylor/angular-graphql-nestjs-postgres-starter-kit.
// MIT License, see https://github.com/alexitaylor/angular-graphql-nestjs-postgres-starter-kit/blob/master/LICENSE
// Copyright (c) 2019 Alexi Taylor

import { SeedDataService } from './SeedDataService';

/**
* WARNING: Running this file will DELETE all data in your database
* and generate and insert new, random data into your database.
*
* BE CAREFUL running this file in production env. It's possible to delete all production data.
* SeedData checks if environment is in production or not by checking src/environments/environment.ts file configs.
* If environment.production config is set to true, then the seeding process will only generate default roles and 2 default users.
* */
(async () => {
const seedDataService = new SeedDataService();
await seedDataService.run(false);
process.exit(0);
})();
@@ -1,8 +1,9 @@
import { Connection } from 'typeorm';
import { Tenant } from '../tenant/tenant.entity';
import { Employee, RecurringExpenseDefaultCategoriesEnum } from '@gauzy/models';
import { CurrenciesEnum, Employee, RecurringExpenseDefaultCategoriesEnum } from '@gauzy/models';
import { EmployeeRecurringExpense } from './employee-recurring-expense.entity';
import * as faker from 'faker';
import * as moment from 'moment';

export const createRandomEmployeeRecurringExpense = async (
connection: Connection,
Expand All @@ -22,32 +23,31 @@ export const createRandomEmployeeRecurringExpense = async (
for (const tenant of tenants) {
const tenantEmployees = tenantEmployeeMap.get(tenant);

for (const tenantEmployee of tenantEmployees) {
const employee = new EmployeeRecurringExpense();
employee.employeeId = tenantEmployee.id;
for (const [index, tenantEmployee] of tenantEmployees.entries()) {
const employee = new EmployeeRecurringExpense();
employee.employeeId = tenantEmployee.id;

const startDate = faker.date.past();
employee.startDay = startDate.getDate();
employee.startMonth = startDate.getMonth() + 1;
employee.startYear = startDate.getFullYear();
employee.startDate = startDate;

/* TODO: fix endDate generation for some entities only, most should not have end date really

const endDate = faker.date.past();
employee.endDay = endDate.getDate();
employee.endMonth = endDate.getMonth();
employee.endYear = endDate.getFullYear();
employee.endDate = endDate;
// TODO: fix endDate generation for some entities only, most should not have end date really
if (index % 2 === 0) { // new changes
const endDate = faker.date.between(new Date(startDate), moment(startDate).add(4, 'months').toDate());
employee.endDay = endDate.getDate();
employee.endMonth = endDate.getMonth();
employee.endYear = endDate.getFullYear();
employee.endDate = endDate;
}
// TODO: seed with random Categories from that enum, but make sure that SALARY exists in most of employees anyway (except contractors)
employee.categoryName =
RecurringExpenseDefaultCategoriesEnum.SALARY;

*/

// TODO: seed with random Categories from that enum, but make sure that SALARY exists in most of employees anyway (except contractors)
employee.categoryName =
RecurringExpenseDefaultCategoriesEnum.SALARY;

employee.value = Math.floor(Math.random() * 999) + 1;
employee.currency = currency[Math.floor(Math.random() * 2)];
employee.value = faker.random.number(999); // new changes
employee.currency = CurrenciesEnum.USD; // new changes

// TODO: some expenses should have a parent if they change "over time"
employee.parentRecurringExpenseId = null;
Expand Down
14 changes: 13 additions & 1 deletion apps/api/src/app/employee/employee.seed.ts
Expand Up @@ -4,7 +4,8 @@ import { Employee } from './employee.entity';
import { Organization } from '../organization/organization.entity';
import { User } from '../user/user.entity';
import { date as fakerDate } from 'faker';
import { ISeedUsers, LanguagesEnum } from '@gauzy/models';
import { CurrenciesEnum, ISeedUsers, LanguagesEnum, PayPeriodEnum } from '@gauzy/models';
import * as faker from 'faker';

export const createDefaultEmployees = async (
connection: Connection,
Expand Down Expand Up @@ -290,6 +291,13 @@ export const createDefaultEmployees = async (
defaultEmployees.filter((e) => e.email === employee.user.email)[0]
.endWork
);

// TODO: check below value as its correct or not, and into frontend too
employee.payPeriod = faker.random.arrayElement(Object.keys(PayPeriodEnum));
employee.billRateValue = faker.random.number(100);
employee.billRateCurrency = faker.random.arrayElement(Object.keys(CurrenciesEnum));
employee.reWeeklyLimit = faker.random.number(40);

await insertEmployee(connection, employee);
employees.push(employee);
counter++;
Expand Down Expand Up @@ -323,6 +331,10 @@ export const createRandomEmployees = async (
employee.endWork = null;
employee.startedWorkOn = fakerDate.past(index % 5);
employee.tenant = tenant;
employee.payPeriod = faker.random.arrayElement(Object.keys(PayPeriodEnum));
employee.billRateValue = faker.random.number(100);
employee.billRateCurrency = faker.random.arrayElement(Object.keys(CurrenciesEnum));
employee.reWeeklyLimit = faker.random.number(40);

if (employee.user) {
employees.push(employee);
Expand Down
3 changes: 3 additions & 0 deletions apps/api/src/app/export_import/export-all.module.ts
Expand Up @@ -195,6 +195,7 @@ import { ProductCategory } from '../product-category/product-category.entity';
import { ProductCategoryService } from '../product-category/product-category.service';
import { OrganizationDocuments } from '../organization-documents/organization-documents.entity';
import { OrganizationDocumentsService } from '../organization-documents/organization-documents.service';
import { UpworkReportService } from '../upwork/upwork-report.service';

@Module({
imports: [
Expand Down Expand Up @@ -421,6 +422,7 @@ import { OrganizationDocumentsService } from '../organization-documents/organiza
TimeSlotService,

UpworkService,
UpworkReportService,
UserService,
UserOrganizationService
],
Expand Down Expand Up @@ -532,6 +534,7 @@ import { OrganizationDocumentsService } from '../organization-documents/organiza
TimeSlotService,

UpworkService,
UpworkReportService,
UserService,
UserOrganizationService
]
Expand Down
6 changes: 4 additions & 2 deletions apps/api/src/app/invite/invite.seed.ts
Expand Up @@ -9,6 +9,8 @@ import { sign } from 'jsonwebtoken';
import { environment as env } from '@env-api/environment';
import { User } from '../user/user.entity';

import * as moment from 'moment';

export const createRandomEmployeeInviteSent = async (
connection: Connection,
tenants: Tenant[],
Expand All @@ -21,15 +23,15 @@ export const createRandomEmployeeInviteSent = async (

for (const tenant of tenants) {
const role = await connection.getRepository(Role).find({
where: [{ tenant: tenant }, { name: RolesEnum.EMPLOYEE }]
where: [{ tenant: tenant, name: RolesEnum.EMPLOYEE}]
});
const orgs = tenantOrganizationsMap.get(tenant);
const admins = tenantSuperAdminMap.get(tenant);
orgs.forEach((org) => {
for (let i = 0; i < noOfInvitesPerOrganization; i++) {
let invitee = new Invite();
invitee.email = faker.internet.email();
invitee.expireDate = faker.date.future();
invitee.expireDate = faker.date.between(new Date(), moment(new Date()).add(30, 'days').toDate());
invitee.invitedBy = faker.random.arrayElement(admins);
invitee.organizationId = org.id;
invitee.organization = org;
Expand Down
57 changes: 57 additions & 0 deletions apps/api/src/app/invoice/invoice.seed.ts
Expand Up @@ -10,6 +10,63 @@ import {
InvoiceTypeEnum
} from '@gauzy/models';

export const createDefaultInvoice = async (
connection: Connection,
defaultOrganizations: Organization[],
noOfInvoicePerOrganization: number
) => {
let invoices: Invoice[] = [];

for (const organization of defaultOrganizations) {
const tags = await connection.manager.find(Tag, {
where: [{ organization: organization }]
});
for (let i = 0; i < noOfInvoicePerOrganization; i++) {
let invoice = new Invoice();
// let invoiceItem = faker.random.arrayElement(invoiceItems);
invoice.tags = [faker.random.arrayElement(tags)];
invoice.invoiceDate = faker.date.past(0.2);
invoice.invoiceNumber = faker.random.number({
min: 1,
max: 9999999
});
invoice.dueDate = faker.date.recent(50);
invoice.currency = faker.random.arrayElement(
Object.values(CurrenciesEnum)
);
invoice.discountValue = faker.random.number({
min: 1,
max: 10
});
invoice.paid = faker.random.boolean();
invoice.tax = faker.random.number({ min: 1, max: 10 });
invoice.tax2 = faker.random.number({ min: 1, max: 10 });
invoice.terms = 'Term and Setting Applied';
invoice.isEstimate = faker.random.boolean();
if (invoice.isEstimate) {
invoice.isAccepted = faker.random.boolean();
}
invoice.discountType = faker.random.arrayElement(
Object.values(DiscountTaxTypeEnum)
);
invoice.taxType = faker.random.arrayElement(
Object.values(DiscountTaxTypeEnum)
);
invoice.tax2Type = faker.random.arrayElement(
Object.values(DiscountTaxTypeEnum)
);
invoice.invoiceType = faker.random.arrayElement(
Object.values(InvoiceTypeEnum)
);
invoice.organizationId = organization.id;
invoice.status = 'Active';
invoices.push(invoice);
}
}

await connection.manager.save(invoices);
};

export const createRandomInvoice = async (
connection: Connection,
tenants: Tenant[],
Expand Down
23 changes: 23 additions & 0 deletions apps/api/src/app/organization/organization.seed.ts
Expand Up @@ -53,6 +53,18 @@ export const createDefaultOrganizations = async (
defaultOrganization.bonusPercentage = 10;
defaultOrganization.registrationDate = faker.date.past(5);

defaultOrganization.overview = faker.name.jobDescriptor();
defaultOrganization.short_description = faker.name.jobDescriptor();
defaultOrganization.client_focus = faker.name.jobDescriptor();
defaultOrganization.show_profits = false;
defaultOrganization.show_bonuses_paid = false;
defaultOrganization.show_income = false;
defaultOrganization.show_total_hours = false;
defaultOrganization.show_projects_count = true;
defaultOrganization.show_minimum_project_size = true;
defaultOrganization.show_clients_count = true;
defaultOrganization.banner = faker.name.jobDescriptor();

defaultOrganizations.push(defaultOrganization);
});

Expand Down Expand Up @@ -97,6 +109,17 @@ export const createRandomOrganizations = async (
);
organization.tenant = tenant;
organization.invitesAllowed = true;
organization.overview = faker.name.jobDescriptor();
organization.short_description = faker.name.jobDescriptor();
organization.client_focus = faker.name.jobDescriptor();
organization.show_profits = false;
organization.show_bonuses_paid = false;
organization.show_income = false;
organization.show_total_hours = false;
organization.show_projects_count = true;
organization.show_minimum_project_size = true;
organization.show_clients_count = true;
organization.banner = faker.name.jobDescriptor();

const { bonusType, bonusPercentage } = randomBonus();
organization.bonusType = bonusType;
Expand Down
27 changes: 27 additions & 0 deletions apps/api/src/app/proposal/proposal.seed.ts
Expand Up @@ -6,6 +6,33 @@ import { Tenant } from '../tenant/tenant.entity';
import { Employee } from '../employee/employee.entity';
import { Organization } from '../organization/organization.entity';

export const createDefaultProposals = async (
connection: Connection,
employees: Employee[],
organizations: Organization[],
noOfProposalsPerOrganization: number
): Promise<Proposal[]> => {
let proposals: Proposal[] = [];
for (const organization of organizations) {
const tags = await connection.manager.find(Tag, { where: [{ organization: organization }] });
for (let i = 0; i < noOfProposalsPerOrganization; i++) {
let proposal = new Proposal();
proposal.employee = faker.random.arrayElement(employees);
proposal.jobPostUrl = faker.internet.url();
proposal.jobPostContent = faker.name.jobTitle();
proposal.organization = organization;
proposal.status = faker.random.arrayElement(['ACCEPTED', 'SENT']);
proposal.tags = [faker.random.arrayElement(tags)];
proposal.valueDate = faker.date.recent();
proposal.proposalContent = faker.name.jobDescriptor();
proposals.push(proposal);
}
}

return await connection.manager.save(proposals);

};

export const createRandomProposals = async (
connection: Connection,
tenants: Tenant[],
Expand Down
16 changes: 7 additions & 9 deletions apps/api/src/app/timesheet/time-log/time-log.seed.ts
Expand Up @@ -14,13 +14,9 @@ import { Screenshot } from '../screenshot.entity';
export const createRandomTimeLogs = async (
connection: Connection,
timeSheets: Timesheet[],
defaultProjects: OrganizationProjects[]
defaultProjects: OrganizationProjects[],
noOfTimeLogsPerTimeSheet
) => {
timeSheets = await connection
.getRepository(Timesheet)
.createQueryBuilder()
.getMany();

const allEmployees = await connection
.getRepository(Employee)
.createQueryBuilder()
Expand Down Expand Up @@ -108,9 +104,11 @@ export const createRandomTimeLogs = async (
).map((timeSlot) => {
timeSlot.employee = timelog.employee;
if (logType === TimeLogType.TRACKED) {
screenshotsPromise.push(
createRandomScreenshot(timeSlot)
);
for(let i = 0; i < noOfTimeLogsPerTimeSheet; i++) {
screenshotsPromise.push(
createRandomScreenshot(timeSlot)
);
}
}
return timeSlot;
});
Expand Down

0 comments on commit 8a205c1

Please sign in to comment.