feat: agregar validaciones de acceso a pagos y mejorar la estructura del componente de perfil fiscal
This commit is contained in:
@@ -1,4 +1,7 @@
|
|||||||
import { validatePermissionsByCompany, validateSessionUser } from "../../helpers/check";
|
import { validatePermissionsByCompany, validateSessionUser } from "../../helpers/check";
|
||||||
|
import CompaniesList from "../Companies/Companies";
|
||||||
|
import PlanSubscriptionsList from "../PlanSubscriptions/PlanSubscriptons";
|
||||||
|
import { PlanFeatures } from "../Plans/Plans.interface";
|
||||||
import { findArcaActivityByCode } from "../ArcaActivities/ArcaActivities.Catalog";
|
import { findArcaActivityByCode } from "../ArcaActivities/ArcaActivities.Catalog";
|
||||||
import { OrganizationFiscalProfilesAdapterMongoose } from "./OrganizationFiscalProfiles.Adapter.Mongoose";
|
import { OrganizationFiscalProfilesAdapterMongoose } from "./OrganizationFiscalProfiles.Adapter.Mongoose";
|
||||||
import {
|
import {
|
||||||
@@ -70,6 +73,21 @@ class OrganizationFiscalProfilesManager implements IOrganizationFiscalProfilesMa
|
|||||||
|
|
||||||
await validatePermissionsByCompany({ companyId: data.companyId, sessionUser: data.sessionUser });
|
await validatePermissionsByCompany({ companyId: data.companyId, sessionUser: data.sessionUser });
|
||||||
|
|
||||||
|
const company = await CompaniesList.companies.findOne({ _id: data.companyId });
|
||||||
|
|
||||||
|
if (!company) {
|
||||||
|
throw new Error("No se ha encontrado la organización");
|
||||||
|
}
|
||||||
|
|
||||||
|
const canAccessPayments = await PlanSubscriptionsList.checkFeature({
|
||||||
|
userId: String(company.ownerId),
|
||||||
|
feature: PlanFeatures.PAYMENTS,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!canAccessPayments) {
|
||||||
|
throw new Error("La organización no tiene un plan que soporte el módulo de pagos");
|
||||||
|
}
|
||||||
|
|
||||||
this.validateProfileFields(data);
|
this.validateProfileFields(data);
|
||||||
|
|
||||||
const existingProfile = await this.organizationFiscalProfiles.findOne({
|
const existingProfile = await this.organizationFiscalProfiles.findOne({
|
||||||
@@ -140,6 +158,18 @@ class OrganizationFiscalProfilesManager implements IOrganizationFiscalProfilesMa
|
|||||||
companyId: data.companyId,
|
companyId: data.companyId,
|
||||||
sessionUser,
|
sessionUser,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const company = await CompaniesList.companies.findOne({ _id: data.companyId });
|
||||||
|
if (company) {
|
||||||
|
const canAccessPayments = await PlanSubscriptionsList.checkFeature({
|
||||||
|
userId: String(company.ownerId),
|
||||||
|
feature: PlanFeatures.PAYMENTS,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!canAccessPayments) {
|
||||||
|
throw new Error("La organización no tiene un plan que soporte el módulo de pagos");
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if (data.id) {
|
} else if (data.id) {
|
||||||
const profile = await this.organizationFiscalProfiles.findOne(data);
|
const profile = await this.organizationFiscalProfiles.findOne(data);
|
||||||
|
|
||||||
@@ -152,6 +182,18 @@ class OrganizationFiscalProfilesManager implements IOrganizationFiscalProfilesMa
|
|||||||
sessionUser,
|
sessionUser,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const company = await CompaniesList.companies.findOne({ _id: String(profile.companyId) });
|
||||||
|
if (company) {
|
||||||
|
const canAccessPayments = await PlanSubscriptionsList.checkFeature({
|
||||||
|
userId: String(company.ownerId),
|
||||||
|
feature: PlanFeatures.PAYMENTS,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!canAccessPayments) {
|
||||||
|
throw new Error("La organización no tiene un plan que soporte el módulo de pagos");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return [profile];
|
return [profile];
|
||||||
} else {
|
} else {
|
||||||
throw new Error("Se requiere una organización para buscar perfiles fiscales");
|
throw new Error("Se requiere una organización para buscar perfiles fiscales");
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import ReceiptLongOutlinedIcon from "@mui/icons-material/ReceiptLongOutlined";
|
|||||||
import { Grid2 } from "@mui/material";
|
import { Grid2 } from "@mui/material";
|
||||||
import { ApiError } from "@models/Server.Error.model";
|
import { ApiError } from "@models/Server.Error.model";
|
||||||
import style from "./page.module.css";
|
import style from "./page.module.css";
|
||||||
|
import SecureByPlan, { SECURE_CONTENTS } from "@core/app/components/SecureByPlan/SecureByPlan";
|
||||||
import {
|
import {
|
||||||
findArcaActivities,
|
findArcaActivities,
|
||||||
findOrganizationFiscalProfiles,
|
findOrganizationFiscalProfiles,
|
||||||
@@ -188,6 +189,7 @@ export default function OrganizationFiscalProfileEdit() {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Location />
|
<Location />
|
||||||
|
<SecureByPlan content={SECURE_CONTENTS.PAYMENTS} companyId={id}>
|
||||||
<div className={style.pageContainer}>
|
<div className={style.pageContainer}>
|
||||||
<section className={style.heroCard}>
|
<section className={style.heroCard}>
|
||||||
<div className={style.heroIcon}>
|
<div className={style.heroIcon}>
|
||||||
@@ -305,6 +307,7 @@ export default function OrganizationFiscalProfileEdit() {
|
|||||||
</p>
|
</p>
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
|
</SecureByPlan>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user