Skip to content
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
7 changes: 4 additions & 3 deletions libs/common/src/interceptors/transform.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ export interface ApiResponse<T> {
* on a stable shape regardless of the controller that produced it.
*/
@Injectable()
export class TransformInterceptor<T>
implements NestInterceptor<T, ApiResponse<T>>
{
export class TransformInterceptor<T> implements NestInterceptor<
T,
ApiResponse<T>
> {
intercept(
_context: ExecutionContext,
next: CallHandler,
Expand Down
20 changes: 20 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"@nestjs/common": "^10.4.4",
"@nestjs/config": "^3.2.3",
"@nestjs/core": "^10.4.4",
"@nestjs/event-emitter": "^3.1.0",
"@nestjs/jwt": "^10.2.0",
"@nestjs/passport": "^10.0.3",
"@nestjs/platform-express": "^10.4.4",
Expand Down
6 changes: 5 additions & 1 deletion src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import { MarketplaceModule } from './modules/marketplace/marketplace.module';
import { AssetsModule } from './modules/assets/assets.module';
import { TransactionsModule } from './modules/transactions/transactions.module';
import { StellarModule } from './modules/stellar/stellar.module';
import { TradingEngineModule } from './modules/trading-engine/trading-engine.module';
import { WalletModule } from './modules/wallet/wallet.module';
import { NotificationsModule } from './modules/notifications/notifications.module';
import { EventEmitterModule } from '@nestjs/event-emitter';
import { TradingEngineModule } from './modules/trading-engine/trading-engine.module';
import { ErrorHandlerModule } from './modules/error-handler/error-handler.module';
import { ResilienceModule } from './modules/resilience/resilience.module';
import { QueueModule } from './modules/queue/queue.module';
Expand All @@ -21,6 +23,7 @@ import { BlockchainIndexerModule } from './modules/blockchain-indexer/blockchain

@Module({
imports: [
EventEmitterModule.forRoot(),
ConfigModule,
TypeOrmModule.forRootAsync({
useClass: DatabaseConfig,
Expand All @@ -34,6 +37,7 @@ import { BlockchainIndexerModule } from './modules/blockchain-indexer/blockchain
StellarModule,
TradingEngineModule,
WalletModule,
NotificationsModule,
ErrorHandlerModule,
ResilienceModule,
QueueModule,
Expand Down
5 changes: 4 additions & 1 deletion src/config/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ export default () => ({
10,
),
// How long, and how often, we poll RPC for a submitted tx to settle.
pollIntervalMs: parseInt(process.env.SOROBAN_POLL_INTERVAL_MS ?? '1000', 10),
pollIntervalMs: parseInt(
process.env.SOROBAN_POLL_INTERVAL_MS ?? '1000',
10,
),
pollTimeoutMs: parseInt(process.env.SOROBAN_POLL_TIMEOUT_MS ?? '30000', 10),
// Contract state cache TTL (seconds) in Redis.
stateCacheTtlSecs: parseInt(
Expand Down
5 changes: 1 addition & 4 deletions src/config/database.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import {
TypeOrmModuleOptions,
TypeOrmOptionsFactory,
} from '@nestjs/typeorm';
import { TypeOrmModuleOptions, TypeOrmOptionsFactory } from '@nestjs/typeorm';

/**
* Builds TypeORM connection options from validated configuration. Entities are
Expand Down
15 changes: 13 additions & 2 deletions src/modules/auth/auth.controller.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
import { Body, Controller, Get, HttpCode, HttpStatus, Post, UseGuards } from '@nestjs/common';
import {
Body,
Controller,
Get,
HttpCode,
HttpStatus,
Post,
UseGuards,
} from '@nestjs/common';
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
import { AuthService } from './auth.service';
import { RegisterDto } from './dto/register.dto';
import { LoginDto } from './dto/login.dto';
import { JwtAuthGuard } from './guards/jwt-auth.guard';
import { CurrentUser, AuthenticatedUser } from './decorators/current-user.decorator';
import {
CurrentUser,
AuthenticatedUser,
} from './decorators/current-user.decorator';

@ApiTags('auth')
@Controller('auth')
Expand Down
5 changes: 1 addition & 4 deletions src/modules/auth/auth.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
Injectable,
UnauthorizedException,
} from '@nestjs/common';
import { Injectable, UnauthorizedException } from '@nestjs/common';
import { JwtService } from '@nestjs/jwt';
import * as bcrypt from 'bcryptjs';
import { UsersService } from '../users/users.service';
Expand Down
4 changes: 1 addition & 3 deletions src/modules/marketplace/marketplace.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ export class MarketplaceService {
return this.listingsRepository.save(listing);
}

async findAll(
query: QueryListingDto,
): Promise<PaginatedResultDto<Listing>> {
async findAll(query: QueryListingDto): Promise<PaginatedResultDto<Listing>> {
const qb = this.listingsRepository
.createQueryBuilder('listing')
.leftJoinAndSelect('listing.seller', 'seller')
Expand Down
11 changes: 11 additions & 0 deletions src/modules/notifications/dto/create-notification-template.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { IsNotEmpty, IsString } from 'class-validator';

export class CreateNotificationTemplateDto {
@IsString()
@IsNotEmpty()
name: string;

@IsString()
@IsNotEmpty()
template: string;
}
20 changes: 20 additions & 0 deletions src/modules/notifications/dto/search-notifications.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { IsOptional, IsString, IsEnum, IsDateString } from 'class-validator';
import { Channel } from '../enums/channel.enum';

export class SearchNotificationsDto {
@IsOptional()
@IsString()
userId?: string;

@IsOptional()
@IsEnum(Channel)
channel?: Channel;

@IsOptional()
@IsDateString()
startDate?: string;

@IsOptional()
@IsDateString()
endDate?: string;
}
18 changes: 18 additions & 0 deletions src/modules/notifications/dto/send-from-template.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { IsEnum, IsNotEmpty, IsObject, IsString } from 'class-validator';
import { Channel } from '../enums/channel.enum';

export class SendFromTemplateDto {
@IsString()
@IsNotEmpty()
templateName: string;

@IsEnum(Channel)
channel: Channel;

@IsString()
@IsNotEmpty()
recipient: string;

@IsObject()
data: Record<string, any>;
}
6 changes: 6 additions & 0 deletions src/modules/notifications/dto/test-notification.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { IsString } from 'class-validator';

export class TestNotificationDto {
@IsString()
message: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { IsBoolean, IsEnum } from 'class-validator';
import { Channel } from '../enums/channel.enum';

export class UpdateNotificationPreferenceDto {
@IsEnum(Channel)
channel: Channel;

@IsBoolean()
isEnabled: boolean;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import {
Column,
Entity,
PrimaryGeneratedColumn,
CreateDateColumn,
UpdateDateColumn,
} from 'typeorm';
import { Channel } from '../enums/channel.enum';

@Entity('notification_preferences')
export class NotificationPreference {
@PrimaryGeneratedColumn('uuid')
id: string;

@Column()
userId: string;

@Column({
type: 'enum',
enum: Channel,
})
channel: Channel;

@Column({ default: true })
isEnabled: boolean;

@CreateDateColumn()
createdAt: Date;

@UpdateDateColumn()
updatedAt: Date;
}
25 changes: 25 additions & 0 deletions src/modules/notifications/entities/notification-template.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {
Column,
CreateDateColumn,
Entity,
PrimaryGeneratedColumn,
UpdateDateColumn,
} from 'typeorm';

@Entity('notification_templates')
export class NotificationTemplate {
@PrimaryGeneratedColumn('uuid')
id: string;

@Column({ unique: true })
name: string;

@Column('text')
template: string;

@CreateDateColumn()
createdAt: Date;

@UpdateDateColumn()
updatedAt: Date;
}
35 changes: 35 additions & 0 deletions src/modules/notifications/entities/notification.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import {
Column,
CreateDateColumn,
Entity,
PrimaryGeneratedColumn,
UpdateDateColumn,
} from 'typeorm';
import { Channel } from '../enums/channel.enum';

@Entity('notifications')
export class Notification {
@PrimaryGeneratedColumn('uuid')
id: string;

@Column()
recipient: string;

@Column({
type: 'enum',
enum: Channel,
})
channel: Channel;

@Column('text')
message: string;

@Column({ default: false })
isRead: boolean;

@CreateDateColumn()
createdAt: Date;

@UpdateDateColumn()
updatedAt: Date;
}
5 changes: 5 additions & 0 deletions src/modules/notifications/enums/channel.enum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export enum Channel {
WEB_SOCKET = 'web_socket',
EMAIL = 'email',
SMS = 'sms',
}
3 changes: 3 additions & 0 deletions src/modules/notifications/events/notification.events.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export class NotificationEvents {
static readonly SEND_NOTIFICATION = 'notification.send';
}
15 changes: 15 additions & 0 deletions src/modules/notifications/listeners/notification.listener.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Injectable } from '@nestjs/common';
import { OnEvent } from '@nestjs/event-emitter';
import { NotificationEvents } from '../events/notification.events';
import { NotificationsService } from '../notifications.service';
import { Notification } from '../notification.class';

@Injectable()
export class NotificationListener {
constructor(private readonly notificationsService: NotificationsService) {}

@OnEvent(NotificationEvents.SEND_NOTIFICATION)
handleSendNotificationEvent(notification: Notification) {
this.notificationsService.send(notification);
}
}
13 changes: 13 additions & 0 deletions src/modules/notifications/notification.class.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Channel } from './enums/channel.enum';

export class Notification {
channel: Channel;
recipient: string;
message: string;

constructor(channel: Channel, recipient: string, message: string) {
this.channel = channel;
this.recipient = recipient;
this.message = message;
}
}
Loading
Loading