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
Empty file added nest
Empty file.
420 changes: 229 additions & 191 deletions package-lock.json

Large diffs are not rendered by default.

262 changes: 138 additions & 124 deletions prisma/schema.prisma

Large diffs are not rendered by default.

Empty file added propchain-backend@1.0.0
Empty file.
3 changes: 2 additions & 1 deletion src/admin/admin.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,9 @@ export class AdminController {
updateTransactionStatus(
@Param('id') transactionId: string,
@Body() payload: UpdateTransactionStatusDto,
@CurrentUser() user: AuthUserPayload,
) {
return this.adminService.updateTransactionStatus(transactionId, payload);
return this.adminService.updateTransactionStatus(transactionId, payload, user.sub);
}

@Get('fraud/alerts')
Expand Down
8 changes: 6 additions & 2 deletions src/admin/admin.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,12 @@ export class AdminService {
};
}

async updateTransactionStatus(transactionId: string, payload: UpdateTransactionStatusDto) {
return this.transactionsService.updateTransactionStatus(transactionId, payload.status);
async updateTransactionStatus(
transactionId: string,
payload: UpdateTransactionStatusDto,
actorId?: string,
) {
return this.transactionsService.updateTransactionStatus(transactionId, payload.status, actorId);
}

async listFraudAlerts(query: FraudAlertsQueryDto) {
Expand Down
2 changes: 1 addition & 1 deletion src/notifications/notifications.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class NotificationsService {
// FCM Push Integration
const user = await this.prisma.user.findUnique({ where: { id: userId }, select: { fcmToken: true } });
if (user?.fcmToken) {
console.log(Sending FCM notification to token: \);
console.log(`Sending FCM notification to token: ${user.fcmToken}`);
// In production, use admin.messaging().send() here
}
const delivered = this.gateway.sendToUser(userId, 'notification', notification);
Expand Down
4 changes: 4 additions & 0 deletions src/transactions/dto/timeline.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export class CreateMilestoneDto {
}

export class UpdateMilestoneDto {
@IsOptional()
@IsString()
title?: string;

@IsOptional()
@IsEnum(MilestoneStatus)
status?: MilestoneStatus;
Expand Down
31 changes: 31 additions & 0 deletions src/transactions/transactions.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ describe('TransactionsService', () => {
provide: PrismaService,
useValue: mockPrismaService,
},
{
provide: NotificationsService,
useValue: notificationsService,
},
],
}).compile();

Expand Down Expand Up @@ -81,4 +85,31 @@ describe('TransactionsService', () => {
expect(result).toBeNull();
});
});

describe('updateStatus', () => {
it('updates status and logs history in a transaction', async () => {
const mockTx = { id: 'tx-123', status: TransactionStatus.PENDING };
prisma.transaction.findUnique.mockResolvedValue(mockTx);
prisma.transaction.update.mockResolvedValue({ ...mockTx, status: TransactionStatus.COMPLETED });
prisma.transactionHistory.create.mockResolvedValue({ id: 'hist-1' });
prisma.$transaction.mockImplementation(async (cb) => cb(prisma));

const result = await service.updateStatus('tx-123', TransactionStatus.COMPLETED, 'actor-1');

expect(prisma.transaction.update).toHaveBeenCalledWith({
where: { id: 'tx-123' },
data: { status: TransactionStatus.COMPLETED },
});
expect(prisma.transactionHistory.create).toHaveBeenCalledWith({
data: {
transactionId: 'tx-123',
status: TransactionStatus.COMPLETED,
actorId: 'actor-1',
notes: 'Status updated from PENDING to COMPLETED',
},
});
expect(notificationsService.handleTransactionUpdate).toHaveBeenCalledWith('tx-123');
expect(result.status).toBe(TransactionStatus.COMPLETED);
});
});
});
10 changes: 10 additions & 0 deletions src/types/prisma.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ export interface ApiKey {
updatedAt: Date;
}

export interface TransactionHistory {
id: string;
transactionId: string;
status: string;
actorId: string | null;
notes: string | null;
metadata: any | null;
createdAt: Date;
}

export enum TokenType {
ACCESS = 'ACCESS',
REFRESH = 'REFRESH',
Expand Down
6 changes: 6 additions & 0 deletions test/transactions/transactions.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,16 @@ describe('TransactionsService', () => {
findFirst: jest.fn(),
update: jest.fn(),
},
transactionHistory: {
create: jest.fn(),
findMany: jest.fn(),
},
$transaction: jest.fn().mockImplementation(async (cb) => cb(mockPrismaService)),
} as any;

const mockNotificationsService = {
sendNotification: jest.fn(),
handleTransactionUpdate: jest.fn(),
};

beforeEach(async () => {
Expand Down
Loading