Draft: Revert "feat: Private Groups + Load-Templates"

This commit is contained in:
Josepablo Cruz Baas
2026-03-31 22:06:21 +00:00
parent 14a8a22880
commit f79329e714
18 changed files with 55 additions and 672 deletions

View File

@@ -1,12 +1,11 @@
"use strict";
const { ROOT_PATH, MODELS_PATH, HANDLERS_PATH, LIB_PATH } = process.env;
const { getModel } = require( '../../../lib/Models' );
const { getModel } = require( `${ROOT_PATH}/${MODELS_PATH}` );
const { GenericHandler } = require( '../../../lib/Handlers/Generic.handler.js' );
const { getPagination } = require( '../../../lib/Misc.js' );
const { getPagination } = require( `${ROOT_PATH}/${LIB_PATH}/Misc.js` );
const usersModel = getModel('users');
const companiesModel = getModel('companies');
const companyGroupsModel = getModel('company_groups');
const branchesModel = getModel('branches');
const vehiclesModel = getModel('vehicles');
const loadsModel = getModel('loads');
@@ -47,60 +46,21 @@ function getAndFilterList( query ){
return filter_list;
}
const companySelectField =
[
"rfc",
"company_name",
"company_type",
"company_code",
"company_city",
"company_state",
"createdAt",
"membership",
"categories",
"truck_type",
"company_description",
"privacy"
];
async function getCompanyIdListFromGroups( companyId ){
const privateGroups = await companyGroupsModel.find({
allowedCompanies: { $in: [companyId] }
});
if( !privateGroups ){
return null;
}
const companiesIds = privateGroups.map((group) => group.owner);
return companiesIds;
}
async function getListByType( companyId, type , req ){
const { privacy } = req.query;
const privacyVal = ( privacy && ( privacy >= 1 || privacy.toLowerCase() === 'true' ))? true: false;
let filter;
if( privacyVal ){
const companiesIds = await getCompanyIdListFromGroups( companyId ) || [];
filter = {
_id : { $in : companiesIds },
company_type: type,
is_hidden: false,
privacy: true,
}
}else{
filter = {
company_type: type,
is_hidden: false,
$or : [
{ privacy : false },
{ privacy : { $exists : false } }
]
};
}
const select = companySelectField;
async function getListByType( type , req ){
const filter = { "company_type" : type , "is_hidden" : false };
const select = [
"rfc",
"company_name",
"company_type",
"company_code",
"company_city",
"company_state",
"createdAt",
"membership",
"categories",
"truck_type",
"company_description"
];
const { $sort } = req.query;
const { elements , page } = getPagination( req.query );
let query_elements;
@@ -183,8 +143,7 @@ async function getCompanyById( req , res ) {
async function getListShippers( req , res ) {
try{
const companyId = req.context.companyId;
const retVal = await getListByType( companyId, "Shipper" , req );
const retVal = await getListByType( "Shipper" , req );
res.send( retVal );
}catch( error ){
console.error( error );
@@ -194,8 +153,7 @@ async function getListShippers( req , res ) {
async function getListCarriers( req , res ) {
try{
const companyId = req.context.companyId;
const retVal = await getListByType( companyId, "Carrier" , req );
const retVal = await getListByType( "Carrier" , req );
res.send( retVal );
}catch( error ){
console.error( error );