Skip to content

Commit

Permalink
Activities review Peter's code (#5908)
Browse files Browse the repository at this point in the history
Some comments and small changes
  • Loading branch information
diderikvw authored and PeterSmallenbroek committed Oct 18, 2024
1 parent bb02c0b commit ec37684
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class ActivitiesController {
@ApiOperation({ summary: '[SCOPED] Get activities for registration' })
@ApiResponse({
status: HttpStatus.OK,
description: 'TODO: Provide description',
description: '##TODO: Provide description',
type: [ActivitiesDto],
})
@ApiParam({ name: 'programId', required: true, type: 'integer' })
Expand Down
8 changes: 4 additions & 4 deletions services/121-service/src/activities/activities.mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ export class ActivitiesMapper {
return { meta: { availableTypes: [], count: {} }, data: [] };
}

private static mapTransactionsToData(transactions: unknown[]): [] {
private static mapTransactionsToData(_transactions: unknown[]): [] {
return [];
}
private static mapMessagesToData(messages: unknown[]): [] {
private static mapMessagesToData(_messages: unknown[]): [] {
return [];
}
private static mapEventsToData(events: unknown[]): [] {
private static mapEventsToData(_events: unknown[]): [] {
return [];
}
private static mapNotesToData(notes: unknown[]): [] {
private static mapNotesToData(_notes: unknown[]): [] {
return [];
}

Expand Down
38 changes: 19 additions & 19 deletions services/121-service/src/activities/dtos/activities.dto.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
import { MessageContentType } from '@121-service/src/notifications/enum/message-type.enum';
import { NotificationType } from '@121-service/src/notifications/twilio.entity';
import { TransactionStatusEnum } from '@121-service/src/payments/transactions/enums/transaction-status.enum';
import { RegistrationStatusEnum } from '@121-service/src/registration/enum/registration-status.enum';
import { StatusEnum } from '@121-service/src/shared/enum/status.enum';

export class ActivitiesDto {
meta: {
availableTypes: ActivityItemType[];
count: Partial<Record<ActivityItemType, number>>;
availableTypes: ActivityTypeEnum[];
count: Partial<Record<ActivityTypeEnum, number>>;
};
data: ActivityLogItem[];
data: ActivityType[];
}

export type ActivityLogItem =
export type ActivityType =
| DataChangeActivity
| MessageActivity
| NoteActivity
| StatusUpdateActivity
| StatusChangeActivity
| TransactionActivity;

export enum ActivityItemType {
DataChange = 'data-change',
export enum ActivityTypeEnum {
Transaction = 'transaction',
Message = 'message',
Note = 'note',
StatusUpdate = 'status-update',
FinancialServiceProviderChange = 'financial-service-provider-change',
DataChange = 'data-change',
StatusChange = 'status-change',
FinancialServiceProviderChange = 'financial-service-provider-change', // ##TODO: Looks like this type is still missing in the rest of the code, e.g. extending from BaseActivity.
}

interface BaseActivity {
Expand All @@ -34,33 +34,33 @@ interface BaseActivity {
username: string;
};
created: Date;
activityType: ActivityItemType;
type: ActivityTypeEnum;
attributes: Record<string, unknown>;
}

export interface TransactionActivity extends BaseActivity {
activityType: ActivityItemType.Transaction;
type: ActivityTypeEnum.Transaction;
attributes: {
payment: number;
status: StatusEnum;
status: TransactionStatusEnum;
amount: number;
paymentDate: Date;
fsp: string; // Financial service provider enum name, like "intersolve-visa";
fspName: string; // Financial service provider name, like "Intersolve Visa";
errorMessage: null | string;
customData: unknown;
customData: unknown; // ##TODO: Do we want/need to expose customData via the API?
};
}

export interface NoteActivity extends BaseActivity {
activityType: ActivityItemType.Note;
type: ActivityTypeEnum.Note;
attributes: {
text: string; // The note content
};
}

export interface MessageActivity extends BaseActivity {
activityType: ActivityItemType.Message;
type: ActivityTypeEnum.Message;
attributes: {
from: string;
to: string;
Expand All @@ -73,16 +73,16 @@ export interface MessageActivity extends BaseActivity {
};
}

export interface StatusUpdateActivity extends BaseActivity {
activityType: ActivityItemType.StatusUpdate;
export interface StatusChangeActivity extends BaseActivity {
type: ActivityTypeEnum.StatusChange;
attributes: {
oldValue: RegistrationStatusEnum;
newValue: RegistrationStatusEnum;
};
}

export interface DataChangeActivity extends BaseActivity {
activityType: ActivityItemType.DataChange;
type: ActivityTypeEnum.DataChange;
attributes: {
fieldName: string;
oldValue: string;
Expand Down
2 changes: 1 addition & 1 deletion services/121-service/src/notes/note.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ export class NoteScopedRepository extends ScopedRepository<NoteEntity> {
'user.username AS username',
])
.orderBy('note.created', 'DESC')
.getRawMany<GetNotesDto>();
.getRawMany<GetNotesDto>(); // ##TODO: Why not just return TwilioMessageEntity[]? And is this an example where we want to try a "normal" TypeORM query instead of a raw query?
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ export interface GetTwilioMessageDto {
from: string;
to: string;
body: string;
status: string; //TODO: might not be the correct type
status: string; // ##TODO: might not be the correct type
medialUrl: string;
contentType: MessageContentType; //TODO: might not be the correct type
contentType: MessageContentType; //##TODO: might not be the correct type
errorCode: string | null;
userId: number;
username: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class TwilioMessageScopedRepository extends ScopedRepository<TwilioMessag
registrationId,
})
.orderBy('twilioMessage.dateCreated', 'DESC')
.getRawMany<GetTwilioMessageDto>();
.getRawMany<GetTwilioMessageDto>(); // ##TODO: Why not just return TwilioMessageEntity[]? And is this an example where we want to try a "normal" TypeORM query instead of a raw query?

if (
messageHistoryArray.length === 1 &&
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { FinancialServiceProviderName } from '@121-service/src/financial-service-providers/enum/financial-service-provider-name.enum';
import { StatusEnum } from '@121-service/src/shared/enum/status.enum';
import { TransactionStatusEnum } from '@121-service/src/payments/transactions/enums/transaction-status.enum';

export interface GetAuditedTransactionDto {
paymentDate: Date;
payment: number;
referenceId: string;
status: StatusEnum;
status: TransactionStatusEnum;
amount: number;
errorMessage?: string;
customData?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { InjectRepository } from '@nestjs/typeorm';

import { FinancialServiceProviderName } from '@121-service/src/financial-service-providers/enum/financial-service-provider-name.enum';
import { GetAuditedTransactionDto } from '@121-service/src/payments/transactions/dto/get-audited-transaction.dto';
import { TransactionStatusEnum } from '@121-service/src/payments/transactions/enums/transaction-status.enum';
import { TransactionEntity } from '@121-service/src/payments/transactions/transaction.entity';
import {
ScopedQueryBuilder,
ScopedRepository,
} from '@121-service/src/scoped.repository';
import { StatusEnum } from '@121-service/src/shared/enum/status.enum';
import { ScopedUserRequest } from '@121-service/src/shared/scoped-user-request';

export class TransactionScopedRepository extends ScopedRepository<TransactionEntity> {
Expand All @@ -32,9 +32,10 @@ export class TransactionScopedRepository extends ScopedRepository<TransactionEnt
.leftJoin('transaction.user', 'user')
.addSelect('user.id', 'userId')
.addSelect('user.username', 'username');
return await query.getRawMany<GetAuditedTransactionDto>();
return await query.getRawMany<GetAuditedTransactionDto>(); // ##TODO: Why not just return TwilioMessageEntity[]? And is this an example where we want to try a "normal" TypeORM query instead of a raw query?
}

// ##TODO: Since LatestTransactionEntity is another Entity, should it not also have its own custom repository?
public getLastTransactionsQuery({
programId,
payment,
Expand All @@ -47,7 +48,7 @@ export class TransactionScopedRepository extends ScopedRepository<TransactionEnt
payment?: number;
registrationId?: number;
referenceId?: string;
status?: StatusEnum;
status?: TransactionStatusEnum;
fspName?: FinancialServiceProviderName;
}): ScopedQueryBuilder<TransactionEntity> {
let transactionQuery = this.createQueryBuilder('transaction')
Expand All @@ -65,7 +66,7 @@ export class TransactionScopedRepository extends ScopedRepository<TransactionEnt
])
.leftJoin('transaction.financialServiceProvider', 'fsp')
.leftJoin('transaction.registration', 'r')
// TODO: Why is latest transaction joined here, no where/select on it?
// ##TODO: Why is latest transaction joined here, no where/select on it?
.innerJoin('transaction.latestTransaction', 'lt')
.andWhere('transaction."programId" = :programId', {
programId,
Expand Down

0 comments on commit ec37684

Please sign in to comment.