Skip to content

Commit

Permalink
feat: add unique index to webhook model
Browse files Browse the repository at this point in the history
  • Loading branch information
wrn14897 committed Feb 28, 2024
1 parent d09cb7f commit 6b5c9c5
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions packages/api/src/models/webhook.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,40 @@
import { ObjectId } from 'mongodb';
import mongoose, { Schema } from 'mongoose';

export enum WebhookService {
Slack = 'slack',
}

export interface IWebhook {
_id: ObjectId;
createdAt: Date;
name: string;
service: string;
service: WebhookService;
team: ObjectId;
updatedAt: Date;
url: string;
}

export default mongoose.model<IWebhook>(
'Webhook',
new Schema<IWebhook>(
{
team: { type: Schema.Types.ObjectId, ref: 'Team' },
service: String,
name: String,
url: String,
const WebhookSchema = new Schema<IWebhook>(
{
team: { type: Schema.Types.ObjectId, ref: 'Team' },
service: {
type: String,
enum: Object.values(WebhookService),
required: true,
},
name: {
type: String,
required: true,
},
{ timestamps: true },
),
url: {
type: String,
required: false,
},
},
{ timestamps: true },
);

WebhookSchema.index({ team: 1, service: 1, name: 1 }, { unique: true });

export default mongoose.model<IWebhook>('Webhook', WebhookSchema);

0 comments on commit 6b5c9c5

Please sign in to comment.