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
4 changes: 4 additions & 0 deletions backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import { ContractsModule } from './contracts/contracts.module';
import { LicensesModule } from './licenses/licenses.module';
import { PurchaseOrdersModule } from './purchase-orders/purchase-orders.module';
import { TasksModule } from './tasks/tasks.module';
import { NotificationsModule } from './notifications/notifications.module';
import { WebhooksModule } from './webhooks/webhooks.module';
import { ReportsModule } from './reports/reports.module';
import { NotificationsModule } from './notifications/notifications.module';
import { ApiKeysModule } from './api-keys/api-keys.module';
Expand Down Expand Up @@ -112,6 +114,8 @@ import { NotificationModule } from './notifications/notification.module';
InventoryModule,
VendorsModule,
DashboardModule,
NotificationsModule,
WebhooksModule,
ReportsModule,
NotificationsModule,
ApiKeysModule,
Expand Down
31 changes: 31 additions & 0 deletions backend/src/notifications/notification-preference.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {
Entity,
PrimaryGeneratedColumn,
Column,
CreateDateColumn,
UpdateDateColumn,
} from 'typeorm';

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

@Column()
userId: string;

@Column()
channel: string;

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

@Column('simple-array', { nullable: true })
events: string[];

@CreateDateColumn()
createdAt: Date;

@UpdateDateColumn()
updatedAt: Date;
}
46 changes: 46 additions & 0 deletions backend/src/notifications/notification-preference.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { NotificationPreference } from './notification-preference.entity';

@Injectable()
export class NotificationPreferenceService {
constructor(
@InjectRepository(NotificationPreference)
private readonly repo: Repository<NotificationPreference>,
) {}

async findByUser(userId: string): Promise<NotificationPreference[]> {
return this.repo.find({ where: { userId } });
}

async upsert(
userId: string,
channel: string,
enabled: boolean,
events?: string[],
): Promise<NotificationPreference> {
let pref = await this.repo.findOne({ where: { userId, channel } });
if (!pref) {
pref = this.repo.create({ userId, channel });
}
pref.enabled = enabled;
if (events !== undefined) pref.events = events;
return this.repo.save(pref);
}

async upsertAll(
userId: string,
preferences: { channel: string; enabled: boolean; events?: string[] }[],
): Promise<NotificationPreference[]> {
return Promise.all(
preferences.map((p) =>
this.upsert(userId, p.channel, p.enabled, p.events),
),
);
}

async reset(userId: string): Promise<void> {
await this.repo.delete({ userId });
}
}
36 changes: 25 additions & 11 deletions backend/src/notifications/notifications.controller.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,38 @@
import { Controller, Get, Patch, Param, Req, UseGuards } from '@nestjs/common';
import {
Controller,
Get,
Put,
Post,
Body,
Req,
UseGuards,
} from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { NotificationsService } from './notifications.service';
import { NotificationPreferenceService } from './notification-preference.service';

