feat: add showPublicScores and showPublicOpinions flags to services with plan-based access control
This commit is contained in:
@@ -46,6 +46,17 @@ class ServiceManager implements IServicesManager {
|
||||
this.services = new ServicesAdapterMongoose();
|
||||
}
|
||||
|
||||
private async validatePublicRatingFlagsPlan(ownerId: string): Promise<void> {
|
||||
const { default: PlanSubscriptionsList } = await import("../PlanSubscriptions/PlanSubscriptons");
|
||||
const subscription = await PlanSubscriptionsList.getSubscriptionByUser({
|
||||
sessionUser: ownerId,
|
||||
});
|
||||
|
||||
if (!subscription || subscription.plan.price === 0) {
|
||||
throw new Error("Esta configuración está disponible solo para planes pagos.");
|
||||
}
|
||||
}
|
||||
|
||||
public async setPublishedStatus(data: SetPublishedStatusParams): Promise<void> {
|
||||
const sessionUser = await UsersManager.users.findOne({
|
||||
_id: data.sessionUser,
|
||||
@@ -145,6 +156,10 @@ class ServiceManager implements IServicesManager {
|
||||
throw new Error("Ha alcanzado el limite de servicios permitidos de acuerdo a su plan.");
|
||||
}
|
||||
|
||||
if (data.showPublicScores !== undefined || data.showPublicOpinions !== undefined) {
|
||||
await this.validatePublicRatingFlagsPlan(String(companyCheck.ownerId));
|
||||
}
|
||||
|
||||
const newService = await this.services.create({
|
||||
...data,
|
||||
...{
|
||||
@@ -190,6 +205,10 @@ class ServiceManager implements IServicesManager {
|
||||
throw new Error(NoPermissionMessage());
|
||||
}
|
||||
|
||||
if (data.showPublicScores !== undefined || data.showPublicOpinions !== undefined) {
|
||||
await this.validatePublicRatingFlagsPlan(String(companyCheck.ownerId));
|
||||
}
|
||||
|
||||
await this.services.update(data);
|
||||
}
|
||||
|
||||
@@ -307,6 +326,8 @@ class ServiceManager implements IServicesManager {
|
||||
service.published,
|
||||
SERVICE_PUBLISHED_STATUS.PRIVATE
|
||||
),
|
||||
showPublicScores: service.showPublicScores ?? true,
|
||||
showPublicOpinions: service.showPublicOpinions ?? true,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -363,6 +384,8 @@ class ServiceManager implements IServicesManager {
|
||||
fontColor: isNull<string>(service.fontColor, defFontColor),
|
||||
fontShadowColor: isNull<string>(service.fontShadowColor, defFontShadowColor),
|
||||
published: isNull<SERVICE_PUBLISHED_STATUS>(service.published, SERVICE_PUBLISHED_STATUS.PRIVATE),
|
||||
showPublicScores: service.showPublicScores ?? true,
|
||||
showPublicOpinions: service.showPublicOpinions ?? true,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -486,6 +509,8 @@ class ServiceManager implements IServicesManager {
|
||||
color: isNull<string>(service.color, defColor),
|
||||
fontColor: isNull<string>(service.fontColor, defFontColor),
|
||||
fontShadowColor: isNull<string>(service.fontShadowColor, defFontShadowColor),
|
||||
showPublicScores: service.showPublicScores ?? true,
|
||||
showPublicOpinions: service.showPublicOpinions ?? true,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user