Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:erxes/erxes into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Wlkr123 committed Sep 26, 2023
2 parents 8d26b53 + 78a7883 commit 2fe3255
Show file tree
Hide file tree
Showing 17 changed files with 311 additions and 132 deletions.
5 changes: 2 additions & 3 deletions cli/commands/update.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
const fse = require("fs-extra");
const execa = require("execa");
const start = require('./start');
const { filePath, log, execCommand } = require('./utils');
const { execSync } = require('child_process');

module.exports = async function() {
try {
log('Stopping pm2 processes ...');

// stop services
try {
await execa("pm2", ["delete", 'all']);
execSync("pm2 delete all", { stdio: 'inherit' });
} catch (e) {
console.log(e.message);
}
Expand Down
14 changes: 3 additions & 11 deletions cli/commands/utils.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const chalk = require('chalk');
const execa = require('execa');
const fs = require('fs');
const cliProgress = require('cli-progress');
const request = require('request');
const fse = require('fs-extra');
const { resolve } = require('path');
const exec = require('child_process').exec;
const colors = require('colors');
const { execSync } = require('child_process');

const filePath = pathName => {
if (pathName) {
Expand Down Expand Up @@ -145,14 +145,6 @@ module.exports.downloadLatesVersion = async configs => {
await fse.copy(filePath('build.tar.gz'), filePath('build-backup.tar.gz'));
};

const runCommand = (command, args, pipe) => {
if (pipe) {
return execa(command, args).stdout.pipe(process.stdout);
}

return execa(command, args);
};

module.exports.startServices = async configs => {
log('Starting services using pm2 ...');

Expand Down Expand Up @@ -482,7 +474,8 @@ module.exports.startServices = async configs => {
)}`
);

return runCommand('pm2', ['start', filePath('ecosystem.config.js')], false);
const ecosystemPath = filePath('ecosystem.config.js');
return execSync(`pm2 start ${ecosystemPath}`);
};

const generateNginxConf = async ({
Expand Down Expand Up @@ -555,6 +548,5 @@ const generateNginxConf = async ({
);
};

module.exports.runCommand = runCommand;
module.exports.downloadFile = downloadFile;
module.exports.execCurl = execCurl;
33 changes: 12 additions & 21 deletions cli/installer/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@

var amqplib = require('amqplib');
var shell = require('shelljs');

var open = amqplib.connect(process.env.RABBITMQ_HOST);
var queueName = 'managePluginInstall';

var runCommand = (command, method='exec') => {
return new Promise((resolve) => {
setTimeout(() => {
shell[method](command);
resolve('done');
}, 500)
});
}
const { execSync } = require('child_process');

var sleep = ms => {
return new Promise(resolve => {
Expand Down Expand Up @@ -50,43 +41,43 @@ open

sendMessage(ch, 'started');

await runCommand('..', 'cd');
execSync('cd ..');

// Update configs.json
await runCommand(`npm run erxes installer-update-configs ${data.type} ${data.name}`);
execSync(`npm run erxes installer-update-configs ${data.type} ${data.name}`);

if (data.type === 'install') {
sendMessage(ch, 'Running up ....');
await runCommand(`npm run erxes up -- --fromInstaller`);
execSync(`npm run erxes up -- --fromInstaller`);

sendMessage(ch, 'Syncing ui ....');
await runCommand(`npm run erxes syncui ${data.name}`);
execSync(`npm run erxes syncui ${data.name}`);

sendMessage(ch, 'Restarting coreui ....');
await runCommand(`npm run erxes restart coreui`);
execSync(`npm run erxes restart coreui`);

sendMessage(ch, 'Waiting for 10 seconds for plugin api....');
await sleep(10000);

sendMessage(ch, 'Restarting gateway ...');
await runCommand(`npm run erxes restart gateway`);
execSync(`npm run erxes restart gateway`);
}

if (data.type === 'uninstall') {
sendMessage(ch, 'Running up');
await runCommand(`npm run erxes up -- --fromInstaller`);
execSync(`npm run erxes up -- --fromInstaller`);

sendMessage(ch, `Removing ${data.name} service ....`);
await runCommand(`npm run erxes remove-service erxes_plugin_${data.name}_api`);
execSync(`npm run erxes remove-service erxes_plugin_${data.name}_api`);

sendMessage(ch, `Restarting coreui ....`);
await runCommand(`npm run erxes restart coreui`);
execSync(`npm run erxes restart coreui`);

sendMessage(ch, `Restarting gateway ....`);
await runCommand(`npm run erxes restart gateway`);
execSync(`npm run erxes restart gateway`);
}

await runCommand('installer', 'cd');
execSync('cd installer');

sendMessage(ch, `done`);

Expand Down
4 changes: 1 addition & 3 deletions cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "erxes",
"version": "0.4.24",
"version": "0.4.25",
"description": "Free and open fair-code licensed all-in-one growth marketing & management software",
"homepage": "https://erxes.io",
"repository": "https://github.com/erxes/erxes",
Expand All @@ -25,15 +25,13 @@
"colors": "^1.4.0",
"commander": "^6.2.0",
"dotenv": "^16.0.3",
"execa": "^4.1.0",
"figlet": "^1.5.0",
"fs-extra": "^9.0.1",
"jsonwebtoken": "^8.5.1",
"kill-port": "^1.6.1",
"lodash": "^4.17.21",
"pm2": "^5.2.2",
"request": "^2.88.2",
"shelljs": "^0.8.5",
"yaml": "^1.10.2"
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import { PRODUCT_STATUSES } from '../../../models/definitions/products';
import { escapeRegExp } from '@erxes/api-utils/src/core';
import { IContext, IModels } from '../../../connectionResolver';
import messageBroker, { sendTagsMessage } from '../../../messageBroker';
import { getSimilaritiesProducts } from '../../../maskUtils';
import {
getSimilaritiesProducts,
getSimilaritiesProductsCount
} from '../../../maskUtils';
import { Builder, countBySegment, countByTag } from '../../../utils';

interface IQueryParams {
Expand Down Expand Up @@ -236,6 +239,10 @@ const productQueries = {
params
);

if (params.groupedSimilarity) {
return await getSimilaritiesProductsCount(models, filter, params);
}

return models.Products.find(filter).count();
},

Expand Down
62 changes: 56 additions & 6 deletions packages/plugin-products-api/src/maskUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ export const checkSameMaskConfig = async (models: IModels, doc: IProduct) => {
return undefined;
};

export const groupBySameMasksAggregator = () => {
return [
export const groupBySameMasksAggregator = (isCount = false) => {
const sameArr = [
{
$addFields: {
sameMasksLen: {
Expand All @@ -197,7 +197,28 @@ export const groupBySameMasksAggregator = () => {
},
{
$unwind: '$sameMasks'
},
}
];

if (isCount) {
return [
...sameArr,
{
$group: {
_id: { sameMasks: '$sameMasks' },
product: { $first: '$code' }
}
},
{
$group: {
_id: { code: '$product' }
}
}
];
}

return [
...sameArr,
{ $sort: { 'product.code': 1 } },
{
$group: {
Expand All @@ -217,8 +238,8 @@ export const groupBySameMasksAggregator = () => {
];
};

export const groupByCategoryAggregator = () => {
return [
export const groupByCategoryAggregator = (isCount = false) => {
const sameArr = [
{
$lookup: {
from: 'product_categories',
Expand Down Expand Up @@ -248,7 +269,22 @@ export const groupByCategoryAggregator = () => {
}
}
}
},
}
];

if (isCount) {
return [
...sameArr,
{
$group: {
_id: { same: '$same' }
}
}
];
}

return [
...sameArr,
{
$group: {
_id: { same: '$same' },
Expand Down Expand Up @@ -281,3 +317,17 @@ export const getSimilaritiesProducts = async (models, filter, params) => {
hasSimilarity: gd.count > 1
}));
};

export const getSimilaritiesProductsCount = async (models, filter, params) => {
const aggregates =
params.groupedSimilarity === 'config'
? groupBySameMasksAggregator(true)
: groupByCategoryAggregator(true);
const groupedData = await models.Products.aggregate([
{ $match: filter },
...aggregates,
{ $group: { _id: {}, count: { $sum: 1 } } }
]);

return ((groupedData || [])[0] || {}).count || 0;
};
15 changes: 15 additions & 0 deletions packages/plugin-timeclock-api/src/graphql/resolvers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,20 @@ export const timeclockReportByUser = async (
]
});

const requestsOfSelectedMonth = await models.Absences.find({
$and: [
{ userId },
{ solved: true },
{ status: 'Approved' },
{
startTime: {
$gte: startOfSelectedMonth,
$lte: startOfNextMonth
}
}
]
});

let scheduledShiftStartSelectedDay;
let scheduledShiftEndSelectedDay;

Expand Down Expand Up @@ -465,6 +479,7 @@ export const timeclockReportByUser = async (
totalHoursBreakScheduled,
totalHoursBreakSelecteDay,

requests: requestsOfSelectedMonth,
scheduledShifts: scheduleShiftsSelectedMonth,
timeclocks: timeclocksOfSelectedMonth,

Expand Down
3 changes: 2 additions & 1 deletion packages/plugin-timeclock-api/src/graphql/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ export const types = `
scheduledShifts: [Shift]
timeclocks: [Timeclock]
requests: [Absence]
totalHoursWorkedSelectedDay: Float
totalHoursScheduledSelectedDay: Float
totalMinsLateSelectedDay: Float
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
FlexRow,
MarginX,
MarginY,
CustomBoxWrapper,
SortItem,
CustomContainer
} from '../../styles';
Expand All @@ -37,7 +36,6 @@ import Datetime from '@nateradebaugh/react-datetime';
import { dateFormat, timeFormat } from '../../constants';
import { IUser } from '@erxes/ui/src/auth/types';
import { FormControl } from '@erxes/ui/src/components/form';
import Box from '@erxes/ui/src/components/Box';

import * as icons from 'react-bootstrap-icons';

Expand Down

0 comments on commit 2fe3255

Please sign in to comment.