@Controller('notifications')
@Controller('users/me/notification-preferences')
@UseGuards(AuthGuard('jwt'))
export class NotificationsController {
constructor(private readonly notificationsService: NotificationsService) {}
constructor(private readonly prefService: NotificationPreferenceService) {}

@Get()
findAll(@Req() req: any) {
return this.notificationsService.findByUser(req.user?.id);
return this.prefService.findByUser(req.user?.id);
}

@Patch(':id/read')
markRead(@Param('id') id: string, @Req() req: any) {
return this.notificationsService.markRead(id, req.user?.id);
@Put()
upsertAll(
@Req() req: any,
@Body()
body: {
preferences: { channel: string; enabled: boolean; events?: string[] }[];
},
) {
return this.prefService.upsertAll(req.user?.id, body.preferences);
}

@Patch('read-all')
markAllRead(@Req() req: any) {
return this.notificationsService.markAllRead(req.user?.id);
@Post('reset')
reset(@Req() req: any) {
return this.prefService.reset(req.user?.id);
}
}
24 changes: 5 additions & 19 deletions backend/src/notifications/notifications.module.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,13 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { JwtModule } from '@nestjs/jwt';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { Notification } from './entities/notification.entity';
import { NotificationsGateway } from './notifications.gateway';
import { NotificationsService } from './notifications.service';
import { NotificationPreference } from './notification-preference.entity';
import { NotificationPreferenceService } from './notification-preference.service';
import { NotificationsController } from './notifications.controller';

@Module({
imports: [
TypeOrmModule.forFeature([Notification]),
JwtModule.registerAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: (config: ConfigService) => ({
secret: config.get('JWT_SECRET', 'change-me-in-env'),
signOptions: { expiresIn: '15m' },
}),
}),
ConfigModule,
],
imports: [TypeOrmModule.forFeature([NotificationPreference])],
controllers: [NotificationsController],
providers: [NotificationsGateway, NotificationsService],
exports: [NotificationsService, NotificationsGateway],
providers: [NotificationPreferenceService],
exports: [NotificationPreferenceService],
})
export class NotificationsModule {}
57 changes: 57 additions & 0 deletions backend/src/stellar/stellar-dividends.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import {
Controller,
Get,
Post,
Body,
Param,
UseGuards,
Req,
} from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { StellarService } from './stellar.service';

@Controller('stellar')
@UseGuards(AuthGuard('jwt'))
export class StellarDividendsController {
constructor(private readonly stellarService: StellarService) {}

@Post('assets/:id/dividends/distribute')
distributeDividends(
@Param('id') id: string,
@Body() body: { amount: number; recipients: string[] },
) {
return this.stellarService.distributeDividends(
id,
body.amount,
body.recipients,
);
}

@Post('assets/:id/voting/proposals')
createProposal(
@Param('id') id: string,
@Body() body: { title: string; description: string; options: string[] },
) {
return this.stellarService.createVotingProposal(
id,
body.title,
body.description,
body.options,
);
}

@Post('assets/:id/voting/proposals/:proposalId/vote')
castVote(
@Param('id') id: string,
@Param('proposalId') proposalId: string,
@Body() body: { vote: string },
@Req() _req: any,
) {
return this.stellarService.castVote(id, proposalId, body.vote);
}

@Get('assets/:id/voting/proposals/:proposalId/results')
getResults(@Param('id') id: string, @Param('proposalId') proposalId: string) {
return this.stellarService.getVotingResults(id, proposalId);
}
}
43 changes: 43 additions & 0 deletions backend/src/stellar/stellar-kyc.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import {
Controller,
Get,
Post,
Body,
Param,
UseGuards,
Req,
} from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { StellarService } from './stellar.service';

@Controller('stellar')
@UseGuards(AuthGuard('jwt'))
export class StellarKycController {
constructor(private readonly stellarService: StellarService) {}

@Post('assets/:id/lease')
createLease(
@Param('id') id: string,
@Body() body: { lessee: string; terms: Record<string, unknown> },
) {
return this.stellarService.createLease('', id, body.lessee, body.terms);
}

@Get('assets/:id/insurance')
getInsurance(@Param('id') id: string) {
return this.stellarService.getInsurancePolicy('', id);
}

@Post('kyc/submit')
submitKyc(
@Req() req: any,
@Body() body: { documents: Record<string, string> },
) {
return this.stellarService.submitKyc(req.user?.id, body.documents);
}

@Get('kyc/status')
getKycStatus(@Req() req: any) {
return this.stellarService.getKycStatus(req.user?.id);
}
}
5 changes: 3 additions & 2 deletions backend/src/stellar/stellar.module.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { StellarService } from './stellar.service';
import { StellarController } from './stellar.controller';
import { StellarDividendsController } from './stellar-dividends.controller';
import { StellarKycController } from './stellar-kyc.controller';

@Module({
imports: [ConfigModule],
controllers: [StellarController],
controllers: [StellarDividendsController, StellarKycController],
providers: [StellarService],
exports: [StellarService],
})
Expand Down
Loading
Loading