Add limit of 10 webhooks/team
This commit is contained in:
@@ -7,8 +7,11 @@ import {
|
||||
NotEmpty,
|
||||
DataType,
|
||||
IsUrl,
|
||||
BeforeCreate,
|
||||
} from "sequelize-typescript";
|
||||
import { SaveOptions } from "sequelize/types";
|
||||
import { WebhookSubscriptionValidation } from "@shared/validations";
|
||||
import { ValidationError } from "@server/errors";
|
||||
import { Event } from "@server/types";
|
||||
import Team from "./Team";
|
||||
import User from "./User";
|
||||
@@ -55,6 +58,20 @@ class WebhookSubscription extends ParanoidModel {
|
||||
@Column
|
||||
teamId: string;
|
||||
|
||||
// hooks
|
||||
|
||||
@BeforeCreate
|
||||
static async checkLimit(model: WebhookSubscription) {
|
||||
const count = await this.count({
|
||||
where: { teamId: model.teamId },
|
||||
});
|
||||
if (count >= WebhookSubscriptionValidation.maxSubscriptions) {
|
||||
throw ValidationError(
|
||||
`You have reached the limit of ${WebhookSubscriptionValidation.maxSubscriptions} webhooks`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// methods
|
||||
|
||||
/**
|
||||
|
||||
@@ -41,3 +41,8 @@ export const TeamValidation = {
|
||||
/** The maximum number of domains per team */
|
||||
maxDomains: 10,
|
||||
};
|
||||
|
||||
export const WebhookSubscriptionValidation = {
|
||||
/** The maximum number of webhooks per team */
|
||||
maxSubscriptions: 10,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user