Skip to content

Commit

Permalink
feat(dal): create topic subscribers schema and entity
Browse files Browse the repository at this point in the history
  • Loading branch information
p-fernandez committed Nov 24, 2022
1 parent b3b5f70 commit 2e0fd5d
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 5 deletions.
4 changes: 3 additions & 1 deletion libs/dal/src/repositories/subscriber/subscriber.entity.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { ChatProviderIdEnum, PushProviderIdEnum } from '@novu/shared';

export type SubscriberId = string;

export class SubscriberEntity {
_id?: string;
_id?: SubscriberId;

firstName: string;

Expand Down
1 change: 1 addition & 0 deletions libs/dal/src/repositories/topic/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './topic.entity';
export * from './topic-subscribers.entity';
13 changes: 13 additions & 0 deletions libs/dal/src/repositories/topic/topic-subscribers.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Types } from 'mongoose';

import { EnvironmentId, OrganizationId, TopicId, UserId } from './topic.entity';

import { SubscriberId } from '../subscriber/subscriber.entity';

export class TopicSubscribersEntity {
_environmentId: EnvironmentId;
_organizationId: OrganizationId;
_userId: UserId;
topicId: TopicId;
subscribers: [SubscriberId];
}
35 changes: 35 additions & 0 deletions libs/dal/src/repositories/topic/topic-subscribers.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import * as mongoose from 'mongoose';
import { Schema } from 'mongoose';

import { TopicSubscribersEntity } from './topic-subscribers.entity';

import { schemaOptions } from '../schema-default.options';

const topicSubscribersSchema = new Schema(
{
_environmentId: {
type: Schema.Types.ObjectId,
ref: 'Environment',
index: true,
required: true,
},
_organizationId: {
type: Schema.Types.ObjectId,
ref: 'Organization',
index: true,
required: true,
},
_userId: {
type: Schema.Types.ObjectId,
ref: 'User',
index: true,
required: true,
},
subscribers: [{ type: Schema.Types.ObjectId, ref: 'Subscriber', required: true }],
},
schemaOptions
);

// eslint-disable-next-line @typescript-eslint/naming-convention
export const TopicSubscribers =
mongoose.models.Topic || mongoose.model<TopicSubscribersEntity>('TopicSubscribers', topicSubscribersSchema);
8 changes: 4 additions & 4 deletions libs/dal/src/repositories/topic/topic.entity.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Types } from 'mongoose';

type EnvironmentId = Types.ObjectId;
type OrganizationId = Types.ObjectId;
type TopicId = Types.ObjectId;
export type EnvironmentId = Types.ObjectId;
export type OrganizationId = Types.ObjectId;
export type TopicId = Types.ObjectId;
type TopicKey = string;
type UserId = Types.ObjectId;
export type UserId = Types.ObjectId;

export class TopicEntity {
_id: TopicId;
Expand Down

0 comments on commit 2e0fd5d

Please sign in to comment.