Skip to content

Commit

Permalink
Merge branch 'next' into parsu_ci_testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Techpurshottam authored Jun 21, 2024
2 parents 9854dcf + e1ab56f commit 05ecc8e
Show file tree
Hide file tree
Showing 102 changed files with 5,570 additions and 6,413 deletions.
6 changes: 3 additions & 3 deletions apps/api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@impler/api",
"version": "0.19.0",
"version": "0.20.0",
"author": "implerhq",
"license": "MIT",
"private": true,
Expand All @@ -21,8 +21,8 @@
"dependencies": {
"@aws-sdk/client-s3": "^3.185.0",
"@aws-sdk/client-ses": "^3.354.0",
"@impler/dal": "^0.19.0",
"@impler/shared": "^0.19.0",
"@impler/dal": "^0.20.0",
"@impler/shared": "^0.20.0",
"@nestjs/common": "^9.1.2",
"@nestjs/core": "^9.1.2",
"@nestjs/jwt": "^10.0.1",
Expand Down
4 changes: 3 additions & 1 deletion apps/api/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import { CommonModule } from './app/common/common.module';
import { HealthModule } from 'app/health/health.module';
import { AuthModule } from './app/auth/auth.module';
import { EnvironmentModule } from './app/environment/environment.module';
import { ActivityModule } from 'app/activity/activity.module';
import { ActivityModule } from './app/activity/activity.module';
import { UserModule } from './app/user/user.module';

const modules: Array<Type | DynamicModule | Promise<DynamicModule> | ForwardReference> = [
ProjectModule,
Expand All @@ -25,6 +26,7 @@ const modules: Array<Type | DynamicModule | Promise<DynamicModule> | ForwardRefe
CommonModule,
HealthModule,
AuthModule,
UserModule,
EnvironmentModule,
ActivityModule,
];
Expand Down
3 changes: 2 additions & 1 deletion apps/api/src/app/auth/auth.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { SharedModule } from '../shared/shared.module';
import { GitHubStrategy } from './services/passport/github.strategy';
import { JwtStrategy } from './services/passport/jwt.strategy';
import { LeadService } from '@shared/services/lead.service';
import { PaymentAPIService } from '@impler/shared';

const AUTH_STRATEGIES: Provider[] = [JwtStrategy];

Expand All @@ -32,7 +33,7 @@ if (process.env.GITHUB_OAUTH_CLIENT_ID) {
}),
],
controllers: [AuthController],
providers: [AuthService, ...AUTH_STRATEGIES, ...USE_CASES, LeadService],
providers: [AuthService, ...AUTH_STRATEGIES, ...USE_CASES, LeadService, PaymentAPIService],
exports: [AuthService],
})
export class AuthModule implements NestModule {
Expand Down
12 changes: 10 additions & 2 deletions apps/api/src/app/auth/services/auth.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as bcrypt from 'bcryptjs';
import { JwtService } from '@nestjs/jwt';
import { IJwtPayload } from '@impler/shared';
import { IJwtPayload, PaymentAPIService } from '@impler/shared';
import { CONSTANTS } from '@shared/constants';
import { Injectable, UnauthorizedException } from '@nestjs/common';
import { UserEntity, UserRepository, EnvironmentRepository } from '@impler/dal';
Expand All @@ -15,7 +15,8 @@ export class AuthService {
private jwtService: JwtService,
private leadService: LeadService,
private userRepository: UserRepository,
private environmentRepository: EnvironmentRepository
private environmentRepository: EnvironmentRepository,
private paymentAPIService: PaymentAPIService
) {}

async authenticate({ profile, provider }: IAuthenticationData): Promise<IStrategyResponse> {
Expand All @@ -40,6 +41,13 @@ export class AuthService {
'Lead Source': 'Github Signup',
});
userCreated = true;

const userData = {
name: user.firstName + ' ' + user.lastName,
email: user.email,
externalId: user.email,
};
this.paymentAPIService.createUser(userData);
}
if (!user) {
throw new UserNotFoundException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import { AuthService } from '../../services/auth.service';
import { RegisterUserCommand } from './register-user.command';
import { UniqueEmailException } from '@shared/exceptions/unique-email.exception';
import { LeadService } from '@shared/services/lead.service';
import { PaymentAPIService } from '@impler/shared';

@Injectable()
export class RegisterUser {
constructor(
private userRepository: UserRepository,
private authService: AuthService,
private leadService: LeadService
private leadService: LeadService,
private paymentAPIService: PaymentAPIService
) {}

async execute(command: RegisterUserCommand) {
Expand All @@ -38,6 +40,14 @@ export class RegisterUser {
'Lead Source': 'Website Signup',
});

const userData = {
name: user.firstName + ' ' + user.lastName,
email: user.email,
externalId: user.email,
};

await this.paymentAPIService.createUser(userData);

const token = this.authService.getSignedToken({
_id: user._id,
email: user.email,
Expand Down
6 changes: 4 additions & 2 deletions apps/api/src/app/common/common.module.ts
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 {}
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 };
}
}
13 changes: 10 additions & 3 deletions apps/api/src/app/review/usecases/do-review/do-review.usecase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { Writable } from 'stream';
import { Injectable, BadRequestException } from '@nestjs/common';

import { APIMessages } from '@shared/constants';
import { ColumnTypesEnum, ITemplateSchemaItem, UploadStatusEnum } from '@impler/shared';
import { BaseReview } from './base-review.usecase';
import { BATCH_LIMIT } from '@shared/services/sandbox';
import { StorageService } from '@impler/shared/dist/services/storage';
import { PaymentAPIService, ColumnTypesEnum, UploadStatusEnum, ITemplateSchemaItem } from '@impler/shared';
import { UploadRepository, ValidatorRepository, FileRepository, DalService } from '@impler/dal';

interface ISaveResults {
Expand All @@ -18,14 +18,15 @@ interface ISaveResults {

@Injectable()
export class DoReview extends BaseReview {
private _modal: Model<any>;
private _modal: Model<unknown>;

constructor(
private storageService: StorageService,
private uploadRepository: UploadRepository,
private validatorRepository: ValidatorRepository,
private fileRepository: FileRepository,
private dalService: DalService
private dalService: DalService,
private paymentAPIService: PaymentAPIService
) {
super();
}
Expand Down Expand Up @@ -158,5 +159,11 @@ export class DoReview extends BaseReview {
invalidRecords,
}
);
const userExternalIdOrEmail = await this.uploadRepository.getUserEmailFromUploadId(uploadId);

await this.paymentAPIService.createEvent(
{ uploadId, totalRecords, validRecords, invalidRecords },
userExternalIdOrEmail
);
}
}
5 changes: 3 additions & 2 deletions apps/api/src/app/review/usecases/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { ConfirmReview } from './confirm-review/confirm-review.usecase';
import { GetUpload } from '@shared/usecases/get-upload/get-upload.usecase';
import { UpdateImportCount } from './update-import-count/update-import-count.usecase';
import { GetUploadData } from './get-upload-data/get-upload-data.usecase';

import { UpdateImportCountCommand } from './update-import-count/update-import-count.command';
import { PaymentAPIService } from '@impler/shared';

export const USE_CASES = [
DoReview,
Expand All @@ -20,7 +20,7 @@ export const USE_CASES = [
ConfirmReview,
GetUploadData,
UpdateImportCount,
//
PaymentAPIService,
];

export {
Expand All @@ -33,5 +33,6 @@ export {
ConfirmReview,
GetUploadData,
UpdateImportCount,
PaymentAPIService,
};
export { UpdateImportCountCommand };
4 changes: 4 additions & 0 deletions apps/api/src/app/shared/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,7 @@ export const VARIABLES = {
ONE: 1,
TWO: 2,
};

export const DATE_FORMATS = {
COMMON: 'DD MMM YYYY',
};
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;
}
}
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);
}
}
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;
}
}
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,
}
),
}));
}
}
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,
}));
}
}
31 changes: 31 additions & 0 deletions apps/api/src/app/user/usecases/index.ts
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,
};
Loading

0 comments on commit 05ecc8e

Please sign in to comment.