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
96 changes: 32 additions & 64 deletions src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
// Unit tests stub
import { Test, TestingModule } from '@nestjs/testing';
import { CommandFrameworkService } from '../command-framework.service';

describe('CommandFrameworkService', () => {
let service: CommandFrameworkService;
import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { TypeOrmModule } from '@nestjs/typeorm';
Expand All @@ -29,10 +23,10 @@ import { AnalyticsModule } from './analytics/analytics.module';
import { TransactionsModule } from './transactions/transactions.module';
import { LoggingModule } from './common/logging/logging.module';
import { ScheduledJobsModule } from './scheduled-jobs/scheduled-jobs.module';
import { AIModerationModule } from './ai-moderation/ai-moderation.module';
import { NFTsModule } from './nfts/nfts.module';
import { AppI18nModule } from './i18n/app-i18n.module';
import { InChatTransfersModule } from './in-chat-transfers/in-chat-transfers.module';
import { GroupExpensesModule } from './group-expenses/group-expenses.module';
import { WebhooksModule } from './webhooks/webhooks.module';
import { ObservabilityModule } from './observability/observability.module';
import { UserSettingsModule } from './user-settings/user-settings.module';
Expand Down Expand Up @@ -95,27 +89,37 @@ import { BlockEnforcementModule } from './block-enforcement/block-enforcement.mo
TypeOrmModule.forRootAsync({ useFactory: typeOrmConfig }),
ThrottlerModule.forRoot([{ ttl: 60000, limit: 10 }]),
RedisCacheModule,
ScheduleModule.forRoot(),
WaitlistModule,
LoggingModule,
HealthModule,
UsersModule,
AuthModule,
TwoFactorModule,
StellarEventsModule,
TypeOrmModule.forRootAsync({
useFactory: typeOrmConfig,
}),
ThrottlerModule.forRoot([
{
ttl: 60000,
limit: 10,
},
]),
CacheModule,
FraudDetectionModule,
LoggingModule,
ScheduleModule.forRoot(),
AppI18nModule,
HealthModule,
UsersModule,
UserSettingsModule,
AppConfigModule,
AuthModule,
SessionsModule,
WalletsModule,
AnalyticsModule,
TransactionsModule,
LoggingModule,
ScheduledJobsModule,
NFTsModule,
AppI18nModule,
StellarEventsModule,
ContractStateCacheModule,
NotificationsModule,
ReactionsModule,
StickersModule,
UserStickerPacksModule,
PrivacyModule,
BlockEnforcementModule,
SpamDetectionModule,
Expand All @@ -124,57 +128,21 @@ import { BlockEnforcementModule } from './block-enforcement/block-enforcement.mo
Sep10Module,
RampModule,
QrCodeModule,
PollsModule,
OnboardingModule,
MessageDraftsModule,
ScheduledJobsModule,
AIModerationModule,
InChatTransfersModule,
BotsModule,
GroupExpensesModule,
WebhooksModule,
ObservabilityModule,
UserSettingsModule,
AppConfigModule,
AppVersionModule,
AdminModule,
MembershipTierModule,
CacheModule,
ReportsModule,
BlockchainTransactionsModule,
MessageForwardingModule,
PollsModule,
MentionsModule,
RecurringPaymentsModule,
AnchorModule,
ConversationExportModule,
FeedbackModule,
RevenueModule,
PortfolioModule,
AddressBookModule,
UsernameDiscoveryModule,
DeveloperSandboxModule,
StoriesModule,
PaymentsModule,
LinkPreviewsModule,
NotificationDigestModule,
ReceiptsModule,
TrustNetworkModule,
AmlMonitoringModule,
ConnectionsModule,
PaymentSettingsModule,
ActivityFeedModule,
],

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [CommandFrameworkService],
}).compile();

service = module.get<CommandFrameworkService>(CommandFrameworkService);
});

it('should parse command', () => {
expect(service.parseCommand('/help')).toBeDefined();
});
// TODO: full coverage >85%
});
controllers: [AppController],
providers: [
AppService,
{
provide: APP_GUARD,
useClass: AdvancedThrottlerGuard,
},
],
})
export class AppModule {}
6 changes: 3 additions & 3 deletions src/conversations/entities/conversation.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { ConversationParticipant } from './conversation-participant.entity';
import { Message } from '../../messages/entities/message.entity';
import { InChatTransfer } from '../../in-chat-transfers/entities/in-chat-transfer.entity';
import { PinnedMessage } from '../../pinned-messages/entities/pinned-message.entity';
import { PaymentRequest } from '../../payment-requests/entities/payment-request.entity';
import { GroupExpense } from '../../group-expenses/entities/group-expense.entity';

