fix: checking process.env.NODE_ENV
gitea/salix/pipeline/pr-master This commit looks good Details

This commit is contained in:
Alex Moreno 2024-05-21 13:50:45 +02:00
parent d672385776
commit 18bb8a4ea5
15 changed files with 24 additions and 15 deletions

View File

@ -37,7 +37,7 @@ module.exports = Self => {
if (!recipient)
throw new Error(`Could not send message "${message}" to worker id ${recipientId} from user ${userId}`);
if (process.env.NODE_ENV == 'test')
if (!Self.app.models.Application.isProduction())
message = `[Test:Environment to user ${userId}] ` + message;
const chat = await models.Chat.create({

View File

@ -94,7 +94,7 @@ module.exports = Self => {
* @return {Promise} - The request promise
*/
Self.sendMessage = async function sendMessage(senderFk, recipient, message) {
if (process.env.NODE_ENV !== 'production') {
if (!Self.app.models.Application.isProduction()) {
return new Promise(resolve => {
return resolve({
statusCode: 200,
@ -149,7 +149,7 @@ module.exports = Self => {
* @return {Promise} - The request promise
*/
Self.getUserStatus = async function getUserStatus(username) {
if (process.env.NODE_ENV !== 'production') {
if (!Self.app.models.Application.isProduction()) {
return new Promise(resolve => {
return resolve({
data: {

View File

@ -22,7 +22,7 @@ module.exports = Self => {
if (typeof options == 'object')
Object.assign(myOptions, options);
if (process.env.NODE_ENV == 'test')
if (!Self.app.models.Application.isProduction())
throw new UserError(`Action not allowed on the test environment`);
const models = Self.app.models;

View File

@ -119,7 +119,7 @@ module.exports = Self => {
]
};
if (process.env.NODE_ENV != 'production')
if (!Self.app.models.Application.isProduction(false))
throw new UserError('Action not allowed on the test environment');
// delete old

View File

@ -43,8 +43,7 @@ module.exports = Self => {
Self.scrub = async function(collection, remove, limit, dryRun, skipLock) {
const $ = Self.app.models;
const env = process.env.NODE_ENV;
dryRun = dryRun || (env && env !== 'production');
dryRun = dryRun || !Self.app.models.Application.isProduction(false);
const instance = await $.ImageCollection.findOne({
fields: ['id'],

View File

@ -41,7 +41,7 @@ module.exports = Self => {
if (!hasWriteRole)
throw new UserError(`You don't have enough privileges`);
if (process.env.NODE_ENV == 'test')
if (!Self.app.models.Application.isProduction())
throw new UserError(`Action not allowed on the test environment`);
// Upload file to temporary path

View File

@ -70,7 +70,7 @@ module.exports = Self => {
const newParams = Object.assign({}, queueParams, sendParams);
const email = new Email(queueName, newParams);
if (process.env.NODE_ENV != 'test')
if (Self.app.models.Application.isProduction())
await email.send();
await queue.updateAttribute('status', statusSent);

View File

@ -0,0 +1,3 @@
module.exports = (localAsProduction = true) => {
if ((!process.env.NODE_ENV && localAsProduction) || process.env.NODE_ENV == 'production') return true;
};

View File

@ -1,3 +1,4 @@
const isProductionFn = require('../methods/application/isProduction');
module.exports = function(Self) {
require('../methods/application/status')(Self);
@ -6,4 +7,8 @@ module.exports = function(Self) {
require('../methods/application/executeProc')(Self);
require('../methods/application/executeFunc')(Self);
require('../methods/application/getEnumValues')(Self);
Self.isProduction = (localAsProduction = true) => {
return isProductionFn(localAsProduction);
};
};

View File

@ -3,9 +3,10 @@ const app = require('vn-loopback/server/server');
const ldap = require('../util/ldapjs-extra');
const crypto = require('crypto');
const nthash = require('smbhash').nthash;
const isProduction = require('vn-loopback/common/methods/application/isProduction');
module.exports = Self => {
const shouldSync = process.env.NODE_ENV !== 'test';
const shouldSync = isProduction();
Self.getLinker = async function() {
return await Self.findOne({

View File

@ -1,6 +1,7 @@
const ldap = require('../util/ldapjs-extra');
const execFile = require('child_process').execFile;
const isProduction = require('vn-loopback/common/methods/application/isProduction');
/**
* Summary of userAccountControl flags:
@ -12,7 +13,7 @@ const UserAccountControlFlags = {
};
module.exports = Self => {
const shouldSync = process.env.NODE_ENV !== 'test';
const shouldSync = isProduction();
Self.getLinker = async function() {
return await Self.findOne({

View File

@ -47,7 +47,7 @@ module.exports = Self => {
let response;
try {
if (process.env.NODE_ENV !== 'production')
if (!Self.app.models.Application.isProduction(false))
response = {result: [{status: 'ok'}]};
else {
const jsonTest = {

View File

@ -66,7 +66,7 @@ module.exports = Self => {
console.error(err);
});
if (process.env.NODE_ENV == 'test') {
if (!Self.app.models.Application.isProduction()) {
try {
await fs.access(file.path);
} catch (error) {

View File

@ -59,7 +59,7 @@ module.exports = Self => {
hasPdf: true
}, options);
if (process.env.NODE_ENV !== 'test') {
if (Self.app.models.Application.isProduction()) {
await print.storage.write(buffer, {
type: 'invoice',
path: pdfFile.path,

View File

@ -111,7 +111,7 @@ module.exports = Self => {
const destinationFile = path.join(
accessContainer.client.root, accessContainer.name, appName, `${toVersion}.7z`);
if (process.env.NODE_ENV == 'test')
if (!Self.app.models.Application.isProduction())
await fs.unlink(srcFile);
else {
await fs.move(srcFile, destinationFile, {