Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: upgrade mongoose version to 7 #4106

Merged
merged 9 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@
"errmsg",
"shelljs",
"prefiltering",
"virtuals",
"autodocs",
"stackalt",
"mediumdark",
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/app/change/e2e/promote-changes.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ describe('Promote changes', () => {

const prodVersion = await notificationTemplateRepository.findOne({
_organizationId: session.organization._id,
_notificationId: prodEnv._id,
_environmentId: prodEnv._id,
_parentId: notificationTemplateId,
});

Expand Down
101 changes: 56 additions & 45 deletions apps/api/src/app/subscribers/e2e/mark-all-subscriber-messages.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import { expect } from 'chai';
import axios from 'axios';
import { ChannelTypeEnum, MarkMessagesAsEnum } from '@novu/shared';
import { UserSession } from '@novu/testing';
import { NotificationTemplateEntity, MessageRepository } from '@novu/dal';
import { NotificationTemplateEntity, MessageRepository, SubscriberRepository } from '@novu/dal';

const axiosInstance = axios.create();

describe('Mark All Subscriber Messages - /subscribers/:subscriberId/messages/mark-all (POST)', function () {
let session: UserSession;
let template: NotificationTemplateEntity;
const messageRepository = new MessageRepository();
const subscriberRepository = new SubscriberRepository();

beforeEach(async () => {
session = new UserSession();
Expand All @@ -36,27 +37,29 @@ describe('Mark All Subscriber Messages - /subscribers/:subscriberId/messages/mar
});

it('should mark all the subscriber messages as read', async function () {
await session.triggerEvent(template.triggers[0].identifier, session.subscriberId);
await session.triggerEvent(template.triggers[0].identifier, session.subscriberId);
await session.triggerEvent(template.triggers[0].identifier, session.subscriberId);
await session.triggerEvent(template.triggers[0].identifier, session.subscriberId);
await session.triggerEvent(template.triggers[0].identifier, session.subscriberId);
const subscriberId = session.subscriberId;
await session.triggerEvent(template.triggers[0].identifier, subscriberId);
await session.triggerEvent(template.triggers[0].identifier, subscriberId);
await session.triggerEvent(template.triggers[0].identifier, subscriberId);
await session.triggerEvent(template.triggers[0].identifier, subscriberId);
await session.triggerEvent(template.triggers[0].identifier, subscriberId);

await session.awaitRunningJobs(template._id);

const notificationsFeedResponse = await getSubscriberNotifications(session, session.subscriberId);
const notificationsFeedResponse = await getSubscriberNotifications(session, subscriberId);
expect(notificationsFeedResponse.totalCount).to.equal(5);

const messagesMarkedAsReadResponse = await markAllSubscriberMessagesAs(
session,
session.subscriberId,
subscriberId,
MarkMessagesAsEnum.READ
);
expect(messagesMarkedAsReadResponse.data).to.equal(5);

const subscriber = await subscriberRepository.findBySubscriberId(session.environment._id, subscriberId);
const feed = await messageRepository.find({
_environmentId: session.environment._id,
subscriberId: session.subscriberId,
_subscriberId: subscriber?._id,
channel: ChannelTypeEnum.IN_APP,
seen: true,
read: true,
Expand All @@ -70,21 +73,23 @@ describe('Mark All Subscriber Messages - /subscribers/:subscriberId/messages/mar
});

it('should not mark all the messages as read if they are already read', async function () {
await session.triggerEvent(template.triggers[0].identifier, session.subscriberId);
await session.triggerEvent(template.triggers[0].identifier, session.subscriberId);
await session.triggerEvent(template.triggers[0].identifier, session.subscriberId);
await session.triggerEvent(template.triggers[0].identifier, session.subscriberId);
await session.triggerEvent(template.triggers[0].identifier, session.subscriberId);
const subscriberId = session.subscriberId;
await session.triggerEvent(template.triggers[0].identifier, subscriberId);
await session.triggerEvent(template.triggers[0].identifier, subscriberId);
await session.triggerEvent(template.triggers[0].identifier, subscriberId);
await session.triggerEvent(template.triggers[0].identifier, subscriberId);
await session.triggerEvent(template.triggers[0].identifier, subscriberId);

await session.awaitRunningJobs(template._id);

const notificationsFeedResponse = await getSubscriberNotifications(session, session.subscriberId);
const notificationsFeedResponse = await getSubscriberNotifications(session, subscriberId);
expect(notificationsFeedResponse.totalCount).to.equal(5);

const subscriber = await subscriberRepository.findBySubscriberId(session.environment._id, subscriberId);
await messageRepository.update(
{
_environmentId: session.environment._id,
subscriberId: session.subscriberId,
_subscriberId: subscriber?._id,
channel: ChannelTypeEnum.IN_APP,
seen: false,
read: false,
Expand All @@ -94,14 +99,14 @@ describe('Mark All Subscriber Messages - /subscribers/:subscriberId/messages/mar

const messagesMarkedAsReadResponse = await markAllSubscriberMessagesAs(
session,
session.subscriberId,
subscriberId,
MarkMessagesAsEnum.READ
);
expect(messagesMarkedAsReadResponse.data).to.equal(0);

const feed = await messageRepository.find({
_environmentId: session.environment._id,
subscriberId: session.subscriberId,
_subscriberId: subscriber?._id,
channel: ChannelTypeEnum.IN_APP,
seen: true,
read: true,
Expand All @@ -115,21 +120,23 @@ describe('Mark All Subscriber Messages - /subscribers/:subscriberId/messages/mar
});

it('should mark all the subscriber messages as unread', async function () {
await session.triggerEvent(template.triggers[0].identifier, session.subscriberId);
await session.triggerEvent(template.triggers[0].identifier, session.subscriberId);
await session.triggerEvent(template.triggers[0].identifier, session.subscriberId);
await session.triggerEvent(template.triggers[0].identifier, session.subscriberId);
await session.triggerEvent(template.triggers[0].identifier, session.subscriberId);
const subscriberId = session.subscriberId;
await session.triggerEvent(template.triggers[0].identifier, subscriberId);
await session.triggerEvent(template.triggers[0].identifier, subscriberId);
await session.triggerEvent(template.triggers[0].identifier, subscriberId);
await session.triggerEvent(template.triggers[0].identifier, subscriberId);
await session.triggerEvent(template.triggers[0].identifier, subscriberId);

await session.awaitRunningJobs(template._id);

const notificationsFeedResponse = await getSubscriberNotifications(session, session.subscriberId);
const notificationsFeedResponse = await getSubscriberNotifications(session, subscriberId);
expect(notificationsFeedResponse.totalCount).to.equal(5);

const subscriber = await subscriberRepository.findBySubscriberId(session.environment._id, subscriberId);
await messageRepository.update(
{
_environmentId: session.environment._id,
subscriberId: session.subscriberId,
_subscriberId: subscriber?._id,
channel: ChannelTypeEnum.IN_APP,
seen: false,
read: false,
Expand All @@ -139,14 +146,14 @@ describe('Mark All Subscriber Messages - /subscribers/:subscriberId/messages/mar

const messagesMarkedAsReadResponse = await markAllSubscriberMessagesAs(
session,
session.subscriberId,
subscriberId,
MarkMessagesAsEnum.UNREAD
);
expect(messagesMarkedAsReadResponse.data).to.equal(5);

const feed = await messageRepository.find({
_environmentId: session.environment._id,
subscriberId: session.subscriberId,
_subscriberId: subscriber?._id,
channel: ChannelTypeEnum.IN_APP,
seen: true,
read: false,
Expand All @@ -160,27 +167,29 @@ describe('Mark All Subscriber Messages - /subscribers/:subscriberId/messages/mar
});

it('should mark all the subscriber messages as seen', async function () {
await session.triggerEvent(template.triggers[0].identifier, session.subscriberId);
await session.triggerEvent(template.triggers[0].identifier, session.subscriberId);
await session.triggerEvent(template.triggers[0].identifier, session.subscriberId);
await session.triggerEvent(template.triggers[0].identifier, session.subscriberId);
await session.triggerEvent(template.triggers[0].identifier, session.subscriberId);
const subscriberId = session.subscriberId;
await session.triggerEvent(template.triggers[0].identifier, subscriberId);
await session.triggerEvent(template.triggers[0].identifier, subscriberId);
await session.triggerEvent(template.triggers[0].identifier, subscriberId);
await session.triggerEvent(template.triggers[0].identifier, subscriberId);
await session.triggerEvent(template.triggers[0].identifier, subscriberId);

await session.awaitRunningJobs(template._id);

const notificationsFeedResponse = await getSubscriberNotifications(session, session.subscriberId);
const notificationsFeedResponse = await getSubscriberNotifications(session, subscriberId);
expect(notificationsFeedResponse.totalCount).to.equal(5);

const messagesMarkedAsReadResponse = await markAllSubscriberMessagesAs(
session,
session.subscriberId,
subscriberId,
MarkMessagesAsEnum.SEEN
);
expect(messagesMarkedAsReadResponse.data).to.equal(5);

const subscriber = await subscriberRepository.findBySubscriberId(session.environment._id, subscriberId);
const feed = await messageRepository.find({
_environmentId: session.environment._id,
subscriberId: session.subscriberId,
_subscriberId: subscriber?._id,
channel: ChannelTypeEnum.IN_APP,
seen: true,
read: false,
Expand All @@ -194,21 +203,23 @@ describe('Mark All Subscriber Messages - /subscribers/:subscriberId/messages/mar
});

it('should mark all the subscriber messages as unseen', async function () {
await session.triggerEvent(template.triggers[0].identifier, session.subscriberId);
await session.triggerEvent(template.triggers[0].identifier, session.subscriberId);
await session.triggerEvent(template.triggers[0].identifier, session.subscriberId);
await session.triggerEvent(template.triggers[0].identifier, session.subscriberId);
await session.triggerEvent(template.triggers[0].identifier, session.subscriberId);
const subscriberId = session.subscriberId;
await session.triggerEvent(template.triggers[0].identifier, subscriberId);
await session.triggerEvent(template.triggers[0].identifier, subscriberId);
await session.triggerEvent(template.triggers[0].identifier, subscriberId);
await session.triggerEvent(template.triggers[0].identifier, subscriberId);
await session.triggerEvent(template.triggers[0].identifier, subscriberId);

await session.awaitRunningJobs(template._id);

const notificationsFeedResponse = await getSubscriberNotifications(session, session.subscriberId);
const notificationsFeedResponse = await getSubscriberNotifications(session, subscriberId);
expect(notificationsFeedResponse.totalCount).to.equal(5);

const subscriber = await subscriberRepository.findBySubscriberId(session.environment._id, subscriberId);
await messageRepository.update(
{
_environmentId: session.environment._id,
subscriberId: session.subscriberId,
_subscriberId: subscriber?._id,
channel: ChannelTypeEnum.IN_APP,
seen: false,
read: false,
Expand All @@ -218,14 +229,14 @@ describe('Mark All Subscriber Messages - /subscribers/:subscriberId/messages/mar

const messagesMarkedAsReadResponse = await markAllSubscriberMessagesAs(
session,
session.subscriberId,
subscriberId,
MarkMessagesAsEnum.UNSEEN
);
expect(messagesMarkedAsReadResponse.data).to.equal(5);

const feed = await messageRepository.find({
_environmentId: session.environment._id,
subscriberId: session.subscriberId,
_subscriberId: subscriber?._id,
channel: ChannelTypeEnum.IN_APP,
seen: false,
read: false,
Expand Down Expand Up @@ -256,7 +267,7 @@ async function markAllSubscriberMessagesAs(session: UserSession, subscriberId: s
}

async function getSubscriberNotifications(session: UserSession, subscriberId: string) {
const response = await axios.get(`${session.serverUrl}/v1/subscribers/${session.subscriberId}/notifications/feed`, {
const response = await axios.get(`${session.serverUrl}/v1/subscribers/${subscriberId}/notifications/feed`, {
params: {
limit: 100,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class DeleteTenant {
);

try {
return await this.tenantRepository.delete({
await this.tenantRepository.delete({
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To respect the current response interface of void

_environmentId: command.environmentId,
_organizationId: command.organizationId,
identifier: command.identifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export class CreateNotificationTemplate {

const blueprintFeed = await this.feedRepository.findOne({
_organizationId: this.getBlueprintOrganizationId,
id: step.template._feedId,
_id: step.template._feedId,
});

if (!blueprintFeed) {
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/pages/templates/filter/FilterModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ export function FilterModal({

function handleOnChildOnChange(index: number) {
return (data) => {
const newField = Object.assign({}, fields[index], { on: data });
update(index, newField);
const { id: _, ...rest } = fields[index];
update(index, { ...rest, on: data });
};
}

Expand Down
4 changes: 2 additions & 2 deletions libs/dal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
"googleapis": "^60.0.1",
"intercom-client": "^2.11.0",
"jsonfile": "^6.0.1",
"mongoose": "6.11.3",
"mongoose-delete": "^0.5.4",
"mongoose": "^7.5.0",
"mongoose-delete": "^1.0.1",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Matching a supporting version for the delete package

"ng-intercom": "^8.0.2",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
Expand Down
9 changes: 7 additions & 2 deletions libs/dal/src/repositories/base-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,13 @@ export class BaseRepository<T_DBModel, T_MappedEntity, T_Enforcement = object> {
return this.mapEntity(data.toObject());
}

async delete(query: FilterQuery<T_DBModel> & T_Enforcement): Promise<void> {
return await this.MongooseModel.remove(query);
async delete(query: FilterQuery<T_DBModel> & T_Enforcement): Promise<{
/** Indicates whether this writes result was acknowledged. If not, then all other members of this result will be undefined. */
acknowledged: boolean;
/** The number of documents that were deleted */
deletedCount: number;
Comment on lines +62 to +65
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to do that, since the type is not exported from mongoose

}> {
return await this.MongooseModel.deleteMany(query);
}

async find(
Expand Down
2 changes: 1 addition & 1 deletion libs/dal/src/repositories/feed/feed.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class FeedRepository extends BaseRepository<FeedDBModel, FeedEntity, Enfo
);
if (relatedMessages.length) throw new DalException(`Can not delete feed that has existing message`);

await this.feed.delete({ _id: feed._id, _environmentId: feed._environmentId });
return await this.feed.delete({ _id: feed._id, _environmentId: feed._environmentId });
}

async findDeleted(query: FilterQuery<FeedEntity>): Promise<FeedEntity> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class IntegrationRepository extends BaseRepository<IntegrationDBModel, In
const integration = await this.findOne({ _id: query._id, _organizationId: query._organizationId });
if (!integration) throw new DalException(`Could not find integration with id ${query._id}`);

await this.integration.delete({ _id: integration._id, _organizationId: integration._organizationId });
return await this.integration.delete({ _id: integration._id, _organizationId: integration._organizationId });
}

async deleteMany(query: IntegrationQuery): Promise<IDeleteResult> {
Expand Down
12 changes: 10 additions & 2 deletions libs/dal/src/repositories/member/member.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,16 @@ export class MemberRepository extends BaseRepository<MemberDBModel, MemberEntity
super(Member, MemberEntity);
}

async removeMemberById(organizationId: string, memberId: string) {
return this.MongooseModel.remove({
async removeMemberById(
organizationId: string,
memberId: string
): Promise<{
/** Indicates whether this write result was acknowledged. If not, then all other members of this result will be undefined. */
acknowledged: boolean;
/** The number of documents that were deleted */
deletedCount: number;
}> {
return this.MongooseModel.deleteOne({
_id: memberId,
_organizationId: organizationId,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ export class MessageTemplateRepository extends BaseRepository<
throw new DalException(`Could not find a message template with id ${query._id}`);
}

await this.messageTemplate.delete({ _id: messageTemplate._id, _environmentId: messageTemplate._environmentId });
return await this.messageTemplate.delete({
_id: messageTemplate._id,
_environmentId: messageTemplate._environmentId,
});
}

async findDeleted(query: MessageTemplateQuery): Promise<MessageTemplateEntity> {
Expand Down
2 changes: 1 addition & 1 deletion libs/dal/src/repositories/message/message.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ export class MessageRepository extends BaseRepository<MessageDBModel, MessageEnt
throw new DalException(`Could not find a message with id ${query._id}`);
}

await this.message.delete({ _id: message._id, _environmentId: message._environmentId });
return await this.message.delete({ _id: message._id, _environmentId: message._environmentId });
}

async deleteMany(query: MessageQuery) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ export class NotificationTemplateRepository extends BaseRepository<
async delete(query: NotificationTemplateQuery) {
const item = await this.findOne({ _id: query._id, _environmentId: query._environmentId });
if (!item) throw new DalException(`Could not find workflow with id ${query._id}`);
await this.notificationTemplate.delete({ _id: item._id, _environmentId: item._environmentId });

return await this.notificationTemplate.delete({ _id: item._id, _environmentId: item._environmentId });
}

async findDeleted(query: NotificationTemplateQuery): Promise<NotificationTemplateEntity> {
Expand Down
1 change: 1 addition & 0 deletions libs/dal/src/repositories/schema-default.options.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export const schemaOptions = {
timestamps: true,
id: true,
toJSON: {
virtuals: true,
},
Expand Down
Loading