-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'next' into parsu_ci_testing
- Loading branch information
Showing
102 changed files
with
5,570 additions
and
6,413 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { USE_CASES } from './usecases'; | ||
import { UploadRepository } from '@impler/dal'; | ||
import { CommonController } from './common.controller'; | ||
import { SharedModule } from '@shared/shared.module'; | ||
import { PaymentAPIService } from '@impler/shared'; | ||
|
||
@Module({ | ||
imports: [SharedModule], | ||
providers: [...USE_CASES], | ||
imports: [SharedModule, UploadRepository], | ||
providers: [...USE_CASES, PaymentAPIService], | ||
controllers: [CommonController], | ||
}) | ||
export class CommonModule {} |
15 changes: 10 additions & 5 deletions
15
apps/api/src/app/common/usecases/get-import-config/get-import-config.usecase.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,19 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { ProjectRepository } from '@impler/dal'; | ||
import { IImportConfig } from '@impler/shared'; | ||
import { UserRepository } from '@impler/dal'; | ||
import { IImportConfig, PaymentAPIService } from '@impler/shared'; | ||
|
||
@Injectable() | ||
export class GetImportConfig { | ||
constructor(private projectRepository: ProjectRepository) {} | ||
constructor( | ||
private userRepository: UserRepository, | ||
private paymentAPIService: PaymentAPIService | ||
) {} | ||
|
||
async execute(projectId: string): Promise<IImportConfig> { | ||
const projectInfo = await this.projectRepository.findById(projectId, 'showBranding'); | ||
const userEmail = await this.userRepository.findUserEmailFromProjectId(projectId); | ||
|
||
return { showBranding: projectInfo.showBranding }; | ||
const removeBrandingAvailable = await this.paymentAPIService.checkEvent(userEmail, 'REMOVE_BRANDING'); | ||
|
||
return { showBranding: !removeBrandingAvailable }; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,3 +69,7 @@ export const VARIABLES = { | |
ONE: 1, | ||
TWO: 2, | ||
}; | ||
|
||
export const DATE_FORMATS = { | ||
COMMON: 'DD MMM YYYY', | ||
}; |
16 changes: 16 additions & 0 deletions
16
apps/api/src/app/user/usecases/cancel-subscription/cancel-subscription.usecase.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import * as dayjs from 'dayjs'; | ||
import { Injectable } from '@nestjs/common'; | ||
import { PaymentAPIService } from '@impler/shared'; | ||
import { DATE_FORMATS } from '@shared/constants'; | ||
|
||
@Injectable() | ||
export class CancelSubscription { | ||
constructor(private paymentApiService: PaymentAPIService) {} | ||
|
||
async execute(userEmail: string) { | ||
const cancelledSubscription = await this.paymentApiService.cancelSubscription(userEmail); | ||
cancelledSubscription.expiryDate = dayjs(cancelledSubscription.expiryDate).format(DATE_FORMATS.COMMON); | ||
|
||
return cancelledSubscription; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...pi/src/app/user/usecases/delete-user-payment-method/delete-user-payment-method.usecase.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { PaymentAPIService } from '@impler/shared'; | ||
|
||
@Injectable() | ||
export class DeleteUserPaymentMethod { | ||
constructor(private paymentApiService: PaymentAPIService) {} | ||
|
||
async execute(paymentMethodId: string) { | ||
return await this.paymentApiService.deleteUserPaymentMethod(paymentMethodId); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
apps/api/src/app/user/usecases/get-active-subscription/get-active-subscription.usecase.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import * as dayjs from 'dayjs'; | ||
import { Injectable } from '@nestjs/common'; | ||
import { DATE_FORMATS } from '@shared/constants'; | ||
import { ISubscriptionData, PaymentAPIService } from '@impler/shared'; | ||
|
||
@Injectable() | ||
export class GetActiveSubscription { | ||
constructor(private paymentApiService: PaymentAPIService) {} | ||
|
||
async execute(userEmail: string): Promise<ISubscriptionData> { | ||
const activeSubscription = await this.paymentApiService.fetchActiveSubscription(userEmail); | ||
|
||
if (!activeSubscription) { | ||
return null; | ||
} | ||
|
||
activeSubscription.expiryDate = dayjs(activeSubscription.expiryDate).format(DATE_FORMATS.COMMON); | ||
|
||
return activeSubscription; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
apps/api/src/app/user/usecases/get-import-count/get-import-count.usecase.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { UploadRepository } from '@impler/dal'; | ||
import { UploadStatusEnum } from '@impler/shared'; | ||
|
||
interface IImportCountItem { | ||
_id: string; | ||
records: { totalRecords: number; status: UploadStatusEnum }[]; | ||
} | ||
|
||
@Injectable() | ||
export class GetImportCounts { | ||
constructor(private uploadRepository: UploadRepository) {} | ||
|
||
async execute({ _userId, start, end }: { _userId: string; start?: string; end?: string }) { | ||
const startOfMonthDate = new Date(); | ||
startOfMonthDate.setDate(1); | ||
const endOfMonthDate = new Date(); | ||
endOfMonthDate.setMonth(endOfMonthDate.getMonth() + 1); | ||
|
||
const records = (await this.uploadRepository.getImportCount( | ||
_userId, | ||
start ? new Date(start) : startOfMonthDate, | ||
end ? new Date(end) : endOfMonthDate | ||
)) as IImportCountItem[]; | ||
|
||
return records.map((item) => ({ | ||
date: item._id, | ||
records: item.records.reduce( | ||
(obj, recordItem) => { | ||
obj[recordItem.status] += recordItem.totalRecords; | ||
|
||
return obj; | ||
}, | ||
{ | ||
[UploadStatusEnum.COMPLETED]: 0, | ||
[UploadStatusEnum.TERMINATED]: 0, | ||
[UploadStatusEnum.MAPPING]: 0, | ||
[UploadStatusEnum.REVIEWING]: 0, | ||
} | ||
), | ||
})); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
apps/api/src/app/user/usecases/get-transaction-history/get-transaction-history.usecase.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import * as dayjs from 'dayjs'; | ||
import { Injectable } from '@nestjs/common'; | ||
import { DATE_FORMATS } from '@shared/constants'; | ||
import { PaymentAPIService } from '@impler/shared'; | ||
|
||
@Injectable() | ||
export class GetTransactionHistory { | ||
constructor(private paymentApiService: PaymentAPIService) {} | ||
|
||
async execute(email: string) { | ||
const transactions = await this.paymentApiService.getTransactionHistory(email); | ||
|
||
return transactions.map((transactionItem) => ({ | ||
transactionDate: dayjs(transactionItem.transactionDate).format(DATE_FORMATS.COMMON), | ||
planName: transactionItem.planName, | ||
transactionStatus: transactionItem.transactionStatus, | ||
membershipDate: transactionItem.membershipDate | ||
? dayjs(transactionItem.membershipDate).format(DATE_FORMATS.COMMON) | ||
: undefined, | ||
expiryDate: transactionItem.expiryDate | ||
? dayjs(transactionItem.expiryDate).format(DATE_FORMATS.COMMON) | ||
: undefined, | ||
isPlanActive: transactionItem.isPlanActive, | ||
charge: transactionItem.charge, | ||
amount: transactionItem.amount, | ||
currency: transactionItem.currency, | ||
_id: transactionItem.id, | ||
})); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { GetImportCounts } from './get-import-count/get-import-count.usecase'; | ||
import { GetActiveSubscription } from './get-active-subscription/get-active-subscription.usecase'; | ||
import { CancelSubscription } from './cancel-subscription/cancel-subscription.usecase'; | ||
import { UpdatePaymentMethod } from './setup-payment-intent/setup-payment-intent.usecase'; | ||
import { ConfirmIntentId } from './save-payment-intent-id/save-paymentintentid.usecase'; | ||
import { RetrievePaymentMethods } from './retrive-payment-methods/retrive-payment-methods.usecase'; | ||
import { DeleteUserPaymentMethod } from './delete-user-payment-method/delete-user-payment-method.usecase'; | ||
import { GetTransactionHistory } from './get-transaction-history/get-transaction-history.usecase'; | ||
|
||
export const USE_CASES = [ | ||
GetImportCounts, | ||
CancelSubscription, | ||
GetActiveSubscription, | ||
UpdatePaymentMethod, | ||
ConfirmIntentId, | ||
RetrievePaymentMethods, | ||
DeleteUserPaymentMethod, | ||
GetTransactionHistory, | ||
// | ||
]; | ||
|
||
export { | ||
GetImportCounts, | ||
CancelSubscription, | ||
GetActiveSubscription, | ||
UpdatePaymentMethod, | ||
ConfirmIntentId, | ||
RetrievePaymentMethods, | ||
DeleteUserPaymentMethod, | ||
GetTransactionHistory, | ||
}; |
Oops, something went wrong.