export enum ConversationType {
DIRECT = 'direct',
Expand Down Expand Up @@ -47,8 +47,8 @@ export class Conversation {
@OneToMany(() => PinnedMessage, (pin) => pin.conversation)
pinnedMessages!: PinnedMessage[];

@OneToMany(() => PaymentRequest, (req: PaymentRequest) => req.conversation)
paymentRequests!: PaymentRequest[];
@OneToMany(() => GroupExpense, (expense) => expense.conversation)
expenses!: GroupExpense[];

@CreateDateColumn({ type: 'timestamp' })
createdAt!: Date;
Expand Down
65 changes: 65 additions & 0 deletions src/group-expenses/dto/create-group-expense.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import {
ArrayMinSize,
IsArray,
IsEnum,
IsNumber,
IsOptional,
IsString,
IsUUID,
MaxLength,
Min,
ValidateNested,
} from 'class-validator';
import { GroupExpenseSplitType } from '../entities/group-expense.entity';

export class SplitInputDto {
@ApiProperty()
@IsUUID()
userId!: string;

@ApiPropertyOptional({ description: 'Used when splitType is CUSTOM' })
@IsOptional()
@Type(() => Number)
@IsNumber({ maxDecimalPlaces: 7 })
@Min(0)
amount?: number;

@ApiPropertyOptional({ description: 'Used when splitType is PERCENTAGE' })
@IsOptional()
@Type(() => Number)
@IsNumber({ maxDecimalPlaces: 4 })
@Min(0)
percentage?: number;
}

export class CreateGroupExpenseDto {
@ApiProperty()
@IsString()
@MaxLength(180)
title!: string;

@ApiProperty({ minimum: 0.0000001 })
@Type(() => Number)
@IsNumber({ maxDecimalPlaces: 7 })
@Min(0.0000001)
totalAmount!: number;

@ApiProperty()
@IsString()
@MaxLength(64)
tokenId!: string;

@ApiProperty({ enum: GroupExpenseSplitType })
@IsEnum(GroupExpenseSplitType)
splitType!: GroupExpenseSplitType;

@ApiPropertyOptional({ type: [SplitInputDto] })
@IsOptional()
@IsArray()
@ArrayMinSize(1)
@ValidateNested({ each: true })
@Type(() => SplitInputDto)
splits?: SplitInputDto[];
}
24 changes: 24 additions & 0 deletions src/group-expenses/dto/get-group-expenses-query.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { ApiPropertyOptional } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import { IsEnum, IsInt, IsOptional, Max, Min } from 'class-validator';
import { GroupExpenseStatus } from '../entities/group-expense.entity';

export class GetGroupExpensesQueryDto {
@ApiPropertyOptional({ enum: GroupExpenseStatus })
@IsOptional()
@IsEnum(GroupExpenseStatus)
status?: GroupExpenseStatus;

@ApiPropertyOptional({ default: 1, minimum: 1 })
@Type(() => Number)
@IsInt()
@Min(1)
page: number = 1;

@ApiPropertyOptional({ default: 20, minimum: 1, maximum: 100 })
@Type(() => Number)
@IsInt()
@Min(1)
@Max(100)
limit: number = 20;
}
110 changes: 110 additions & 0 deletions src/group-expenses/dto/group-expense-response.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import { ApiProperty } from '@nestjs/swagger';
import {
GroupExpenseSplitType,
GroupExpenseStatus,
} from '../entities/group-expense.entity';

export class ExpenseSplitResponseDto {
@ApiProperty()
expenseId!: string;

@ApiProperty()
userId!: string;

@ApiProperty()
amountOwed!: string;

@ApiProperty()
amountPaid!: string;

@ApiProperty()
isPaid!: boolean;

@ApiProperty({ nullable: true })
paidAt!: Date | null;
}

export class GroupExpenseResponseDto {
@ApiProperty()
id!: string;

@ApiProperty()
groupId!: string;

@ApiProperty()
conversationId!: string;

@ApiProperty()
createdBy!: string;

@ApiProperty()
title!: string;

@ApiProperty()
totalAmount!: string;

@ApiProperty()
tokenId!: string;

@ApiProperty({ enum: GroupExpenseSplitType })
splitType!: GroupExpenseSplitType;

@ApiProperty({ enum: GroupExpenseStatus })
status!: GroupExpenseStatus;

@ApiProperty()
createdAt!: Date;

@ApiProperty({ type: [ExpenseSplitResponseDto] })
splits!: ExpenseSplitResponseDto[];
}

export class GroupExpenseListResponseDto {
@ApiProperty({ type: [GroupExpenseResponseDto] })
items!: GroupExpenseResponseDto[];

@ApiProperty()
total!: number;

@ApiProperty()
page!: number;

@ApiProperty()
limit!: number;
}

export class GroupBalanceMemberSummaryDto {
@ApiProperty()
userId!: string;

@ApiProperty()
netOwed!: string;

@ApiProperty()
netOwedTo!: string;
}

export class GroupUnsettledBalanceDto {
@ApiProperty()
userId!: string;

@ApiProperty()
totalOwed!: string;

@ApiProperty()
totalOwedTo!: string;

@ApiProperty()
netBalance!: string;
}

export class GroupBalanceResponseDto {
@ApiProperty()
groupId!: string;

@ApiProperty({ type: GroupUnsettledBalanceDto })
unsettledBalance!: GroupUnsettledBalanceDto;

@ApiProperty({ type: [GroupBalanceMemberSummaryDto] })
summary!: GroupBalanceMemberSummaryDto[];
}
Loading
Loading