Skip to content

Commit

Permalink
ported notification replaceById and deps
Browse files Browse the repository at this point in the history
  • Loading branch information
f-w committed Oct 19, 2023
1 parent 503feed commit 852f8dd
Show file tree
Hide file tree
Showing 8 changed files with 732 additions and 10 deletions.
4 changes: 4 additions & 0 deletions notify-bc-lb/src/controllers/notification.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ export class NotificationController extends BaseController {
await this.notificationRepository.updateById(id, notification, undefined);
}

// start: ported
@put('/notifications/{id}', {
responses: {
'204': {
Expand All @@ -303,6 +304,7 @@ export class NotificationController extends BaseController {
this.httpContext.bind('args').to({data: notification});
await this.dispatchNotification(notification);
}
// end: ported

@del('/notifications/{id}', {
responses: {
Expand Down Expand Up @@ -353,6 +355,7 @@ export class NotificationController extends BaseController {
return this.sendPushNotification(notification);
}

// start: ported
async sendPushNotification(data: Notification) {
const inboundSmtpServerDomain =
this.appConfig.email.inboundSmtpServer?.domain;
Expand Down Expand Up @@ -1022,4 +1025,5 @@ export class NotificationController extends BaseController {
throw new HttpErrors[403]('invalid user');
}
}
// end: ported
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"@nestjs/mongoose": "^10.0.1",
"@nestjs/platform-express": "^10.0.0",
"@nestjs/swagger": "^7.1.8",
"async": "^3.2.4",
"bcryptjs": "^2.4.3",
"bottleneck": "^2.19.5",
"class-transformer": "^0.5.1",
Expand Down
1 change: 1 addition & 0 deletions src/api/bounces/bounces.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ import { Bounce, BounceSchema } from './entities/bounce.entity';
],
controllers: [BouncesController],
providers: [BouncesService],
exports: [BouncesService],
})
export class BouncesModule {}
62 changes: 59 additions & 3 deletions src/api/notifications/entities/notification.entity.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Schema, SchemaFactory } from '@nestjs/mongoose';
import { HydratedDocument } from 'mongoose';
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import mongoose, { AnyObject, HydratedDocument } from 'mongoose';
import { BaseEntity, BaseSchemaOptions } from 'src/api/common/base.entity';

export type NotificationDocument = HydratedDocument<Notification>;
Expand All @@ -8,7 +8,63 @@ export type NotificationDocument = HydratedDocument<Notification>;
collection: 'notification',
...BaseSchemaOptions,
})
export class Notification extends BaseEntity {}
export class Notification extends BaseEntity {
@Prop({ required: true })
serviceName: string;

@Prop({
default: 'new',
})
state: string;

@Prop()
userChannelId?: string;

@Prop({
type: mongoose.Schema.Types.Mixed,
required: true,
default: {},
})
message: AnyObject;

@Prop({
required: true,
default: 'inApp',
})
channel: string;

@Prop({
default: false,
})
isBroadcast?: boolean;

@Prop({
default: false,
})
skipSubscriptionConfirmationCheck?: boolean;

@Prop()
validTill?: Date;

@Prop()
invalidBefore?: Date;

@Prop({
type: mongoose.Schema.Types.Mixed,
})
data?: AnyObject;

@Prop({
type: mongoose.Schema.Types.Mixed,
})
asyncBroadcastPushNotification?: any;

@Prop()
broadcastPushNotificationSubscriptionFilter?: string;

// Indexer property to allow additional data
[prop: string]: any;
}

export const NotificationSchema = SchemaFactory.createForClass(
Notification,
Expand Down
Loading

0 comments on commit 852f8dd

Please sign in to comment.